diff --git a/migrate_tools/migrate_tools.drush.inc b/migrate_tools/migrate_tools.drush.inc index 286cad0a998f961dee2f1927019b14df5e0d0704..013e4beb1d59e1faaaebb137cd565cf3be6b62cd 100644 --- a/migrate_tools/migrate_tools.drush.inc +++ b/migrate_tools/migrate_tools.drush.inc @@ -39,6 +39,7 @@ function migrate_tools_drush_command() { 'options' => array( 'all' => 'Process all migrations.', 'group' => 'Name of the migration group to import', + 'limit' => 'Limit on the number of items to process in each migration', 'feedback' => 'Frequency of progress messages, in items processed', 'update' => ' In addition to processing unprocessed items from the source, update previously-imported items with the current data', 'force' => 'Force an operation to run, even if all dependencies are not satisfied', @@ -50,6 +51,7 @@ function migrate_tools_drush_command() { 'migrate-import --all' => 'Perform all migrations', 'migrate-import --group=beer' => 'Import all migrations in the beer group', 'migrate-import BeerTerm,BeerNode' => 'Import new terms and nodes', + 'migrate-import BeerUser --limit=2' => 'Import no more than 2 users', ), 'drupal dependencies' => array('migrate_tools'), 'aliases' => array('mi'), @@ -179,6 +181,9 @@ function drush_migrate_tools_migrate_import($migration_names = '') { return; } + if (drush_get_option('limit')) { + $options['limit'] = drush_get_option('limit'); + } if (drush_get_option('feedback')) { $options['feedback'] = drush_get_option('feedback'); } diff --git a/migrate_tools/src/MigrateExecutable.php b/migrate_tools/src/MigrateExecutable.php index 964109df004f9bb6c21069a11fa1072311f761e1..4ecf67f5937afeeadc13f87267a8241f11359164 100644 --- a/migrate_tools/src/MigrateExecutable.php +++ b/migrate_tools/src/MigrateExecutable.php @@ -73,6 +73,9 @@ class MigrateExecutable extends MigrateExecutableBase { */ public function __construct(MigrationInterface $migration, MigrateMessageInterface $message, array $options = []) { parent::__construct($migration, $message); + if (isset($options['limit'])) { + $this->itemLimit = $options['limit']; + } if (isset($options['feedback'])) { $this->feedback = $options['feedback']; } @@ -251,6 +254,9 @@ class MigrateExecutable extends MigrateExecutableBase { $this->resetCounters(); } $this->counter++; + if ($this->itemLimit && $this->counter >= $this->itemLimit) { + $event->getMigration()->interruptMigration(MigrationInterface::RESULT_COMPLETED); + } } }