namespace Drupal\migrate_tools\Controller;
+use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Routing\CurrentRouteMatch;
+use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate_plus\Entity\MigrationGroup;
-use Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Drupal\Core\Datetime\DateFormatter;
/**
* Provides a listing of migration entities in a given group.
/**
* Plugin manager for migration plugins.
*
- * @var \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager
+ * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
- protected $migrationConfigEntityPluginManager;
+ protected $migrationPluginManager;
+
+ /**
+ * The logger service.
+ *
+ * @var \Drupal\Core\Logger\LoggerChannelInterface
+ */
+ protected $logger;
/**
* Constructs a new EntityListBuilder object.
* The entity storage class.
* @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match
* The current route match service.
- * @param \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager
+ * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The plugin manager for config entity-based migrations.
+ * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
+ * The logger service.
*/
- public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, CurrentRouteMatch $current_route_match, MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager) {
+ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, CurrentRouteMatch $current_route_match, MigrationPluginManagerInterface $migration_plugin_manager, LoggerChannelInterface $logger) {
parent::__construct($entity_type, $storage);
$this->currentRouteMatch = $current_route_match;
- $this->migrationConfigEntityPluginManager = $migration_config_entity_plugin_manager;
+ $this->migrationPluginManager = $migration_plugin_manager;
+ $this->logger = $logger;
}
/**
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('current_route_match'),
- $container->get('plugin.manager.config_entity_migration')
+ $container->get('plugin.manager.migration'),
+ $container->get('logger.channel.migrate_tools')
);
}
* @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');
$header['unprocessed'] = $this->t('Unprocessed');
$header['messages'] = $this->t('Messages');
$header['last_imported'] = $this->t('Last Imported');
- return $header; // + parent::buildHeader();
+ $header['operations'] = $this->t('Operations');
+ return $header;
}
/**
* @param \Drupal\Core\Entity\EntityInterface $migration_entity
* The migration plugin for which to build the row.
*
- * @return array
+ * @return array|null
* A render array of the table row for displaying the plugin information.
*
- * @see Drupal\Core\Entity\EntityListController::render()
+ * @see \Drupal\Core\Entity\EntityListController::render()
*/
public function buildRow(EntityInterface $migration_entity) {
- $migration = $this->migrationConfigEntityPluginManager->createInstance($migration_entity->id());
- $migration_group = $migration->get('migration_group');
- if (!$migration_group) {
- $migration_group = 'default';
+ try {
+ /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
+ $migration = $this->migrationPluginManager->createInstance($migration_entity->id());
+ $migration_group = $migration->get('migration_group');
+ if (!$migration_group) {
+ $migration_group = 'default';
+ }
+ $route_parameters = [
+ 'migration_group' => $migration_group,
+ 'migration' => $migration->id(),
+ ];
+ $row['label'] = [
+ 'data' => [
+ '#type' => 'link',
+ '#title' => $migration->label(),
+ '#url' => Url::fromRoute("entity.migration.overview", $route_parameters),
+ ],
+ ];
+ $row['machine_name'] = $migration->id();
+ $row['status'] = $migration->getStatusLabel();
}
- $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');
+ catch (PluginException $e) {
+ $this->logger->warning('Migration entity id %id is malformed: %orig', ['%id' => $migration_entity->id(), '%orig' => $e->getMessage()]);
+ return NULL;
}
- 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');
+
+ 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'] = [
+ 'data' => [
+ '#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 \Drupal\Core\Datetime\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'] = [
+ '#type' => 'dropbutton',
+ '#links' => [
+ 'simple_form' => [
+ 'title' => $this->t('Execute'),
+ 'url' => Url::fromRoute('migrate_tools.execute', [
+ 'migration_group' => $migration_group,
+ 'migration' => $migration->id(),
+ ]),
+ ],
+ ],
+ ];
}
- else {
- $row['last_imported'] = '';
+ catch (PluginException $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);
- }
- /**
- * {@inheritdoc}
- */
- public function getDefaultOperations(EntityInterface $entity) {
- $operations = parent::getDefaultOperations($entity);
- $migration_group = $entity->get('migration_group');
- if (!$migration_group) {
- $migration_group = 'default';
- }
-// $this->addGroupParameter($operations['edit']['url'], $migration_group);
-// $this->addGroupParameter($operations['delete']['url'], $migration_group);
- return $operations;
+ return $row;
}
/**
+ * Add group route parameter.
+ *
* @param \Drupal\Core\Url $url
* The URL associated with an operation.
- *
- * @param $migration_group
+ * @param string $migration_group
* The migration's parent group.
*/
protected function addGroupParameter(Url $url, $migration_group) {