1

I have a situation where I need to migrate a D6 node that has three location fields. The example code shown in the drupal module documentation ( https://drupal.org/node/2018113 ) isn't working. I either get no addresses or four copies of the node.

1 Answer 1

0

I used the following code to join to the location tables for each lid field in the d6 content. Whee!

$address_arguments = array(
        'administrative_area' => array('source_field' => 'hq_province'),
        'locality' => array('source_field' => 'hq_city'),
        'thoroughfare' => array('source_field' => 'hq_street'),
        'premise' => array('source_field' => 'hq_additional'),
        'postal_code' => array('source_field' => 'hq_postal_code'),
);
$this->addFieldMapping('field_company_address','hq_country')
->arguments($address_arguments);


$address_arguments = array(
        'administrative_area' => array('source_field' => 'leg_province'),
        'locality' => array('source_field' => 'leg_city'),
        'thoroughfare' => array('source_field' => 'leg_street'),
        'premise' => array('source_field' => 'leg_additional'),
        'postal_code' => array('source_field' => 'leg_postal_code'),
);
$this->addFieldMapping('field_company_legal_contact','leg_country')
->arguments($address_arguments);

$address_arguments = array(
        'administrative_area' => array('source_field' => 'inc_province'),
        'locality' => array('source_field' => 'inc_city'),
        'thoroughfare' => array('source_field' => 'inc_street'),
        'premise' => array('source_field' => 'inc_additional'),
        'postal_code' => array('source_field' => 'inc_postal_code'),
);
$this->addFieldMapping('field_company_inc_state','inc_country')
->arguments($address_arguments);


$this->addUnmigratedSources(array('field_company_twitter:title','field_company_twitter:attributes','field_company_linkedin:title','field_company_linkedin:attributes','field_website:title','field_website:attributes')); 

}
protected function query() {
$query = parent::query();
$query->leftJoin('location_instance', 'hq_i', 'hq_i.lid = f.field_hqaddress_lid AND hq_i.vid = n.vid');
$query->leftJoin('location', 'hq_l', 'hq_l.lid = hq_i.lid');
$query->addField('hq_l','street','hq_street');
$query->addField('hq_l','additional', 'hq_additional');
$query->addField('hq_l','city', 'hq_city');
$query->addField('hq_l','province' ,'hq_province');
$query->addField('hq_l','postal_code', 'hq_postal_code');
$query->addField('hq_l','country' ,'hq_country');

$query->leftJoin('location_instance', 'leg_i', 'leg_i.lid = f.field_legal_contact_address_lid AND leg_i.vid = n.vid');
$query->leftJoin('location', 'leg_l', 'leg_l.lid = leg_i.lid');
$query->addField('leg_l','street','leg_street');
$query->addField('leg_l','additional', 'leg_additional');
$query->addField('leg_l','city', 'leg_city');
$query->addField('leg_l','province' ,'leg_province');
$query->addField('leg_l','postal_code', 'leg_postal_code');
$query->addField('leg_l','country' ,'leg_country');

$query->leftJoin('location_instance', 'inc_i', 'inc_i.lid = f.field_incorporation_state_lid AND inc_i.vid = n.vid');
$query->leftJoin('location', 'inc_l', 'inc_l.lid = inc_i.lid');
$query->addField('inc_l','street','inc_street');
$query->addField('inc_l','additional', 'inc_additional');
$query->addField('inc_l','city', 'inc_city');
$query->addField('inc_l','province' ,'inc_province');
$query->addField('inc_l','postal_code', 'inc_postal_code');
$query->addField('inc_l','country' ,'inc_country');

return $query;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.