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\Plugin\MigrationPluginManagerInterface;
10 use Drupal\migrate_plus\Entity\MigrationGroupInterface;
11 use Drupal\migrate_plus\Entity\MigrationInterface as MigratePlusMigrationInterface;
12 use Symfony\Component\DependencyInjection\ContainerInterface;
15 * Returns responses for migrate_tools message routes.
17 class MessageController extends ControllerBase {
20 * The database service.
22 * @var \Drupal\Core\Database\Connection
27 * Plugin manager for migration plugins.
29 * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
31 protected $migrationPluginManager;
36 public static function create(ContainerInterface $container) {
38 $container->get('database'),
39 $container->get('plugin.manager.migration')
44 * Constructs a MessageController object.
46 * @param \Drupal\Core\Database\Connection $database
47 * A database connection.
48 * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
49 * The migration plugin manager.
51 public function __construct(Connection $database, MigrationPluginManagerInterface $migration_plugin_manager) {
52 $this->database = $database;
53 $this->migrationPluginManager = $migration_plugin_manager;
57 * Gets an array of log level classes.
60 * An array of log level classes.
62 public static function getLogLevelClassMap() {
64 MigrationInterface::MESSAGE_INFORMATIONAL => 'migrate-message-4',
65 MigrationInterface::MESSAGE_NOTICE => 'migrate-message-3',
66 MigrationInterface::MESSAGE_WARNING => 'migrate-message-2',
67 MigrationInterface::MESSAGE_ERROR => 'migrate-message-1',
72 * Displays a listing of migration messages.
74 * Messages are truncated at 56 chars.
76 * @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
77 * The migration group.
78 * @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
82 * A render array as expected by drupal_render().
84 public function overview(MigrationGroupInterface $migration_group, MigratePlusMigrationInterface $migration) {
86 $classes = static::getLogLevelClassMap();
87 $migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
88 $source_id_field_names = array_keys($migration_plugin->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_plugin->getIdMap()->messageTableName();
108 $map_table = $migration_plugin->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'];