drupal migrate

Drupal Migrate: Don't forget to de register your classes

Often times when writing a module to migrate content leveraging the Migrate module you will find yourself disabling and re enabling your module as you add classes to it.
When you do this you might find that you get errors about classes not being found or that your migrations are still being displayed in the interface even though your module is disabled (when using a class from another module such as d2d_migrate).
To get around this, make sure you de register your migration classes in a HOOK_disable() function in your module.

 function MYMODULE_disable() { 
Migration::deregisterMigration('my_role_migration');
Migration::deregisterMigration('my_user_migration');
}

Drupal Migrate V2 and Addressfield

While trying to migrate data from a legacy CakePHP system to Drupal 7 recently I had a problem getting an Addressfield field to play nicely.
What I had origianly was this (which did not work).

  $this->addFieldMapping('field_customer_address:thoroughfare', 'address'); 
$this->addFieldMapping('field_customer_address:locality', 'suburb');
$this->addFieldMapping('field_customer_address:administrative_area', 'state');
$this->addFieldMapping('field_customer_address:postal_code', 'postcode');

Looking all over the web I found many examples saying to use the arguments function. eg.
  $address_arguments= array( 
'thoroughfare' => array('source_field' => 'address'),
'locality' => array('source_field' => 'suburb'),
'administrative_area' => array('source_field'=>'state'),
'postal_code' => array('source_field' => 'postcode'),
);
$this->addFieldMapping('field_customer_address')
->arguments($address_arguments);

But when trying this I got a message from the module saying that this was not correct. I think the above code was/is for version 1 of the migrate module.
It turns out that all I needed to do was to set a default country. ie.
  $this->addFieldMapping('field_customer_address')->defaultValue('AU'); 
$this->addFieldMapping('field_customer_address:thoroughfare', 'address');
$this->addFieldMapping('field_customer_address:locality', 'suburb');
$this->addFieldMapping('field_customer_address:administrative_area', 'state');
$this->addFieldMapping('field_customer_address:postal_code', 'postcode');