diff --git a/migrate_tools.routing.yml b/migrate_tools.routing.yml index b12735a..5393f4b 100644 --- a/migrate_tools.routing.yml +++ b/migrate_tools.routing.yml @@ -74,6 +74,13 @@ entity.migration.process: _title: 'Process' requirements: _permission: 'administer migrations' +entity.migration.process.run: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/process/run' + defaults: + _controller: '\Drupal\migrate_tools\Controller\MigrationController::run' + _title: 'Run' + requirements: + _permission: 'administer migrations' entity.migration.destination: path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/destination' defaults: @@ -107,3 +114,99 @@ migrate_tools.messages: _title: 'Messages' requirements: _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' + +migrate_tools.launch: + path: '/admin/structure/migrate/manage/{migration_group}/migrations/{migration}/launch' + defaults: + _form: '\Drupal\migrate_tools\Form\MigrationLaunchForm' + _title: 'Launch migration' + requirements: + _permission: 'administer migrations' diff --git a/src/BatchLogMigrateMessage.php b/src/BatchLogMigrateMessage.php new file mode 100644 index 0000000..458035b --- /dev/null +++ b/src/BatchLogMigrateMessage.php @@ -0,0 +1,21 @@ +migrationPluginManager->createInstance($migration); + + $migrateMessage = new MigrateMessage(); + $options = []; + + $executable = new MigrateBatchExecutable($migration, $migrateMessage, $options); + $executable->batchImport(); + + return batch_process(); + } + + /** * Display process information of a migration entity. * * @param string $migration_group @@ -205,6 +233,12 @@ class MigrationController extends ControllerBase implements ContainerInjectionIn '#empty' => $this->t('No process defined.'), ]; + $build['process']['run'] = [ + '#type' => 'link', + '#title' => $this->t('Run'), + '#url' => Url::fromRoute('entity.migration.process.run', ['migration_group' => $migration_group, 'migration' => $migration->id()]), + ]; + return $build; } diff --git a/src/Controller/MigrationListBuilder.php b/src/Controller/MigrationListBuilder.php index 035195c..ed27f3b 100644 --- a/src/Controller/MigrationListBuilder.php +++ b/src/Controller/MigrationListBuilder.php @@ -99,7 +99,7 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand * @return array * A render array structure of header strings. * - * @see Drupal\Core\Entity\EntityListController::render() + * @see \Drupal\Core\Entity\EntityListController::render() */ public function buildHeader() { $header['label'] = $this->t('Migration'); @@ -110,6 +110,7 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand $header['unprocessed'] = $this->t('Unprocessed'); $header['messages'] = $this->t('Messages'); $header['last_imported'] = $this->t('Last Imported'); + $header['operations'] = $this->t('Operations'); return $header; // + parent::buildHeader(); } @@ -125,56 +126,88 @@ class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHand * @see \Drupal\Core\Entity\EntityListController::render() */ public function buildRow(EntityInterface $migration_entity) { - $migration = $this->migrationPluginManager->createInstance($migration_entity->id()); - $migration_group = $migration->get('migration_group'); - if (!$migration_group) { - $migration_group = 'default'; - } - $route_parameters = array( - 'migration_group' => $migration_group, - 'migration' => $migration->id(), - ); - $row['label'] = array( - 'data' => array( - '#type' => 'link', - '#title' => $migration->label(), - '#url' => Url::fromRoute("entity.migration.overview", $route_parameters), - ), - ); - $row['machine_name'] = $migration->id(); - $row['status'] = $migration->getStatusLabel(); - - // Derive the stats. - $source_plugin = $migration->getSourcePlugin(); - $row['total'] = $source_plugin->count(); - $map = $migration->getIdMap(); - $row['imported'] = $map->importedCount(); - // -1 indicates uncountable sources. - if ($row['total'] == -1) { - $row['total'] = $this->t('N/A'); - $row['unprocessed'] = $this->t('N/A'); + + try { + $migration = $this->migrationPluginManager->createInstance($migration_entity->id()); + $migration_group = $migration->get('migration_group'); + if (!$migration_group) { + $migration_group = 'default'; + } + $route_parameters = array( + 'migration_group' => $migration_group, + 'migration' => $migration->id(), + ); + $row['label'] = array( + 'data' => array( + '#type' => 'link', + '#title' => $migration->label(), + '#url' => Url::fromRoute("entity.migration.overview", $route_parameters), + ), + ); + $row['machine_name'] = $migration->id(); + $row['status'] = $migration->getStatusLabel(); } - else { - $row['unprocessed'] = $row['total'] - $map->processedCount(); + catch(\Exception $e) { + return NULL; } - $row['messages'] = array( - 'data' => array( - '#type' => 'link', - '#title' => $map->messageCount(), - '#url' => Url::fromRoute("migrate_tools.messages", $route_parameters), - ), - ); - $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported'); - $last_imported = $migrate_last_imported_store->get($migration->id(), FALSE); - if ($last_imported) { - /** @var DateFormatter $date_formatter */ - $date_formatter = \Drupal::service('date.formatter'); - $row['last_imported'] = $date_formatter->format($last_imported / 1000, - 'custom', 'Y-m-d H:i:s'); + + try { + // Derive the stats. + $source_plugin = $migration->getSourcePlugin(); + $row['total'] = $source_plugin->count(); + $map = $migration->getIdMap(); + $row['imported'] = $map->importedCount(); + // -1 indicates uncountable sources. + if ($row['total'] == -1) { + $row['total'] = $this->t('N/A'); + $row['unprocessed'] = $this->t('N/A'); + } + else { + $row['unprocessed'] = $row['total'] - $map->processedCount(); + } + $row['messages'] = array( + 'data' => array( + '#type' => 'link', + '#title' => $map->messageCount(), + '#url' => Url::fromRoute("migrate_tools.messages", $route_parameters), + ), + ); + $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported'); + $last_imported = $migrate_last_imported_store->get($migration->id(), FALSE); + if ($last_imported) { + /** @var DateFormatter $date_formatter */ + $date_formatter = \Drupal::service('date.formatter'); + $row['last_imported'] = $date_formatter->format($last_imported / 1000, + 'custom', 'Y-m-d H:i:s'); + } + else { + $row['last_imported'] = ''; + } + + $row['operations']['data'] = array( + '#type' => 'dropbutton', + '#links' => array( + 'simple_form' => array( + 'title' => $this->t('Launch'), + 'url' => Url::fromRoute('migrate_tools.launch', array( + 'migration_group' => $migration_group, + 'migration' => $migration->id() + )), + ), + ), + ); } - else { - $row['last_imported'] = ''; + catch (\Exception $e) { + // Derive the stats. + $row['status'] = $this->t('No data found'); + $row['total'] = $this->t('N/A'); + $row['imported'] = $this->t('N/A'); + $row['unprocessed'] = $this->t('N/A'); + $row['messages'] = $this->t('N/A'); + $row['last_imported'] = $this->t('N/A'); + $row['operations'] = $this->t('N/A'); } + return $row; // + parent::buildRow($migration_entity); } diff --git a/src/Form/MigrationLaunchForm.php b/src/Form/MigrationLaunchForm.php new file mode 100644 index 0000000..e2c7e48 --- /dev/null +++ b/src/Form/MigrationLaunchForm.php @@ -0,0 +1,239 @@ +migrationPluginManager = $migration_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.migration') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'migration_launch_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + + $form = []; + + $form['operations'] = $this->migrateMigrateOperations(); + + return $form; + } + + + /** + * Get Operations. + */ + private function migrateMigrateOperations() { + // Build the 'Update options' form. + $operations = [ + '#type' => 'fieldset', + '#title' => t('Operations'), + ]; + + $options = [ + '' => t('Please select'), + 'import_immediate' => t('Import immediately'), + 'rollback_immediate' => t('Rollback immediately'), + 'stop' => t('Stop'), + 'reset' => t('Reset'), + ]; + $operations['operation'] = [ + '#type' => 'select', + '#title' => t('Operation'), + '#title_display' => 'invisible', + '#options' => $options, + ]; + $operations['submit'] = [ + '#type' => 'submit', + '#value' => t('Execute'), + ]; + $operations['description'] = [ + '#prefix' => '
', + '#markup' => t( + 'Choose an operation to run on all selections above: +