3 namespace Drupal\migrate_tools\Controller;
5 use Drupal\Component\Utility\Html;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\Core\Database\Connection;
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Returns responses for migrate_tools message routes.
15 class MessageController extends ControllerBase {
18 * The database service.
20 * @var \Drupal\Core\Database\Connection
25 * Plugin manager for migration plugins.
27 * @var \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager
29 protected $migrationConfigEntityPluginManager;
34 public static function create(ContainerInterface $container) {
36 $container->get('database'),
37 $container->get('plugin.manager.config_entity_migration')
42 * Constructs a MessageController object.
44 * @param \Drupal\Core\Database\Connection $database
45 * A database connection.
46 * @param \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager
47 * The plugin manager for config entity-based migrations.
49 public function __construct(Connection $database, MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager) {
50 $this->database = $database;
51 $this->migrationConfigEntityPluginManager = $migration_config_entity_plugin_manager;
55 * Gets an array of log level classes.
58 * An array of log level classes.
60 public static function getLogLevelClassMap() {
62 MigrationInterface::MESSAGE_INFORMATIONAL => 'migrate-message-4',
63 MigrationInterface::MESSAGE_NOTICE => 'migrate-message-3',
64 MigrationInterface::MESSAGE_WARNING => 'migrate-message-2',
65 MigrationInterface::MESSAGE_ERROR => 'migrate-message-1',
70 * Displays a listing of migration messages.
72 * Messages are truncated at 56 chars.
74 * @param string $migration_group
75 * Machine name of the migration's group.
77 * @param string $migration
78 * Machine name of the migration.
81 * A render array as expected by drupal_render().
83 public function overview($migration_group, $migration) {
85 $classes = static::getLogLevelClassMap();
86 /** @var MigrationInterface $migration */
87 $migration = $this->migrationConfigEntityPluginManager->createInstance($migration);
88 $source_id_field_names = array_keys($migration->getSourcePlugin()->getIds());
90 foreach ($source_id_field_names as $source_id_field_name) {
92 'data' => $source_id_field_name,
93 'field' => 'sourceid' . $column_number++,
94 'class' => [RESPONSIVE_PRIORITY_MEDIUM],
98 'data' => $this->t('Severity level'),
100 'class' => [RESPONSIVE_PRIORITY_LOW],
103 'data' => $this->t('Message'),
104 'field' => 'message',
107 $message_table = $migration->getIdMap()->messageTableName();
108 $map_table = $migration->getIdMap()->mapTableName();
109 $query = $this->database->select($message_table, 'msg')
110 ->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
111 ->extend('\Drupal\Core\Database\Query\TableSortExtender');
112 $query->innerJoin($map_table, 'map', 'msg.source_ids_hash=map.source_ids_hash');
113 $query->fields('msg');
114 $query->fields('map');
117 ->orderByHeader($header)
120 foreach ($result as $message_row) {
122 foreach ($source_id_field_names as $source_id_field_name) {
123 $column_name = 'sourceid' . $column_number++;
124 $row[$column_name] = $message_row->$column_name;
126 $row['level'] = $message_row->level;
127 $row['message'] = $message_row->message;
128 $row['class'] = [Html::getClass('migrate-message-' . $message_row->level), $classes[$message_row->level]];
132 $build['message_table'] = [
134 '#header' => $header,
136 '#attributes' => ['id' => $message_table, 'class' => [$message_table]],
137 '#empty' => $this->t('No messages for this migration.'),
139 $build['message_pager'] = ['#type' => 'pager'];