clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_tools\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\PagerSelectExtender;
use Drupal\Core\Database\Query\TableSortExtender;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate_plus\Entity\MigrationGroupInterface;
use Drupal\migrate_plus\Entity\MigrationInterface as MigratePlusMigrationInterface;
use Drupal\migrate_tools\MigrateTools;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Returns responses for migrate_tools message routes.
*/
class MessageController extends ControllerBase {
protected Connection $database;
protected MigrationPluginManagerInterface $migrationPluginManager;
/**
* Constructs a MessageController object.
*
* @param \Drupal\Core\Database\Connection $database
* A database connection.
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The migration plugin manager.
*/
public function __construct(Connection $database, MigrationPluginManagerInterface $migration_plugin_manager) {
$this->database = $database;
$this->migrationPluginManager = $migration_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new static(
$container->get('database'),
$container->get('plugin.manager.migration')
);
}
/**
* Gets an array of log level classes.
*
* @return array
* An array of log level classes.
*/
public static function getLogLevelClassMap(): array {
return [
MigrationInterface::MESSAGE_INFORMATIONAL => 'migrate-message-4',
MigrationInterface::MESSAGE_NOTICE => 'migrate-message-3',
MigrationInterface::MESSAGE_WARNING => 'migrate-message-2',
MigrationInterface::MESSAGE_ERROR => 'migrate-message-1',
];
}
/**
* Displays a listing of migration messages.
*
* Messages are truncated at 56 chars.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return array
* A render array as expected by drupal_render().
*/
public function overview(MigrationGroupInterface $migration_group, MigratePlusMigrationInterface $migration): array {
$header = [];
$build = [];
$rows = [];
$classes = static::getLogLevelClassMap();
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration_plugin */
$migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
$source_id_field_names = array_keys($migration_plugin->getSourcePlugin()->getIds());
$column_number = 1;
foreach ($source_id_field_names as $source_id_field_name) {
$header[] = [
'data' => $source_id_field_name,
'field' => 'sourceid' . $column_number++,
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
];
}
$header[] = [
'data' => $this->t('Severity level'),
'field' => 'level',
'class' => [RESPONSIVE_PRIORITY_LOW],
];
$header[] = [
'data' => $this->t('Message'),
'field' => 'message',
];
$header[] = [
'data' => $this->t('Destination ID'),
'field' => 'destid',
];
$header[] = [
'data' => $this->t('Status'),
'field' => 'source_row_status',
];
$result = [];
$message_table = $migration_plugin->getIdMap()->messageTableName();
if ($this->database->schema()->tableExists($message_table)) {
$map_table = $migration_plugin->getIdMap()->mapTableName();
$query = $this->database->select($message_table, 'msg')
->extend(PagerSelectExtender::class)
->extend(TableSortExtender::class);
$query->innerJoin($map_table, 'map', 'msg.source_ids_hash=map.source_ids_hash');
$query->fields('msg');
$query->fields('map');
$result = $query
->limit(50)
->orderByHeader($header)
->execute();
}
$level_mapping = MigrateTools::getLogLevelLabelMapping();
$status_mapping = MigrateTools::getStatusLevelLabelMapping();
foreach ($result as $message_row) {
$column_number = 1;
$data = [];
foreach ($source_id_field_names as $source_id_field_name) {
$column_name = 'sourceid' . $column_number++;
$data[$column_name] = $message_row->$column_name;
}
$data['level'] = $level_mapping[$message_row->level] ?: $message_row->level;
$data['message'] = $message_row->message;
$column_number = 1;
foreach ($migration_plugin->getDestinationPlugin()->getIds() as $dest_id_field_name => $dest_id_schema) {
$column_name = 'destid' . $column_number++;
$data['destid']['data'][] = $message_row->$column_name;
$data['destid']['#destination_fields'][$dest_id_field_name] =
$data['destid']['#destination_fields'][$column_name] = $message_row->$column_name;
}
$destid = array_filter($data['destid']['data']);
$data['destid']['data'] = [
'#markup' => $destid ? implode(MigrateTools::DEFAULT_ID_LIST_DELIMITER, $data['destid']['data']) : '',
];
$data['status'] = $status_mapping[$message_row->source_row_status];
$rows[] = [
'class' => [
Html::getClass('migrate-message-' . $message_row->level),
$classes[$message_row->level],
],
'data' => $data,
];
}
$build['message_table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => ['id' => $message_table, 'class' => [$message_table]],
'#empty' => $this->t('No messages for this migration.'),
];
$build['message_pager'] = ['#type' => 'pager'];
return $build;
}
/**
* Get the title of the page.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The translated title.
*/
public function title(MigrationGroupInterface $migration_group, MigratePlusMigrationInterface $migration): TranslatableMarkup {
return $this->t(
'Messages of %migration',
['%migration' => $migration->label()]
);
}
}

