diff --git a/migrate_tools.drush.inc b/migrate_tools.drush.inc index 9f2bca3..00a9531 100644 --- a/migrate_tools.drush.inc +++ b/migrate_tools.drush.inc @@ -47,7 +47,6 @@ function migrate_tools_drush_command() { 'group' => 'A comma-separated list of migration groups to import', 'tag' => 'Name of the migration tag to import', 'limit' => 'Limit on the number of items to process in each migration', - 'feedback' => 'Frequency of progress messages, in items processed', 'idlist' => 'Comma-separated list of IDs to import', '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', @@ -240,7 +239,7 @@ function drush_migrate_tools_migrate_import($migration_names = '') { return; } - foreach (['limit', 'feedback', 'idlist', 'update', 'force'] as $option) { + foreach (['limit', 'idlist', 'update', 'force'] as $option) { if (drush_get_option($option)) { $options[$option] = drush_get_option($option); } diff --git a/src/Commands/MigrateToolsCommands.php b/src/Commands/MigrateToolsCommands.php index e12cc65..f4d5f04 100644 --- a/src/Commands/MigrateToolsCommands.php +++ b/src/Commands/MigrateToolsCommands.php @@ -244,7 +244,6 @@ class MigrateToolsCommands extends DrushCommands { * @option group A comma-separated list of migration groups to import * @option tag Name of the migration tag to import * @option limit Limit on the number of items to process in each migration - * @option feedback Frequency of progress messages, in items processed * @option idlist Comma-separated list of IDs to import * @option update In addition to processing unprocessed items from the * source, update previously-imported items with the current data @@ -281,7 +280,6 @@ class MigrateToolsCommands extends DrushCommands { 'group' => NULL, 'tag' => NULL, 'limit' => NULL, - 'feedback' => NULL, 'idlist' => NULL, 'update' => NULL, 'force' => NULL, @@ -296,7 +294,7 @@ class MigrateToolsCommands extends DrushCommands { throw new \Exception(dt('You must specify --all, --group, --tag or one or more migration names separated by commas')); } - foreach (['limit', 'feedback', 'idlist', 'update', 'force'] as $option) { + foreach (['limit', 'idlist', 'update', 'force'] as $option) { if ($options[$option]) { $additional_options[$option] = $options[$option]; } diff --git a/src/MigrateBatchExecutable.php b/src/MigrateBatchExecutable.php index d7c9e2b..4cd3726 100644 --- a/src/MigrateBatchExecutable.php +++ b/src/MigrateBatchExecutable.php @@ -225,10 +225,7 @@ class MigrateBatchExecutable extends MigrateExecutable { $context['sandbox']['counter'] = $context['results'][$migration->id()]['@numitems']; if ($context['sandbox']['counter'] <= $context['sandbox']['total']) { $context['finished'] = ((float) $context['sandbox']['counter'] / (float) $context['sandbox']['total']); - $context['message'] = t('Importing %migration (@percent%).', [ - '%migration' => $migration->label(), - '@percent' => (int) ($context['finished'] * 100) - ]); + $context['message'] = $executable->progressMessage(FALSE); } } diff --git a/src/MigrateExecutable.php b/src/MigrateExecutable.php index 01dba42..af8b545 100644 --- a/src/MigrateExecutable.php +++ b/src/MigrateExecutable.php @@ -223,10 +223,39 @@ class MigrateExecutable extends MigrateExecutableBase { public function onPostImport(MigrateImportEvent $event) { $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported'); $migrate_last_imported_store->set($event->getMigration()->id(), round(microtime(TRUE) * 1000)); - $this->progressMessage(); + $this->progressMessageEmit(); $this->removeListeners(); } + /** + * Generate a progress message. + * + * @param bool $done + * Whether the import has fully finished + * + * @return \Drupal\Component\Render\MarkupInterface + * The progress message to show to the end user + */ + public function progressMessage($done = TRUE) { + $processed = $this->getProcessedCount(); + if ($done) { + $singular_message = "Processed 1 item (@created created, @updated updated, @failures failed, @ignored ignored) - done with '@name'"; + $plural_message = "Processed @numitems items (@created created, @updated updated, @failures failed, @ignored ignored) - done with '@name'"; + } + else { + $singular_message = "Processed 1 item (@created created, @updated updated, @failures failed, @ignored ignored) - continuing with '@name'"; + $plural_message = "Processed @numitems items (@created created, @updated updated, @failures failed, @ignored ignored) - continuing with '@name'"; + } + return \Drupal::translation()->formatPlural($processed, + $singular_message, $plural_message, + ['@numitems' => $processed, + '@created' => $this->getCreatedCount(), + '@updated' => $this->getUpdatedCount(), + '@failures' => $this->getFailedCount(), + '@ignored' => $this->getIgnoredCount(), + '@name' => $this->migration->id()]); + } + /** * Clean up all our event listeners. */ @@ -242,24 +271,8 @@ class MigrateExecutable extends MigrateExecutableBase { * * @param bool $done */ - protected function progressMessage($done = TRUE) { - $processed = $this->getProcessedCount(); - if ($done) { - $singular_message = "Processed 1 item (@created created, @updated updated, @failures failed, @ignored ignored) - done with '@name'"; - $plural_message = "Processed @numitems items (@created created, @updated updated, @failures failed, @ignored ignored) - done with '@name'"; - } - else { - $singular_message = "Processed 1 item (@created created, @updated updated, @failures failed, @ignored ignored) - continuing with '@name'"; - $plural_message = "Processed @numitems items (@created created, @updated updated, @failures failed, @ignored ignored) - continuing with '@name'"; - } - $this->message->display(\Drupal::translation()->formatPlural($processed, - $singular_message, $plural_message, - ['@numitems' => $processed, - '@created' => $this->getCreatedCount(), - '@updated' => $this->getUpdatedCount(), - '@failures' => $this->getFailedCount(), - '@ignored' => $this->getIgnoredCount(), - '@name' => $this->migration->id()])); + protected function progressMessageEmit($done = TRUE) { + $this->message->display($this->progressMessage($done)); } /** @@ -353,7 +366,7 @@ class MigrateExecutable extends MigrateExecutableBase { } } if ($this->feedback && ($this->counter) && $this->counter % $this->feedback == 0) { - $this->progressMessage(FALSE); + $this->progressMessageEmit(FALSE); $this->resetCounters(); } $this->counter++;