First, there is a disconnect between the code and the documentation for defining groups for dynamic migrations. On the documentation page, the example is:
MigrationBase::registerMigration('ExampleUserMigration', 'ExampleUser', array('group_name' => 'Example', 'default_uid' => 1));
But in the code, there is no reference to an element of the argument array named 'group_name', at least not in the 7.x branch. There is a reference to 'group' argument, however, in __construct in base.inc:
if (empty($group)) {
$this->group = MigrateGroup::getInstance('default');
}
else {
$this->group = $group;
}
So, this means that the argument array passed to registerMigration would contain an instantiated MigrateGroup object, such as perhaps MigrateGroup::getInstance('mygroup', array('dependent1')).
The arguments to the migration argument are then serialized and stored in the migrate_status table. Later when it comes time to order the migrations by dependency, the rows are fetched from the database and deserialized, recreating the MigrateGroup object. This object, however, was not created by the static member function MigrateGroup::getInstance, so it is not stored in the static table. It is therefore unavailable to MigrateGroup::groups(), and the groups are not ordered by dependency.
I suspect, but have not confirmed, that declaring the dynamic migration via hook_migrate_api would work, because the Migration objects would not be re-created from the database.
The solution, I think, would be to process group_name (and a new group_dependencies argument) in registerMigration, and create the MigrateGroup when the database is later read.
Last, I thank Moshe and the current maintainers for this awesome module.
Comments
Comment #1
danchadwick commentedAn update: Yes, group dependency does work fine if an instantiated MigrateGroup object is passed as 'group' in the info array in hook_migrate_api. This does not seem like a good idea, however, since the assumption is that these arrays are declarative.
Comment #2
mikeryanFor once I'm a step ahead - the wizard_api branch now supports the group_name argument in registerMigratoin, and uses MigrateGroup::getInstance when retrieving from migrate_status.
Comment #3.0
(not verified) commentedFixed typos