View File

@@ -0,0 +1,272 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_tools\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\Core\Url;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate_plus\Entity\MigrationGroupInterface;
use Drupal\migrate_plus\Entity\MigrationInterface;
use Drupal\migrate_tools\MigrateBatchExecutable;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Returns responses for migrate_tools migration view routes.
*/
class MigrationController extends ControllerBase implements ContainerInjectionInterface {
protected MigrationPluginManagerInterface $migrationPluginManager;
protected CurrentRouteMatch $currentRouteMatch;
/**
* Constructs a new MigrationController object.
*
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The plugin manager for config entity-based migrations.
* @param \Drupal\Core\Routing\CurrentRouteMatch $currentRouteMatch
* The current route match.
*/
public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, CurrentRouteMatch $currentRouteMatch) {
$this->migrationPluginManager = $migration_plugin_manager;
$this->currentRouteMatch = $currentRouteMatch;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new static(
$container->get('plugin.manager.migration'),
$container->get('current_route_match')
);
}
/**
* Displays an overview of a migration entity.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return array
* A render array as expected by drupal_render().
*/
public function overview(MigrationGroupInterface $migration_group, MigrationInterface $migration): array {
$build = [];
$build['overview'] = [
'#type' => 'fieldset',
'#title' => $this->t('Overview'),
];
$build['overview']['group'] = [
'#title' => $this->t('Group:'),
'#markup' => Xss::filterAdmin($migration_group->label()),
'#type' => 'item',
];
$build['overview']['description'] = [
'#title' => $this->t('Description:'),
'#markup' => Xss::filterAdmin($migration->label()),
'#type' => 'item',
];
$migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
$migration_dependencies = $migration_plugin->getMigrationDependencies();
if (!empty($migration_dependencies['required'])) {
$build['overview']['dependencies'] = [
'#title' => $this->t('Migration Dependencies') ,
'#markup' => Xss::filterAdmin(implode(', ', $migration_dependencies['required'])),
'#type' => 'item',
];
}
if (!empty($migration_dependencies['optional'])) {
$build['overview']['soft_dependencies'] = [
'#title' => $this->t('Soft Migration Dependencies'),
'#markup' => Xss::filterAdmin(implode(', ', $migration_dependencies['optional'])),
'#type' => 'item',
];
}
return $build;
}
/**
* Display source information of a migration entity.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return array
* A render array as expected by drupal_render().
*/
public function source(MigrationGroupInterface $migration_group, MigrationInterface $migration): array {
$build = [];
// Source field information.
$build['source'] = [
'#type' => 'fieldset',
'#title' => $this->t('Source'),
'#group' => 'detail',
'#description' => $this->t('<p>These are the fields available from the source of this migration task. The machine names listed here may be used as sources in the process pipeline.</p>'),
'#description_display' => 'after',
'#attributes' => [
'id' => 'migration-detail-source',
],
];
$migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
$source = $migration_plugin->getSourcePlugin();
$build['source']['query'] = [
'#type' => 'item',
'#title' => $this->t('Query'),
'#markup' => '<pre>' . Xss::filterAdmin($source) . '</pre>',
];
$header = [$this->t('Machine name'), $this->t('Description')];
$rows = [];
foreach ($source->fields($migration_plugin) as $machine_name => $description) {
$rows[] = [
['data' => Html::escape($machine_name)],
['data' => Xss::filterAdmin($description)],
];
}
$build['source']['fields'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No fields'),
];
return $build;
}
/**
* Display process information of a migration entity.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return array
* A render array as expected by drupal_render().
*/
public function process(MigrationGroupInterface $migration_group, MigrationInterface $migration): array {
$build = [];
$migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
// Process information.
$build['process'] = [
'#type' => 'fieldset',
'#title' => $this->t('Process'),
];
$header = [
$this->t('Destination'),
$this->t('Source'),
$this->t('Process plugin'),
$this->t('Default'),
];
$rows = [];
foreach ($migration_plugin->getProcess() as $destination_id => $process_line) {
$row = [];
$row[] = ['data' => Html::escape($destination_id)];
if (isset($process_line[0]['source'])) {
if (is_array($process_line[0]['source'])) {
$process_line[0]['source'] = implode(', ', $process_line[0]['source']);
}
$row[] = ['data' => Xss::filterAdmin($process_line[0]['source'])];
}
else {
$row[] = '';
}
if (isset($process_line[0]['plugin'])) {
$process_line_plugins = [];
foreach ($process_line as $process_line_row) {
$process_line_plugins[] = Xss::filterAdmin($process_line_row['plugin']);
}
$row[] = ['data' => implode(', ', $process_line_plugins)];
}
else {
$row[] = '';
}
if (isset($process_line[0]['default_value'])) {
$row[] = ['data' => Xss::filterAdmin($process_line[0]['default_value'])];
}
else {
$row[] = '';
}
$rows[] = $row;
}
$build['process']['fields'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No process defined.'),
];
return $build;
}
/**
* Displays destination information of a migration entity.
*
* @param \Drupal\migrate_plus\Entity\MigrationGroupInterface $migration_group
* The migration group.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* The $migration.
*
* @return array
* A render array as expected by drupal_render().
*/
public function destination(MigrationGroupInterface $migration_group, MigrationInterface $migration): array {
$build = [];
$migration_plugin = $this->migrationPluginManager->createInstance($migration->id(), $migration->toArray());
// Destination field information.
$build['destination'] = [
'#type' => 'fieldset',
'#title' => $this->t('Destination'),
'#group' => 'detail',
'#description' => $this->t('<p>These are the fields available in the destination plugin of this migration task. The machine names are those available to be used as the keys in the process pipeline.</p>'),
'#description_display' => 'after',
'#attributes' => [
'id' => 'migration-detail-destination',
],
];
$destination = $migration_plugin->getDestinationPlugin();
$build['destination']['type'] = [
'#type' => 'item',
'#title' => $this->t('Type'),
'#markup' => Xss::filterAdmin($destination->getPluginId()),
];
$header = [$this->t('Machine name'), $this->t('Description')];
$rows = [];
$destination_fields = $destination->fields() ?: [];
foreach ($destination_fields as $machine_name => $description) {
$rows[] = [
['data' => Html::escape($machine_name)],
['data' => Xss::filterAdmin($description)],
];
}
$build['destination']['fields'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No fields'),
];
return $build;
}
}

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_tools\Controller;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Provides a listing of migration group entities.
*
* @package Drupal\migrate_tools\Controller
*
* @ingroup migrate_tools
*/
class MigrationGroupListBuilder extends ConfigEntityListBuilder {
/**
* Builds the header row for the entity listing.
*
* @return array
* A render array structure of header strings.
*
* @see \Drupal\Core\Entity\Controller\EntityListController::render()
*/
public function buildHeader(): array {
$header = [];
$header['label'] = $this->t('Migration Group');
$header['machine_name'] = $this->t('Machine Name');
$header['description'] = $this->t('Description');
$header['source_type'] = $this->t('Source Type');
return $header + parent::buildHeader();
}
/**
* Builds a row for an entity in the entity listing.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for which to build the row.
*
* @return array
* A render array of the table row for displaying the entity.
*
* @see \Drupal\Core\Entity\EntityListController::render()
*/
public function buildRow(EntityInterface $entity): array {
$row = [];
$row['label'] = $entity->label();
$row['machine_name'] = $entity->id();
$row['description'] = $entity->get('description');
$row['source_type'] = $entity->get('source_type');
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity): array {
$operations = parent::getDefaultOperations($entity);
$operations['list'] = [
'title' => $this->t('List migrations'),
'weight' => 0,
'url' => Url::fromRoute('entity.migration.list', ['migration_group' => $entity->id()]),
];
return $operations;
}
}

