reverted: --- b/core/modules/migrate/src/Entity/Migration.php +++ a/core/modules/migrate/src/Entity/Migration.php @@ -15,8 +15,6 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; use Drupal\Component\Utility\NestedArray; -use Drupal\migrate\ExtensionInstallStorage; -use Drupal\Core\Config\StorageInterface; /** * Defines the Migration entity. @@ -536,28 +534,4 @@ return $this->dependencies; } - - /** - * Find all migration templates with the specified tag. - * - * @param $tag - * The tag to match. - * - * @return array - * Any templates (parsed YAML config) that matched, keyed by the ID. - */ - public static function templateQuery($tag) { - $extension_install_storage = new ExtensionInstallStorage(\Drupal::service('config.storage'), ExtensionInstallStorage::MIGRATION_TEMPLATE_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE); - $templates = $extension_install_storage->getAllTemplates(); - $matched_templates = []; - foreach ($templates as $template_name => $template) { - if (!empty($template['migration_tags'])) { - if (in_array($tag, $template['migration_tags'])) { - $matched_templates[$template_name] = $template; - } - } - } - return $matched_templates; - } - } diff -u b/core/modules/migrate/src/ExtensionInstallStorage.php b/core/modules/migrate/src/ExtensionInstallStorage.php --- b/core/modules/migrate/src/ExtensionInstallStorage.php +++ b/core/modules/migrate/src/ExtensionInstallStorage.php @@ -22,7 +22,7 @@ const MIGRATION_TEMPLATE_DIRECTORY = 'migration_templates'; /** - * @inheritdoc + * {@inheritdoc} */ public function __construct(StorageInterface $config_storage, $directory = self::MIGRATION_TEMPLATE_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE) { parent::__construct($config_storage, $directory, $collection, $include_profile); @@ -42,9 +42,7 @@ foreach ($folders as $full_name => $folder) { // The fully qualified name will be in the form migrate.migration.d6_node. // Break out the provider ('migrate') and name ('migration.d6_node'). - $first_dot = strpos($full_name, '.'); - $provider = substr($full_name, 0, $first_dot); - $name = substr($full_name, $first_dot + 1); + list($provider, $name) = explode('.', $full_name, 2); // Retrieve and parse the template contents. $discovery = new YamlDiscovery($name, array($provider => $folder)); $all = $discovery->findAll(); diff -u b/core/modules/migrate/src/Tests/TemplateTest.php b/core/modules/migrate/src/Tests/TemplateTest.php --- b/core/modules/migrate/src/Tests/TemplateTest.php +++ b/core/modules/migrate/src/Tests/TemplateTest.php @@ -7,7 +7,7 @@ namespace Drupal\migrate\Tests; -use Drupal\migrate\Entity\Migration; +use Drupal\migrate\MigrationStorage; /** * Test the migration template functionality. @@ -27,18 +27,28 @@ * Test different connection types. */ public function testTemplates() { - $migration_templates = Migration::templateQuery("Template Test"); - $expected = [ + /** @var MigrationStorage $migration_storage */ + $migration_storage = \Drupal::entityManager()->getStorage('migration'); + $migration_templates = $migration_storage->findTemplatesByTag("Template Test"); + $expected_url = [ 'id' => 'url_template', - 'label' => 'Template test', + 'label' => 'Template test - url', 'migration_tags' => ['Template Test'], 'source' => ['plugin' => 'empty'], 'process' => ['src' => 'foobar'], 'destination' => ['plugin' => 'url_alias'], ]; - - $this->assertIdentical($migration_templates['migrate.migration.url_template'], $expected); - + $expected_node = [ + 'id' => 'node_template', + 'label' => 'Template test - node', + 'migration_tags' => ['Template Test'], + 'source' => ['plugin' => 'empty'], + 'process' => ['src' => 'barfoo'], + 'destination' => ['plugin' => 'entity:node'], + ]; + $this->assertIdentical($migration_templates['migrate.migration.url_template'], $expected_url); + $this->assertIdentical($migration_templates['migrate.migration.node_template'], $expected_node); + $this->assertFalse(isset($migration_templates['migrate.migration.other_template'])); } } diff -u b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.url_template.yml b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.url_template.yml --- b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.url_template.yml +++ b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.url_template.yml @@ -1,5 +1,5 @@ id: url_template -label: Template test +label: Template test - url migration_tags: - Template Test source: diff -u b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php --- b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php @@ -9,6 +9,7 @@ use Drupal\migrate\Tests\MigrateTestBase; use Drupal\migrate\Entity\Migration; +use Drupal\migrate\MigrationStorage; use Drupal\Component\Plugin\Exception\PluginNotFoundException; /** @@ -52,7 +53,9 @@ * Drupal version as provided in migration_tags - e.g., 'Drupal 6'. */ protected function installMigrations($version) { - $migration_templates = Migration::templateQuery($version); + /** @var MigrationStorage $migration_storage */ + $migration_storage = \Drupal::entityManager()->getStorage('migration'); + $migration_templates = $migration_storage->findTemplatesByTag($version); foreach ($migration_templates as $template_name => $template) { try { $migration = Migration::create($template); only in patch2: unchanged: --- a/core/modules/migrate/src/MigrationStorage.php +++ b/core/modules/migrate/src/MigrationStorage.php @@ -9,6 +9,12 @@ use Drupal\Component\Graph\Graph; use Drupal\Core\Config\Entity\ConfigEntityStorage; +use Drupal\Core\Config\StorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Storage for migration entities. @@ -16,6 +22,46 @@ class MigrationStorage extends ConfigEntityStorage implements MigrateBuildDependencyInterface { /** + * Extension storage is used for finding templates. + * + * @var \Drupal\migrate\ExtensionInstallStorage + */ + protected $extensionInstallStorage; + + /** + * Constructs a ConfigEntityStorage object. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service + * The UUID service. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. + * @param \Drupal\Core\Config\StorageInterface $config_storage + * The storage object to use for reading configuration data. + */ + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, StorageInterface $config_storage) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + + $this->extensionInstallStorage = new ExtensionInstallStorage($config_storage, ExtensionInstallStorage::MIGRATION_TEMPLATE_DIRECTORY); + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('config.factory'), + $container->get('uuid'), + $container->get('language_manager'), + $container->get('config.storage') + ); + } + + /** * {@inheritdoc} */ public function buildDependencyMigration(array $migrations, array $dynamic_ids) { @@ -90,4 +136,26 @@ protected function addDependency(array &$graph, $id, $dependency, $dynamic_ids) $graph[$id]['edges'] += array_combine($dependencies, $dependencies); } + /** + * Find all migration templates with the specified tag. + * + * @param $tag + * The tag to match. + * + * @return array + * Any templates (parsed YAML config) that matched, keyed by the ID. + */ + public function findTemplatesByTag($tag) { + $templates = $this->extensionInstallStorage->getAllTemplates(); + $matched_templates = []; + foreach ($templates as $template_name => $template) { + if (!empty($template['migration_tags'])) { + if (in_array($tag, $template['migration_tags'])) { + $matched_templates[$template_name] = $template; + } + } + } + return $matched_templates; + } + } only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.node_template.yml @@ -0,0 +1,10 @@ +id: node_template +label: Template test - node +migration_tags: + - Template Test +source: + plugin: empty +process: + src: barfoo +destination: + plugin: entity:node only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/tests/modules/template_test/migration_templates/migrate.migration.other_template.yml @@ -0,0 +1,10 @@ +id: other_template +label: Template with a different tag +migration_tags: + - Different Template Test +source: + plugin: empty +process: + src: raboof +destination: + plugin: entity:user only in patch2: unchanged: --- a/core/modules/migrate_drupal/src/MigrationStorage.php +++ b/core/modules/migrate_drupal/src/MigrationStorage.php @@ -19,6 +19,7 @@ use Drupal\migrate\MigrationStorage as BaseMigrationStorage; use Drupal\migrate_drupal\Plugin\MigratePluginManager; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Config\StorageInterface; /** * Storage for migration entities. @@ -48,11 +49,13 @@ class MigrationStorage extends BaseMigrationStorage { * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Config\StorageInterface $config_storage + * The storage object to use for reading configuration data. * @param \Drupal\migrate_drupal\Plugin\MigratePluginManager * The cckfield plugin manager. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, MigratePluginManager $cck_plugin_manager) { - parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, StorageInterface $config_storage, MigratePluginManager $cck_plugin_manager) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $config_storage); $this->cckPluginManager = $cck_plugin_manager; } @@ -65,6 +68,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('config.factory'), $container->get('uuid'), $container->get('language_manager'), + $container->get('config.storage'), $container->get('plugin.manager.migrate.cckfield') ); }