metatag.module | 1 - migrations/d7_metatag_field_instance.yml | 2 +- src/Migrate/MigrationPluginAlterer.php | 193 --------------------- .../source/d7/MetatagFieldInstanceDeriver.php | 2 +- 4 files changed, 2 insertions(+), 196 deletions(-) diff --git a/metatag.module b/metatag.module index 64be628..a84c0c7 100644 --- a/metatag.module +++ b/metatag.module @@ -15,7 +15,6 @@ use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; -use Drupal\metatag\Migrate\MigrationPluginAlterer; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Plugin\MigrationInterface; diff --git a/migrations/d7_metatag_field_instance.yml b/migrations/d7_metatag_field_instance.yml index 70d1d78..5be196c 100644 --- a/migrations/d7_metatag_field_instance.yml +++ b/migrations/d7_metatag_field_instance.yml @@ -26,4 +26,4 @@ migration_dependencies: required: # The base field migration is required before this migration can run. - d7_metatag_field - # Relevant required dependencies are added in \Drupal\metatag\Migrate\MigrationPluginAlterer. + # Relevant required dependencies are added in metatag_migration_plugins_alter(). diff --git a/src/Migrate/MigrationPluginAlterer.php b/src/Migrate/MigrationPluginAlterer.php deleted file mode 100644 index 760c973..0000000 --- a/src/Migrate/MigrationPluginAlterer.php +++ /dev/null @@ -1,193 +0,0 @@ -migrationPluginManager = $migration_plugin_manager; - $this->moduleHandler = $module_handler; - $this->connection = $connection; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.migration'), - $container->get('module_handler'), - $container->get('database') - ); - } - - /** - * Adds dependency to the migration derivatives of content entities. - * - * @param mixed[][] $migrations - * An associative array of migrations keyed by migration ID. See - * hook_migration_plugins_alter(). - */ - public function alterMigrationPlugins(array &$migrations) { - $complete_node_migration = $this->isCompleteNodeMigration($migrations); - $metatag_migration_ids = array_keys(array_filter($migrations, function ($migration) { - return $migration['provider'] === 'metatag' && in_array('Drupal 7', $migration['migration_tags']) && !empty($migration['deriver']) && !empty($migration['source']['entity_type_id']); - })); - - foreach ($metatag_migration_ids as $metatag_migration_id) { - $migration_plugin = &$migrations[$metatag_migration_id]; - $migration_plugin += ['migration_dependencies' => []]; - $migration_plugin['migration_dependencies'] += [ - 'required' => [], - 'optional' => [], - ]; - - $target_entity_type_id = $migration_plugin['source']['entity_type_id']; - $target_entity_bundle = $migration_plugin['source']['bundle'] ?? NULL; - $content_entity_migration_id = NULL; - $required_dependencies = []; - - $content_entity_migration_id = ($target_entity_type_id === 'node' && $complete_node_migration) ? 'd7_node_complete' : "d7_$content_entity_migration_id"; - if (!isset($migrations[$content_entity_migration_id])) { - continue; - } - - // If the migration is derived by both entity type and bundle, we - // filter on the potential derived entity migrations, and only add - // what we need. - if ($target_entity_bundle) { - if (isset($migrations["$content_entity_migration_id:$target_entity_bundle"])) { - $required_dependencies[] = "$content_entity_migration_id:$target_entity_bundle"; - } - elseif (isset($migrations[$content_entity_migration_id])) { - $required_dependencies[] = $content_entity_migration_id; - } - } - // If this migration is derived only by entity type, we already know the - // dependencies. - else { - if (isset($migrations[$content_entity_migration_id])) { - $required_dependencies[] = $content_entity_migration_id; - } - } - - $migration_plugin['migration_dependencies']['required'] = array_unique(array_merge($migration_plugin['migration_dependencies']['required'], array_values($required_dependencies))); - } - } - - /** - * Gets the version of the migration's Drupal source instance. - * - * @see \Drupal\migrate_drupal\MigrationConfigurationTrait::getLegacyDrupalVersion() - * - * @param array[] $migrations - * Migration plugins, keyed by the migration plugin ID. - * - * @return string|false - * The version of the source Drupal instance ('5', '6' or '7'), or FALSE if - * it cannot be determined. - */ - protected function getSourceDrupalInstanceVersion(array $migrations) { - $version = FALSE; - // We use the source plugin of the system_site migration only for getting - // the database connection. - $system_site_migration = $migrations['system_site'] ?? NULL; - - if (!$system_site_migration) { - return FALSE; - } - - // We need to get the version of the source database in order to check if - // the classic or complete node tables have been used in a migration. - $source_plugin = $this->migrationPluginManager - ->createStubMigration($system_site_migration) - ->getSourcePlugin(); - if (!($source_plugin instanceof SqlBase)) { - return FALSE; - }; - - try { - $source_connection = $source_plugin->getDatabase(); - $version_string = FALSE; - - if ($source_connection->schema()->tableExists('system')) { - try { - $version_string = $source_connection - ->select('system', 's') - ->fields('s', ['schema_version']) - ->condition('s.name', 'system') - ->execute() - ->fetchField(); - if ($version_string && $version_string[0] == '1' && (int) $version_string >= 1000) { - $version_string = '5'; - } - } - catch (\PDOException $e) { - } - } - - $version = $version_string ? substr($version_string, 0, 1) : FALSE; - } - catch (\Exception $e) { - } - - return $version; - } - - /** - * Determines if complete node migrations are available or not. - * - * @param array $migrations - * - * @return bool - * TRUE if complete node migrations are available, FALSE otherwise. - */ - protected function isCompleteNodeMigration(array $migrations): bool { - if ( - $this->moduleHandler->moduleExists('migrate_drupal') && - $this->moduleHandler->moduleExists('node') && - class_exists(NodeMigrateType::class) - ) { - $source_drupal_version = $this->getSourceDrupalInstanceVersion($migrations); - $node_migrate_type = NodeMigrateType::getNodeMigrateType($this->connection, $source_drupal_version); - return $node_migrate_type === NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE; - } - - return FALSE; - } - -} diff --git a/src/Plugin/migrate/source/d7/MetatagFieldInstanceDeriver.php b/src/Plugin/migrate/source/d7/MetatagFieldInstanceDeriver.php index c4d0aaa..8325592 100644 --- a/src/Plugin/migrate/source/d7/MetatagFieldInstanceDeriver.php +++ b/src/Plugin/migrate/source/d7/MetatagFieldInstanceDeriver.php @@ -144,7 +144,7 @@ class MetatagFieldInstanceDeriver extends DeriverBase implements ContainerDerive // If we have per-bundle results for a content entity type, we are // able to derive migrations per entity type and bundle. - // Dependency metadata is added im \Drupal\metatag\Migrate\MigrationPluginAlterer::alterMigrationPlugins(). + // Dependency metadata is added in metatag_migration_plugins_alter(). if (!empty($metatags_grouped_by_bundle)) { foreach ($metatags_grouped_by_bundle as $bundle_id => $bundle_label) { $derivative_id = "$entity_type_id:$bundle_id";