View File

@@ -0,0 +1,247 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_tools\Controller;
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\Routing\CurrentRouteMatch;
use Drupal\Core\Url;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_plus\Entity\MigrationGroup;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a listing of migration entities in a given group.
*
* @package Drupal\migrate_tools\Controller
*
* @ingroup migrate_tools
*/
class MigrationListBuilder extends ConfigEntityListBuilder implements EntityHandlerInterface {
protected CurrentRouteMatch $currentRouteMatch;
protected MigrationPluginManagerInterface $migrationPluginManager;
protected LoggerInterface $logger;
/**
* Constructs a new EntityListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match
* The current route match service.
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The plugin manager for config entity-based migrations.
* @param \Psr\Log\LoggerInterface $logger
* The logger service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, CurrentRouteMatch $current_route_match, MigrationPluginManagerInterface $migration_plugin_manager, LoggerInterface $logger) {
parent::__construct($entity_type, $storage);
$this->currentRouteMatch = $current_route_match;
$this->migrationPluginManager = $migration_plugin_manager;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type): self {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('current_route_match'),
$container->get('plugin.manager.migration'),
$container->get('logger.channel.migrate_tools')
);
}
/**
* Retrieve the migrations belonging to the appropriate group.
*
* @return array
* An array of entity IDs.
*/
protected function getEntityIds(): array {
$migration_group = $this->currentRouteMatch->getParameter('migration_group');
$query = $this->getStorage()->getQuery()
->accessCheck(TRUE)
->sort($this->entityType->getKey('id'));
$migration_groups = MigrationGroup::loadMultiple();
if (array_key_exists($migration_group, $migration_groups)) {
$query->condition('migration_group', $migration_group);
}
else {
$query->notExists('migration_group');
}
// Only add the pager if a limit is specified.
if ($this->limit) {
$query->pager($this->limit);
}
return $query->execute();
}
/**
* Builds the header row for the entity listing.
*
* @return array
* A render array structure of header strings.
*
* @see \Drupal\Core\Entity\EntityListController::render()
*/
public function buildHeader(): array {
$header = [];
$header['label'] = $this->t('Migration');
$header['machine_name'] = $this->t('Machine Name');
$header['status'] = $this->t('Status');
$header['total'] = $this->t('Total');
$header['imported'] = $this->t('Imported');
$header['unprocessed'] = $this->t('Unprocessed');
$header['messages'] = $this->t('Messages');
$header['last_imported'] = $this->t('Last Imported');
$header['operations'] = $this->t('Operations');
return $header;
}
/**
* Builds a row for a migration plugin.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The migration plugin for which to build the row.
*
* @return array
* A render array of the table row for displaying the plugin information.
*
* @see \Drupal\Core\Entity\EntityListController::render()
*/
public function buildRow(EntityInterface $entity): array {
$row = [];
try {
assert($entity instanceof Migration);
$migration = $this->migrationPluginManager->createInstance($entity->id());
if (!$migration) {
return $row;
}
$migration_group = $entity->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();
}
catch (\Exception $e) {
$this->logger->warning('Migration entity id %id is malformed: %orig', [
'%id' => $entity->id(),
'%orig' => $e->getMessage(),
]);
return $row;
}
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((int) ($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(),
]),
],
],
];
}
catch (\Throwable $throwable) {
$this->handleThrowable($row);
}
return $row;
}
/**
* Derive the row data.
*
* @param array $row
* The table row.
*/
protected function handleThrowable(array &$row): void {
$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');
}
/**
* Add group route parameter.
*
* @param \Drupal\Core\Url $url
* The URL associated with an operation.
* @param string $migration_group
* The migration's parent group.
*/
protected function addGroupParameter(Url $url, $migration_group): void {
if (!$migration_group) {
$migration_group = 'default';
}
$route_parameters = $url->getRouteParameters() + ['migration_group' => $migration_group];
$url->setRouteParameters($route_parameters);
}
}