Commit 9f4d5e84 authored by catch's avatar catch

Issue #2460529 by alexpott, chx, phenaproxima: Migrations need to use the...

Issue #2460529 by alexpott, chx, phenaproxima: Migrations need to use the configuration entity dependency system
parent 45092042
......@@ -498,12 +498,6 @@ protected function findDefaultConfigWithUnmetDependencies(StorageInterface $stor
* TRUE if the dependencies are met, FALSE if not.
*/
protected function validateDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {
// All the migrate tests will fail if we check since they install the
// migrate_drupal module but only set up the dependencies for the single
// migration they are testing.
if (strpos($config_name, 'migrate.migration.') === 0) {
return TRUE;
}
if (isset($data['dependencies'])) {
$all_dependencies = $data['dependencies'];
......
......@@ -198,12 +198,41 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
protected $requirements = [];
/**
* These migrations, if ran at all, must be executed before this migration.
* These migrations, if run, must be executed before this migration.
*
* These are different from the configuration dependencies. Migration
* dependencies are only used to store relationships between migrations.
*
* The migration_dependencies value is structured like this:
* @code
* array(
* 'required' => array(
* // An array of migration IDs that must be run before this migration.
* ),
* 'optional' => array(
* // An array of migration IDs that, if they exist, must be run before
* // this migration.
* ),
* );
* @endcode
*
* @var array
*/
protected $migration_dependencies = [];
/**
* The migration's configuration dependencies.
*
* These store any dependencies on modules or other configuration (including
* other migrations) that must be available before the migration can be
* created.
*
* @see \Drupal\Core\Config\Entity\ConfigDependencyManager
*
* @var array
*/
protected $dependencies = [];
/**
* The entity manager.
*
......@@ -478,6 +507,31 @@ public function setTrackLastImported($track_last_imported) {
* {@inheritdoc}
*/
public function getMigrationDependencies() {
return $this->migration_dependencies;
return $this->migration_dependencies + ['required' => [], 'optional' => []];
}
/**
* {@inheritdoc}
*/
public function trustData() {
// Migrations cannot be trusted since they are often written by hand and not
// through a UI.
$this->trustedData = FALSE;
return $this;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
$this->calculatePluginDependencies($this->getSourcePlugin());
$this->calculatePluginDependencies($this->getDestinationPlugin());
// Add dependencies on required migration dependencies.
foreach ($this->getMigrationDependencies()['required'] as $dependency) {
$this->addDependency('config', $this->getEntityType()->getConfigPrefix() . '.' . $dependency);
}
return $this->dependencies;
}
}
......@@ -68,6 +68,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'id' => "entity:$entity_type",
'class' => $class,
'requirements_met' => 1,
'provider' => $entity_info->getProvider(),
);
}
return $this->derivatives;
......
......@@ -66,6 +66,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'id' => "entity_revision:$entity_type",
'class' => 'Drupal\migrate\Plugin\migrate\destination\EntityRevision',
'requirements_met' => 1,
'provider' => $entity_info->getProvider(),
);
}
}
......
......@@ -6,7 +6,9 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\DependencyTrait;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateException;
......@@ -24,7 +26,8 @@
* id = "config"
* )
*/
class Config extends DestinationBase implements ContainerFactoryPluginInterface {
class Config extends DestinationBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
use DependencyTrait;
/**
* The config object.
......@@ -104,4 +107,13 @@ public function getIds() {
return array();
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$provider = explode('.', $this->config->getName(), 2)[0];
$this->addDependency('module', $provider);
return $this->dependencies;
}
}
......@@ -7,6 +7,8 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Entity\DependencyTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
......@@ -19,7 +21,8 @@
* deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntity"
* )
*/
abstract class Entity extends DestinationBase implements ContainerFactoryPluginInterface {
abstract class Entity extends DestinationBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
use DependencyTrait;
/**
* The entity storage.
......@@ -80,7 +83,6 @@ public static function create(ContainerInterface $container, array $configuratio
*
* @return string
* The entity type.
* @throws \Drupal\migrate\MigrateException
*/
protected static function getEntityTypeId($plugin_id) {
// Remove "entity:"
......@@ -169,4 +171,12 @@ protected function getKey($key) {
return $this->storage->getEntityType()->getKey($key);
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$this->addDependency('module', $this->storage->getEntityType()->getProvider());
return $this->dependencies;
}
}
......@@ -83,7 +83,7 @@ protected function getSource($configuration = [], $migrate_config = [], $status
->willReturn($id_map_array);
$constructor_args = [$configuration, 'd6_action', [], $this->migration];
$methods = ['getModuleHandler', 'fields', 'getIds', '__toString', 'getIterator', 'prepareRow', 'initializeIterator'];
$methods = ['getModuleHandler', 'fields', 'getIds', '__toString', 'getIterator', 'prepareRow', 'initializeIterator', 'calculateDependencies'];
$source_plugin = $this->getMock('\Drupal\migrate\Plugin\migrate\source\SourcePluginBase', $methods, $constructor_args);
$source_plugin
......
......@@ -70,6 +70,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
*/
protected function setUp() {
$module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$migration = $this->getMigration();
$migration->expects($this->any())
......@@ -77,7 +78,7 @@ protected function setUp() {
->will($this->returnValue(static::ORIGINAL_HIGH_WATER));
// Need the test class, not the original because we need a setDatabase method. This is not pretty :/
$plugin_class = preg_replace('/^Drupal\\\\(\w+)\\\\Plugin\\\\migrate(\\\\source(\\\\.+)?\\\\)([^\\\\]+)$/', 'Drupal\\Tests\\\$1\\Unit$2Test$4', static::PLUGIN_CLASS);
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration);
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $entity_manager);
$plugin->setDatabase($this->getDatabase($this->databaseContents + array('test_map' => array())));
$plugin->setModuleHandler($module_handler);
$plugin->setStringTranslation($this->getStringTranslationStub());
......
......@@ -167,4 +167,11 @@ public function fields() {}
*/
public function query() {}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
}
......@@ -11,3 +11,7 @@ process:
destination:
plugin: config
config_name: action.settings
dependencies:
module:
- action
- migrate_drupal
......@@ -22,3 +22,9 @@ destination:
migration_dependencies:
required:
- d6_aggregator_feed
dependencies:
config:
- migrate.migration.d6_aggregator_feed
module:
- aggregator
- migrate_drupal
......@@ -23,3 +23,7 @@ process:
destination:
plugin: config
config_name: aggregator.settings
dependencies:
module:
- aggregator
- migrate_drupal
......@@ -91,3 +91,11 @@ 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
......@@ -5,7 +5,7 @@ migration_tags:
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: empty
plugin: md_empty
constants:
entity_type: block_content
bundle: basic
......@@ -23,3 +23,10 @@ destination:
migration_dependencies:
required:
- d6_block_content_type
dependencies:
config:
- migrate.migration.d6_block_content_type
module:
- block_content
- field
- migrate_drupal
......@@ -5,7 +5,7 @@ migration_tags:
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: empty
plugin: md_empty
constants:
id: basic
label: Basic
......@@ -14,3 +14,7 @@ process:
label: 'constants/label'
destination:
plugin: entity:block_content_type
dependencies:
module:
- block_content
- migrate_drupal
......@@ -20,3 +20,10 @@ destination:
migration_dependencies:
required:
- d6_node
dependencies:
config:
- migrate.migration.d6_node
module:
- book
- migrate_drupal
- node
......@@ -15,3 +15,7 @@ process:
destination:
plugin: config
config_name: book.settings
dependencies:
module:
- book
- migrate_drupal
......@@ -15,3 +15,10 @@ 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,3 +19,11 @@ 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,3 +43,15 @@ 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,3 +24,9 @@ destination:
migration_dependencies:
required:
- d6_comment_field_instance
dependencies:
config:
- migrate.migration.d6_comment_field_instance
module:
- migrate_drupal
- node
......@@ -23,3 +23,9 @@ destination:
migration_dependencies:
required:
- d6_comment_field_instance
dependencies:
config:
- migrate.migration.d6_comment_field_instance
module:
- migrate_drupal
- node
......@@ -30,3 +30,9 @@ destination:
migration_dependencies:
required:
- d6_comment_type
dependencies:
config:
- migrate.migration.d6_comment_type
module:
- comment
- migrate_drupal
......@@ -13,7 +13,15 @@ process:
type: 'constants/type'
'settings/comment_type': comment_type
destination:
plugin: entity:field_storage_config
plugin: md_entity:field_storage_config
migration_dependencies:
required:
- d6_comment_type
dependencies:
config:
- migrate.migration.d6_comment_type
module:
- comment
- field
- migrate_drupal
- node
......@@ -32,3 +32,11 @@ migration_dependencies:
required:
- d6_comment_field
- d6_node_type
dependencies:
config:
- migrate.migration.d6_comment_field
- migrate.migration.d6_node_type
module:
- field
- migrate_drupal
- node
......@@ -13,3 +13,8 @@ process:
description: description
destination:
plugin: entity:comment_type
dependencies:
module:
- comment
- migrate_drupal
- node
......@@ -20,3 +20,7 @@ process:
weight: weight
destination:
plugin: entity:contact_form
dependencies:
module:
- contact
- migrate_drupal
......@@ -20,3 +20,9 @@ destination:
migration_dependencies:
required:
- d6_contact_category
dependencies:
config:
- migrate.migration.d6_contact_category
module:
- contact
- migrate_drupal
......@@ -22,3 +22,10 @@ migration_dependencies:
required:
- d6_filter_format
- d6_block_content_body_field
dependencies:
config:
- migrate.migration.d6_block_content_body_field
- migrate.migration.d6_filter_format
module:
- block_content
- migrate_drupal
......@@ -19,3 +19,6 @@ process:
pattern: value
destination:
plugin: entity:date_format
dependencies:
module:
- migrate_drupal
......@@ -11,3 +11,7 @@ process:
destination:
plugin: config
config_name: dblog.settings
dependencies:
module:
- dblog
- migrate_drupal
......@@ -130,4 +130,9 @@ process:
- widget_settings
destination:
plugin: entity:field_storage_config
plugin: md_entity:field_storage_config
dependencies:
module:
- field
- migrate_drupal
- node
......@@ -255,3 +255,10 @@ migration_dependencies:
required:
- d6_field_instance
- d6_view_modes
dependencies:
config:
- migrate.migration.d6_field_instance
- migrate.migration.d6_view_modes
module:
- migrate_drupal
- node
......@@ -49,3 +49,11 @@ migration_dependencies:
required:
- d6_node_type
- d6_field
dependencies:
config:
- migrate.migration.d6_field
- migrate.migration.d6_node_type
module:
- field
- migrate_drupal
- node
......@@ -59,3 +59,9 @@ destination:
migration_dependencies:
required:
- d6_field_instance
dependencies:
config:
- migrate.migration.d6_field_instance
module:
- migrate_drupal
- node
......@@ -23,3 +23,7 @@ process:
uid: uid
destination:
plugin: entity:file
dependencies:
module:
- file
- migrate_drupal
......@@ -15,3 +15,7 @@ process:
destination:
plugin: config
config_name: file.settings
dependencies:
module:
- file
- migrate_drupal
......@@ -43,3 +43,7 @@ process:
destination:
plugin: entity:filter_format
no_stub: true
dependencies:
module:
- filter
- migrate_drupal
......@@ -27,3 +27,9 @@ destination:
migration_dependencies:
required:
- d6_taxonomy_vocabulary
dependencies:
config:
- migrate.migration.d6_taxonomy_vocabulary
module:
- forum
- migrate_drupal
......@@ -13,3 +13,7 @@ process:
destination:
plugin: config
config_name: locale.settings
dependencies:
module:
- locale
- migrate_drupal
......@@ -10,3 +10,7 @@ process:
description: description
destination:
plugin: entity:menu
dependencies:
module:
- migrate_drupal
- system
......@@ -44,3 +44,9 @@ destination:
migration_dependencies:
required:
- d6_menu
dependencies:
config:
- migrate.migration.d6_menu
module:
- menu_link_content
- migrate_drupal
......@@ -15,3 +15,7 @@ process:
destination:
plugin: config
config_name: menu_ui.settings
dependencies:
module:
- menu_ui
- migrate_drupal