Commit 74d72d1b authored by alexpott's avatar alexpott
Browse files

Issue #2463909 by phenaproxima, mikeryan: Migrations should support...

Issue #2463909 by phenaproxima, mikeryan: Migrations should support non-installed default configurations (templates)
parent 92b34d64
......@@ -5,6 +5,9 @@ services:
- { name: cache.bin }
factory: cache_factory:get
arguments: [migrate]
migrate.template_storage:
class: Drupal\migrate\MigrateTemplateStorage
arguments: ['@config.storage']
plugin.manager.migrate.source:
class: Drupal\migrate\Plugin\MigratePluginManager
arguments: [source, '@container.namespaces', '@cache.discovery', '@module_handler', 'Drupal\migrate\Annotation\MigrateSource']
......
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateTemplateStorage.
*/
namespace Drupal\migrate;
use Drupal\Component\Discovery\YamlDiscovery;
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageInterface;
/**
* Storage to access migration template configuration in enabled extensions.
*/
class MigrateTemplateStorage extends ExtensionInstallStorage {
/**
* Extension sub-directory containing default configuration for migrations.
*/
const MIGRATION_TEMPLATE_DIRECTORY = 'migration_templates';
/**
* {@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);
}
/**
* 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->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;
}
/**
* Retrieves all migration templates belonging to enabled extensions.
*
* @return array
* Array of parsed templates, keyed by the fully-qualified id.
*/
public function getAllTemplates() {
// Retrieve the full list of templates, keyed by fully-qualified name,
// with the containing folder as the value.
$folders = $this->getAllFolders();
$templates = [];
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').
list($provider, $name) = explode('.', $full_name, 2);
// Retrieve and parse the template contents.
$discovery = new YamlDiscovery($name, array($provider => $folder));
$all = $discovery->findAll();
$templates[$full_name] = reset($all);
}
return $templates;
}
}
<?php
/**
* @file
* Contains \Drupal\migrate\Tests\TemplateTest
*/
namespace Drupal\migrate\Tests;
use Drupal\migrate\MigrationStorage;
/**
* Test the migration template functionality.
*
* @group migrate
*/
class TemplateTest extends MigrateTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('template_test');
/**
* Test different connection types.
*/
public function testTemplates() {
$migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag("Template Test");
$expected_url = [
'id' => 'url_template',
'label' => 'Template test - url',
'migration_tags' => ['Template Test'],
'source' => ['plugin' => 'empty'],
'process' => ['src' => 'foobar'],
'destination' => ['plugin' => 'url_alias'],
];
$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']));
}
}
id: node_template
label: Template test - node
migration_tags:
- Template Test
source:
plugin: empty
process:
src: barfoo
destination:
plugin: entity:node
id: other_template
label: Template with a different tag
migration_tags:
- Different Template Test
source:
plugin: empty
process:
src: raboof
destination:
plugin: entity:user
id: url_template
label: Template test - url
migration_tags:
- Template Test
source:
plugin: empty
process:
src: foobar
destination:
plugin: url_alias
name: 'Migration template test'
type: module
package: Testing
version: VERSION
core: 8.x
......@@ -11,7 +11,3 @@ process:
destination:
plugin: config
config_name: action.settings
dependencies:
module:
- action
- migrate_drupal
......@@ -4,7 +4,6 @@ migration_tags:
- Drupal 6
source:
plugin: d6_aggregator_feed
process:
fid: fid
title: title
......@@ -16,10 +15,5 @@ process:
image: image
etag: etag
modified: modified
destination:
plugin: entity:aggregator_feed
dependencies:
module:
- aggregator
- migrate_drupal
......@@ -22,9 +22,3 @@ destination:
migration_dependencies:
required:
- d6_aggregator_feed
dependencies:
config:
- migrate.migration.d6_aggregator_feed
module:
- aggregator
- migrate_drupal
......@@ -23,7 +23,3 @@ process:
destination:
plugin: config
config_name: aggregator.settings
dependencies:
module:
- aggregator
- migrate_drupal
......@@ -92,11 +92,3 @@ migration_dependencies:
- d6_menu
- d6_custom_block
- d6_user_role
dependencies:
config:
- migrate.migration.d6_custom_block
- migrate.migration.d6_menu
- migrate.migration.d6_user_role
module:
- block
- migrate_drupal
......@@ -23,10 +23,3 @@ destination:
migration_dependencies:
required:
- d6_block_content_type
dependencies:
config:
- migrate.migration.d6_block_content_type
module:
- block_content
- field
- migrate_drupal
......@@ -14,7 +14,3 @@ process:
label: 'constants/label'
destination:
plugin: entity:block_content_type
dependencies:
module:
- block_content
- migrate_drupal
......@@ -21,10 +21,3 @@ destination:
migration_dependencies:
required:
- d6_node
dependencies:
config:
- migrate.migration.d6_node
module:
- book
- migrate_drupal
- node
......@@ -15,7 +15,3 @@ process:
destination:
plugin: config
config_name: book.settings
dependencies:
module:
- book
- migrate_drupal
......@@ -15,10 +15,3 @@ migration_dependencies:
required:
- d6_cck_field_values
- d6_node_revision
dependencies:
config:
- migrate.migration.d6_cck_field_values
- migrate.migration.d6_node_revision
module:
- migrate_drupal
- node
......@@ -19,11 +19,3 @@ migration_dependencies:
- d6_node
- d6_field_formatter_settings
- d6_field_instance_widget_settings
dependencies:
config:
- migrate.migration.d6_field_formatter_settings
- migrate.migration.d6_field_instance_widget_settings
- migrate.migration.d6_node
module:
- migrate_drupal
- node
......@@ -43,15 +43,3 @@ migration_dependencies:
- d6_comment_entity_display
- d6_comment_entity_form_display
- d6_filter_format
dependencies:
config:
- migrate.migration.d6_comment_entity_display
- migrate.migration.d6_comment_entity_form_display
- migrate.migration.d6_comment_type
- migrate.migration.d6_filter_format
- migrate.migration.d6_node
- migrate.migration.d6_user
module:
- comment
- migrate_drupal
- node
......@@ -24,9 +24,3 @@ destination:
migration_dependencies:
required:
- d6_comment_field_instance
dependencies:
config:
- migrate.migration.d6_comment_field_instance
module:
- migrate_drupal
- node
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment