Summary
Some migrations need to be derived and executed after other migrations have been successfully executed. For example, a migration might need to be derived based on previously migrated data. For such a case, the migration dependency system is not enough since all migration would still be derived before any one of them has been executed.
Those "follow-up" migrations need to be taged with the "Follow-up migration" tag (or any tag in the "follow_up_migration_tags" configuration) and thus they won't be derived with the other migrations.
To get those follow-up migrations derived at the right time, the migrations on which they depend must implement a new interface MigrationWithFollowUpInterface
and must generate them in the generateFollowUpMigrations()
method.
When the migrations implementing the MigrationWithFollowUpInterface
interface have been successfully executed, the follow-up migrations will then be derived having access to the now migrated data.
Example
Tag a migration as a follow-up migration
id: d7_entity_reference_translation
label: Entity reference translations
migration_tags:
- Drupal 7
- Follow-up migration
deriver: Drupal\migrate_drupal\Plugin\migrate\EntityReferenceTranslationDeriver
Generate the follow-up migrations
<?php
namespace Drupal\node\Plugin\migrate;
use Drupal\migrate\Plugin\Migration;
use Drupal\migrate_drupal\Plugin\MigrationWithFollowUpInterface;
/**
* Migration plugin for the Drupal 7 node translations.
*/
class D7NodeTranslation extends Migration implements MigrationWithFollowUpInterface {
/**
* {@inheritdoc}
*/
public function generateFollowUpMigrations() {
$this->migrationPluginManager->clearCachedDefinitions();
return $this->migrationPluginManager->createInstances('d7_entity_reference_translation');
}
}