Move all files to 2017/
This commit is contained in:
parent
ac7370f67f
commit
2875863330
15717 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,10 @@
|
|||
# Migrations with any of these tags will raise an exception if their source
|
||||
# plugin is missing the source_module property in their annotation.
|
||||
enforce_source_module_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
# Migrations with any of these tags will not be derived and executed with the
|
||||
# other migrations. They will be derived and executed after the migrations on
|
||||
# which they depend have been successfully executed.
|
||||
follow_up_migration_tags:
|
||||
- Follow-up migration
|
|
@ -0,0 +1,16 @@
|
|||
migrate_drupal.settings:
|
||||
type: config_object
|
||||
label: 'Migrate Drupal settings'
|
||||
mapping:
|
||||
enforce_source_module_tags:
|
||||
type: sequence
|
||||
label: 'source_module enforcement tags'
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Tag'
|
||||
follow_up_migration_tags:
|
||||
type: sequence
|
||||
label: 'Follow-up migration tags'
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Tag'
|
|
@ -0,0 +1,8 @@
|
|||
name: Migrate Drupal
|
||||
type: module
|
||||
description: 'Contains migrations from older Drupal versions.'
|
||||
package: Migration
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:migrate
|
33
2017/web/core/modules/migrate_drupal/migrate_drupal.install
Normal file
33
2017/web/core/modules/migrate_drupal/migrate_drupal.install
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains install and update functions for Migrate Drupal
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates migrate_drupal.settings config object.
|
||||
*/
|
||||
function migrate_drupal_update_8501() {
|
||||
\Drupal::configFactory()
|
||||
->getEditable('migrate_drupal.settings')
|
||||
->set('enforce_source_module_tags', ['Drupal 6', 'Drupal 7'])
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the follow-up migration tags.
|
||||
*/
|
||||
function migrate_drupal_update_8502() {
|
||||
\Drupal::configFactory()
|
||||
->getEditable('migrate_drupal.settings')
|
||||
->set('follow_up_migration_tags', ['Follow-up migration'])
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install migrate_drupal_multilingual since migrate_drupal is installed.
|
||||
*/
|
||||
function migrate_drupal_update_8601() {
|
||||
\Drupal::service('module_installer')->install(['migrate_drupal_multilingual']);
|
||||
}
|
86
2017/web/core/modules/migrate_drupal/migrate_drupal.module
Normal file
86
2017/web/core/modules/migrate_drupal/migrate_drupal.module
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides migration from other Drupal sites.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\DatabaseExceptionWrapper;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function migrate_drupal_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.migrate_drupal':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Migrate Drupal module provides a framework based on the <a href=":migrate">Migrate module</a> to facilitate migration from a Drupal (6, 7, or 8) site to your website. It does not provide a user interface. For more information, see the <a href=":migrate_drupal">online documentation for the Migrate Drupal module</a>.', [':migrate' => \Drupal::url('help.page', ['name' => 'migrate']), ':migrate_drupal' => 'https://www.drupal.org/documentation/modules/migrate_drupal']) . '</p>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_migration_plugins_alter().
|
||||
*/
|
||||
function migrate_drupal_migration_plugins_alter(&$definitions) {
|
||||
// This is why the deriver can't do this: the 'd6_taxonomy_vocabulary'
|
||||
// definition is not available to the deriver as it is running inside
|
||||
// getDefinitions().
|
||||
if (isset($definitions['d6_taxonomy_vocabulary'])) {
|
||||
$vocabulary_migration_definition = [
|
||||
'source' => [
|
||||
'ignore_map' => TRUE,
|
||||
'plugin' => 'd6_taxonomy_vocabulary',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
'idMap' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
];
|
||||
$vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($vocabulary_migration_definition);
|
||||
|
||||
try {
|
||||
$source_plugin = $vocabulary_migration->getSourcePlugin();
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
$executable = new MigrateExecutable($vocabulary_migration);
|
||||
$process = ['vid' => $definitions['d6_taxonomy_vocabulary']['process']['vid']];
|
||||
foreach ($source_plugin as $row) {
|
||||
$executable->processRow($row, $process);
|
||||
$source_vid = $row->getSourceProperty('vid');
|
||||
$plugin_ids = ['d6_term_node:' . $source_vid, 'd6_term_node_revision:' . $source_vid];
|
||||
foreach ($plugin_ids as $plugin_id) {
|
||||
// Match the field name derivation in d6_vocabulary_field.yml.
|
||||
$field_name = substr('field_' . $row->getDestinationProperty('vid'), 0, 32);
|
||||
|
||||
// The Forum module is expecting 'taxonomy_forums' as the field name
|
||||
// for the forum nodes. The 'forum_vocabulary' source property is
|
||||
// evaluated in Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary
|
||||
// and is set to true if the vocabulary vid being migrated is the
|
||||
// same as the one in the 'forum_nav_vocabulary' variable on the
|
||||
// source site.
|
||||
$destination_vid = $row->getSourceProperty('forum_vocabulary') ? 'taxonomy_forums' : $field_name;
|
||||
$definitions[$plugin_id]['process'][$destination_vid] = 'tid';
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// This code currently runs whenever the definitions are being loaded and
|
||||
// if you have a Drupal 7 source site then the requirements will not be
|
||||
// met for the d6_taxonomy_vocabulary migration.
|
||||
}
|
||||
catch (DatabaseExceptionWrapper $e) {
|
||||
// When the definitions are loaded it is possible the tables will not
|
||||
// exist.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
services:
|
||||
plugin.manager.migrate.field:
|
||||
class: Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager
|
||||
arguments:
|
||||
- field
|
||||
- '@container.namespaces'
|
||||
- '@cache.discovery'
|
||||
- '@module_handler'
|
||||
- '\Drupal\migrate_drupal\Annotation\MigrateField'
|
||||
plugin.manager.migrate.cckfield:
|
||||
class: Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager
|
||||
arguments:
|
||||
- cckfield
|
||||
- '@container.namespaces'
|
||||
- '@cache.discovery'
|
||||
- '@module_handler'
|
||||
- '\Drupal\migrate_drupal\Annotation\MigrateCckField'
|
||||
deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.migrate.field' service instead. See https://www.drupal.org/node/2751897
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Annotation;
|
||||
|
||||
@trigger_error('MigrateCckField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Deprecated: Defines a cckfield plugin annotation object.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*
|
||||
* Plugin Namespace: Plugin\migrate\cckfield
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class MigrateCckField extends MigrateField {
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines a field plugin annotation object.
|
||||
*
|
||||
* Field plugins are responsible for handling the migration of custom fields
|
||||
* (provided by CCK in Drupal 6 and Field API in Drupal 7) to Drupal 8. They are
|
||||
* allowed to alter fieldable entity migrations when these migrations are being
|
||||
* generated, and can compute destination field types for individual fields
|
||||
* during the actual migration process.
|
||||
*
|
||||
* Plugin Namespace: Plugin\migrate\field
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class MigrateField extends Plugin {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct($values) {
|
||||
parent::__construct($values);
|
||||
// Provide default value for core property, in case it's missing.
|
||||
if (empty($this->definition['core'])) {
|
||||
$this->definition['core'] = [6];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* Map of D6 and D7 field types to D8 field type plugin IDs.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $type_map = [];
|
||||
|
||||
/**
|
||||
* The Drupal core version(s) this plugin applies to.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
public $core;
|
||||
|
||||
/**
|
||||
* Identifies the system providing the data the field plugin will read.
|
||||
*
|
||||
* The source_module is expected to be the name of a Drupal module that must
|
||||
* be installed in the source database.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $source_module;
|
||||
|
||||
/**
|
||||
* Identifies the system handling the data the destination plugin will write.
|
||||
*
|
||||
* The destination_module is expected to be the name of a Drupal module on the
|
||||
* destination site that must be installed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $destination_module;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\DependencyInjection\ServiceProviderBase;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Alters container services.
|
||||
*/
|
||||
class MigrateDrupalServiceProvider extends ServiceProviderBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alter(ContainerBuilder $container) {
|
||||
parent::alter($container);
|
||||
|
||||
$container->getDefinition('plugin.manager.migration')
|
||||
->setClass(MigrationPluginManager::class)
|
||||
->addArgument(new Reference('plugin.manager.migrate.source'))
|
||||
->addArgument(new Reference('config.factory'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
|
||||
/**
|
||||
* Configures the appropriate migrations for a given source Drupal database.
|
||||
*/
|
||||
trait MigrationConfigurationTrait {
|
||||
|
||||
/**
|
||||
* The follow-up migration tags.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $followUpMigrationTags;
|
||||
|
||||
/**
|
||||
* Gets the database connection for the source Drupal database.
|
||||
*
|
||||
* @param array $database
|
||||
* Database array representing the source Drupal database.
|
||||
*
|
||||
* @return \Drupal\Core\Database\Connection
|
||||
* The database connection for the source Drupal database.
|
||||
*/
|
||||
protected function getConnection(array $database) {
|
||||
// Set up the connection.
|
||||
Database::addConnectionInfo('upgrade', 'default', $database);
|
||||
$connection = Database::getConnection('default', 'upgrade');
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the system data from the system table of the source Drupal database.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* Database connection to the source Drupal database.
|
||||
*
|
||||
* @return array
|
||||
* The system data from the system table of the source Drupal database.
|
||||
*/
|
||||
protected function getSystemData(Connection $connection) {
|
||||
$system_data = [];
|
||||
try {
|
||||
$results = $connection->select('system', 's', [
|
||||
'fetch' => \PDO::FETCH_ASSOC,
|
||||
])
|
||||
->fields('s')
|
||||
->execute();
|
||||
foreach ($results as $result) {
|
||||
$system_data[$result['type']][$result['name']] = $result;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// The table might not exist for example in tests.
|
||||
}
|
||||
return $system_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the necessary state entries for SqlBase::getDatabase() to work.
|
||||
*
|
||||
* The state entities created here have to exist before migration plugin
|
||||
* instances are created so that derivers such as
|
||||
* \Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver can access the source
|
||||
* database.
|
||||
*
|
||||
* @param array $database
|
||||
* The source database settings.
|
||||
* @param string $drupal_version
|
||||
* The Drupal version.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()
|
||||
*/
|
||||
protected function createDatabaseStateSettings(array $database, $drupal_version) {
|
||||
$database_state['key'] = 'upgrade';
|
||||
$database_state['database'] = $database;
|
||||
$database_state_key = 'migrate_drupal_' . $drupal_version;
|
||||
\Drupal::state()->set($database_state_key, $database_state);
|
||||
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the migrations for import.
|
||||
*
|
||||
* @param string $database_state_key
|
||||
* The state key.
|
||||
* @param int $drupal_version
|
||||
* The version of Drupal we're getting the migrations for.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations for import.
|
||||
*/
|
||||
protected function getMigrations($database_state_key, $drupal_version) {
|
||||
$version_tag = 'Drupal ' . $drupal_version;
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migration');
|
||||
/** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
|
||||
$all_migrations = $plugin_manager->createInstancesByTag($version_tag);
|
||||
$migrations = [];
|
||||
foreach ($all_migrations as $migration) {
|
||||
// Skip migrations tagged with any of the follow-up migration tags. They
|
||||
// will be derived and executed after the migrations on which they depend
|
||||
// have been successfully executed.
|
||||
// @see Drupal\migrate_drupal\Plugin\MigrationWithFollowUpInterface
|
||||
if (!empty(array_intersect($migration->getMigrationTags(), $this->getFollowUpMigrationTags()))) {
|
||||
continue;
|
||||
}
|
||||
// Multilingual migrations require migrate_drupal_multilingual.
|
||||
$tags = $migration->getMigrationTags() ?: [];
|
||||
if (in_array('Multilingual', $tags, TRUE) && (!\Drupal::service('module_handler')->moduleExists('migrate_drupal_multilingual'))) {
|
||||
throw new RequirementsException(sprintf("Install migrate_drupal_multilingual to run migration '%s'.", $migration->getPluginId()));
|
||||
}
|
||||
|
||||
try {
|
||||
// @todo https://drupal.org/node/2681867 We should be able to validate
|
||||
// the entire migration at this point.
|
||||
$source_plugin = $migration->getSourcePlugin();
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
$destination_plugin = $migration->getDestinationPlugin();
|
||||
if ($destination_plugin instanceof RequirementsInterface) {
|
||||
$destination_plugin->checkRequirements();
|
||||
}
|
||||
$migrations[] = $migration;
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Migrations which are not applicable given the source and destination
|
||||
// site configurations (e.g., what modules are enabled) will be silently
|
||||
// ignored.
|
||||
}
|
||||
}
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the follow-up migration tags.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getFollowUpMigrationTags() {
|
||||
if ($this->followUpMigrationTags === NULL) {
|
||||
$this->followUpMigrationTags = \Drupal::configFactory()
|
||||
->get('migrate_drupal.settings')
|
||||
->get('follow_up_migration_tags') ?: [];
|
||||
}
|
||||
return $this->followUpMigrationTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines what version of Drupal the source database contains.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection object.
|
||||
*
|
||||
* @return string|false
|
||||
* A string representing the major branch of Drupal core (e.g. '6' for
|
||||
* Drupal 6.x), or FALSE if no valid version is matched.
|
||||
*/
|
||||
protected function getLegacyDrupalVersion(Connection $connection) {
|
||||
// Don't assume because a table of that name exists, that it has the columns
|
||||
// we're querying. Catch exceptions and report that the source database is
|
||||
// not Drupal.
|
||||
// Drupal 5/6/7 can be detected by the schema_version in the system table.
|
||||
if ($connection->schema()->tableExists('system')) {
|
||||
try {
|
||||
$version_string = $connection
|
||||
->query('SELECT schema_version FROM {system} WHERE name = :module', [':module' => 'system'])
|
||||
->fetchField();
|
||||
if ($version_string && $version_string[0] == '1') {
|
||||
if ((int) $version_string >= 1000) {
|
||||
$version_string = '5';
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\PDOException $e) {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
// For Drupal 8 (and we're predicting beyond) the schema version is in the
|
||||
// key_value store.
|
||||
elseif ($connection->schema()->tableExists('key_value')) {
|
||||
$result = $connection
|
||||
->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [':system_schema' => 'system.schema', ':module' => 'system'])
|
||||
->fetchField();
|
||||
$version_string = unserialize($result);
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
|
||||
return $version_string ? substr($version_string, 0, 1) : FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
/**
|
||||
* @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\migrate_drupal\MigrationConfigurationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2873794
|
||||
*/
|
||||
trait MigrationCreationTrait {
|
||||
use MigrationConfigurationTrait;
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
|
||||
use Drupal\migrate\Plugin\MigrateSourcePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManager as BaseMigrationPluginManager;
|
||||
|
||||
/**
|
||||
* Manages migration plugins.
|
||||
*
|
||||
* Analyzes migration definitions to ensure that the source plugin of any
|
||||
* migration tagged with particular tags ('Drupal 6' or 'Drupal 7' by default)
|
||||
* defines a source_module property in its plugin annotation. This is done in
|
||||
* order to support the Migrate Drupal UI, which needs to know which modules
|
||||
* "own" the data being migrated into Drupal 8, on both the source and
|
||||
* destination sides.
|
||||
*
|
||||
* @todo Enforce the destination_module property too, in
|
||||
* https://www.drupal.org/project/drupal/issues/2923810.
|
||||
*/
|
||||
class MigrationPluginManager extends BaseMigrationPluginManager {
|
||||
|
||||
/**
|
||||
* The Migrate source plugin manager service.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateSourcePluginManager
|
||||
*/
|
||||
protected $sourceManager;
|
||||
|
||||
/**
|
||||
* The config factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The migration tags which will trigger source_module enforcement.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $enforcedSourceModuleTags;
|
||||
|
||||
/**
|
||||
* MigrationPluginManager constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler service.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager service.
|
||||
* @param \Drupal\migrate\Plugin\MigrateSourcePluginManager $source_manager
|
||||
* The Migrate source plugin manager service.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory service.
|
||||
*/
|
||||
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, MigrateSourcePluginManager $source_manager, ConfigFactoryInterface $config_factory) {
|
||||
parent::__construct($module_handler, $cache_backend, $language_manager);
|
||||
$this->sourceManager = $source_manager;
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the migration tags that trigger source_module enforcement.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getEnforcedSourceModuleTags() {
|
||||
if ($this->enforcedSourceModuleTags === NULL) {
|
||||
$this->enforcedSourceModuleTags = $this->configFactory
|
||||
->get('migrate_drupal.settings')
|
||||
->get('enforce_source_module_tags') ?: [];
|
||||
}
|
||||
return $this->enforcedSourceModuleTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processDefinition(&$definition, $plugin_id) {
|
||||
parent::processDefinition($definition, $plugin_id);
|
||||
|
||||
// If the migration has no tags, we don't need to enforce the source_module
|
||||
// annotation property.
|
||||
if (empty($definition['migration_tags'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the migration has any of the tags that trigger source_module
|
||||
// enforcement.
|
||||
$applied_tags = array_intersect($this->getEnforcedSourceModuleTags(), $definition['migration_tags']);
|
||||
if ($applied_tags) {
|
||||
// Throw an exception if the source plugin definition does not define a
|
||||
// source_module.
|
||||
$source_id = $definition['source']['plugin'];
|
||||
$source_definition = $this->sourceManager->getDefinition($source_id);
|
||||
if (empty($source_definition['source_module'])) {
|
||||
throw new BadPluginDefinitionException($source_id, 'source_module');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for all CCK field type plugins.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
interface MigrateCckFieldInterface extends MigrateFieldInterface {
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the cck bundle migrations.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
* @param string $field_name
|
||||
* The field name we're processing the value for.
|
||||
* @param array $data
|
||||
* The array of field data from CckFieldValues::fieldData().
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Deprecated: Plugin manager for migrate field plugins.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
class MigrateCckFieldPluginManager extends MigrateFieldPluginManager implements MigrateCckFieldPluginManagerInterface {}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldPluginManagerInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManagerInterface instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Provides an interface for cck field plugin manager.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
interface MigrateCckFieldPluginManagerInterface extends MigrateFieldPluginManagerInterface {}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Provides an interface for all field type plugins.
|
||||
*/
|
||||
interface MigrateFieldInterface extends PluginInspectionInterface {
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field migration.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
*/
|
||||
public function alterFieldMigration(MigrationInterface $migration);
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field instance migration.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
*/
|
||||
public function alterFieldInstanceMigration(MigrationInterface $migration);
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field widget migration.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
*/
|
||||
public function alterFieldWidgetMigration(MigrationInterface $migration);
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field formatter migration.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
*/
|
||||
public function alterFieldFormatterMigration(MigrationInterface $migration);
|
||||
|
||||
/**
|
||||
* Get the field formatter type from the source.
|
||||
*
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The field being migrated.
|
||||
*
|
||||
* @return string
|
||||
* The field formatter type.
|
||||
*/
|
||||
public function getFieldFormatterType(Row $row);
|
||||
|
||||
/**
|
||||
* Get a map between D6 formatters and D8 formatters for this field type.
|
||||
*
|
||||
* This is used by static::alterFieldFormatterMigration() in the base class.
|
||||
*
|
||||
* @return array
|
||||
* The keys are D6 formatters and the values are D8 formatters.
|
||||
*/
|
||||
public function getFieldFormatterMap();
|
||||
|
||||
/**
|
||||
* Get the field widget type from the source.
|
||||
*
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The field being migrated.
|
||||
*
|
||||
* @return string
|
||||
* The field widget type.
|
||||
*/
|
||||
public function getFieldWidgetType(Row $row);
|
||||
|
||||
/**
|
||||
* Get a map between D6 and D8 widgets for this field type.
|
||||
*
|
||||
* @return array
|
||||
* The keys are D6 field widget types and the values D8 widgets.
|
||||
*/
|
||||
public function getFieldWidgetMap();
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field bundle migrations.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
* @param string $field_name
|
||||
* The field name we're processing the value for.
|
||||
* @param array $data
|
||||
* The array of field data from FieldValues::fieldData().
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data);
|
||||
|
||||
/**
|
||||
* Computes the destination type of a migrated field.
|
||||
*
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The field being migrated.
|
||||
*
|
||||
* @return string
|
||||
* The destination field type.
|
||||
*/
|
||||
public function getFieldType(Row $row);
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Plugin manager for migrate field plugins.
|
||||
*
|
||||
* @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
* @see \Drupal\migrate\Annotation\MigrateField
|
||||
* @see plugin_api
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
|
||||
|
||||
/**
|
||||
* The default version of core to use for field plugins.
|
||||
*
|
||||
* These plugins were initially only built and used for Drupal 6 fields.
|
||||
* Having been extended for Drupal 7 with a "core" annotation, we fall back to
|
||||
* Drupal 6 where none exists.
|
||||
*/
|
||||
const DEFAULT_CORE_VERSION = 6;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
|
||||
$core = static::DEFAULT_CORE_VERSION;
|
||||
if (!empty($configuration['core'])) {
|
||||
$core = $configuration['core'];
|
||||
}
|
||||
elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
|
||||
foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
|
||||
if ($tag == 'Drupal 7') {
|
||||
$core = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$definitions = $this->getDefinitions();
|
||||
foreach ($definitions as $plugin_id => $definition) {
|
||||
if (in_array($core, $definition['core'])) {
|
||||
if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
|
||||
return $plugin_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new PluginNotFoundException($field_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processDefinition(&$definition, $plugin_id) {
|
||||
parent::processDefinition($definition, $plugin_id);
|
||||
|
||||
foreach (['core', 'source_module', 'destination_module'] as $required_property) {
|
||||
if (empty($definition[$required_property])) {
|
||||
throw new BadPluginDefinitionException($plugin_id, $required_property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
interface MigrateFieldPluginManagerInterface extends MigratePluginManagerInterface {
|
||||
|
||||
/**
|
||||
* Get the plugin ID from the field type.
|
||||
*
|
||||
* @param string $field_type
|
||||
* The field type being migrated.
|
||||
* @param array $configuration
|
||||
* (optional) An array of configuration relevant to the plugin instance.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface|null $migration
|
||||
* (optional) The current migration instance.
|
||||
*
|
||||
* @return string
|
||||
* The ID of the plugin for the field_type if available.
|
||||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
|
||||
* If the plugin cannot be determined, such as if the field type is invalid.
|
||||
*/
|
||||
public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
/**
|
||||
* Interface for migrations with follow-up migrations.
|
||||
*
|
||||
* Some migrations need to be derived and executed after other migrations have
|
||||
* been successfully executed. For example, a migration might need to be derived
|
||||
* based on previously migrated data. For such a case, the migration dependency
|
||||
* system is not enough since all migrations would still be derived before any
|
||||
* one of them has been executed.
|
||||
*
|
||||
* Those "follow-up" migrations need to be tagged with the "Follow-up migration"
|
||||
* tag (or any tag in the "follow_up_migration_tags" configuration) and thus
|
||||
* they won't be derived with the other migrations.
|
||||
*
|
||||
* To get those follow-up migrations derived at the right time, the migrations
|
||||
* on which they depend must implement this interface and generate them in the
|
||||
* generateFollowUpMigrations() method.
|
||||
*
|
||||
* When the migrations implementing this interface have been successfully
|
||||
* executed, the follow-up migrations will then be derived having access to the
|
||||
* now migrated data.
|
||||
*/
|
||||
interface MigrationWithFollowUpInterface {
|
||||
|
||||
/**
|
||||
* Generates follow-up migrations.
|
||||
*
|
||||
* When the migration implementing this interface has been successfully
|
||||
* executed, this method will be used to generate the follow-up migrations
|
||||
* which depends on the now migrated data.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The follow-up migrations.
|
||||
*/
|
||||
public function generateFollowUpMigrations();
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate;
|
||||
|
||||
@trigger_error('CckMigration is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\FieldMigration instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Migration plugin class for migrations dealing with CCK field values.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Plugin\migrate\FieldMigration instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class CckMigration extends FieldMigration {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
const PLUGIN_METHOD = 'cck_plugin_method';
|
||||
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Deriver for entity reference field translations.
|
||||
*
|
||||
* A migration will be created for every bundle with at least one entity
|
||||
* reference field that is configured to point to one of the supported target
|
||||
* entity types. The migrations will update the entity reference fields with
|
||||
* values found in the mapping tables of the migrations associated with the
|
||||
* target types.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* id: d7_entity_reference_translation
|
||||
* label: Entity reference translations
|
||||
* migration_tags:
|
||||
* - Drupal 7
|
||||
* - Follow-up migration
|
||||
* deriver: Drupal\migrate_drupal\Plugin\migrate\EntityReferenceTranslationDeriver
|
||||
* target_types:
|
||||
* node:
|
||||
* - d7_node_translation
|
||||
* source:
|
||||
* plugin: empty
|
||||
* key: default
|
||||
* target: default
|
||||
* process: []
|
||||
* destination:
|
||||
* plugin: null
|
||||
* @endcode
|
||||
*
|
||||
* In this example, the only supported target type is 'node' and the associated
|
||||
* migration for the mapping table lookup is 'd7_node_translation'.
|
||||
*/
|
||||
class EntityReferenceTranslationDeriver extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* EntityReferenceTranslationDeriver constructor.
|
||||
*
|
||||
* @param string $base_plugin_id
|
||||
* The base plugin ID.
|
||||
* @param \Drupal\core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct($base_plugin_id, EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$base_plugin_id,
|
||||
$container->get('entity_field.manager'),
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
// Get all entity reference fields.
|
||||
$field_map = $this->entityFieldManager->getFieldMapByFieldType('entity_reference');
|
||||
|
||||
foreach ($field_map as $entity_type => $fields) {
|
||||
foreach ($fields as $field_name => $field) {
|
||||
foreach ($field['bundles'] as $bundle) {
|
||||
$field_definitions = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle);
|
||||
$target_type = $field_definitions[$field_name]->getSetting('target_type');
|
||||
|
||||
// If the field's target type is not supported, skip it.
|
||||
if (!array_key_exists($target_type, $base_plugin_definition['target_types'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Key derivatives by entity types and bundles.
|
||||
$derivative_key = $entity_type . '__' . $bundle;
|
||||
|
||||
$derivative = $base_plugin_definition;
|
||||
$entity_type_definition = $this->entityTypeManager->getDefinition($entity_type);
|
||||
|
||||
// Set the migration label.
|
||||
$derivative['label'] = $this->t('@label (@derivative)', [
|
||||
'@label' => $base_plugin_definition['label'],
|
||||
'@derivative' => $derivative_key,
|
||||
]);
|
||||
|
||||
// Set the source plugin.
|
||||
$derivative['source']['plugin'] = 'content_entity' . PluginBase::DERIVATIVE_SEPARATOR . $entity_type;
|
||||
if ($entity_type_definition->hasKey('bundle')) {
|
||||
$derivative['source']['bundle'] = $bundle;
|
||||
}
|
||||
|
||||
// Set the process pipeline.
|
||||
$id_key = $entity_type_definition->getKey('id');
|
||||
$derivative['process'][$id_key] = $id_key;
|
||||
if ($entity_type_definition->isRevisionable()) {
|
||||
$revision_key = $entity_type_definition->getKey('revision');
|
||||
$derivative['process'][$revision_key] = $revision_key;
|
||||
}
|
||||
if ($entity_type_definition->isTranslatable()) {
|
||||
$langcode_key = $entity_type_definition->getKey('langcode');
|
||||
$derivative['process'][$langcode_key] = $langcode_key;
|
||||
}
|
||||
|
||||
// Set the destination plugin.
|
||||
$derivative['destination']['plugin'] = 'entity' . PluginBase::DERIVATIVE_SEPARATOR . $entity_type;
|
||||
if ($entity_type_definition->hasKey('bundle')) {
|
||||
$derivative['destination']['default_bundle'] = $bundle;
|
||||
}
|
||||
if ($entity_type_definition->isTranslatable()) {
|
||||
$derivative['destination']['translations'] = TRUE;
|
||||
}
|
||||
|
||||
// Allow overwriting the entity reference field so we can update its
|
||||
// values with the ones found in the mapping table.
|
||||
$derivative['destination']['overwrite_properties'][$field_name] = $field_name;
|
||||
|
||||
// Add the entity reference field to the process pipeline.
|
||||
$derivative['process'][$field_name] = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
[
|
||||
'plugin' => 'migration_lookup',
|
||||
'source' => 'target_id',
|
||||
'migration' => $base_plugin_definition['target_types'][$target_type],
|
||||
'no_stub' => TRUE,
|
||||
],
|
||||
[
|
||||
'plugin' => 'skip_on_empty',
|
||||
'method' => 'row',
|
||||
],
|
||||
[
|
||||
'plugin' => 'extract',
|
||||
'index' => [0],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
if (!isset($this->derivatives[$derivative_key])) {
|
||||
// If this is a new derivative, add it to the returned derivatives.
|
||||
$this->derivatives[$derivative_key] = $derivative;
|
||||
}
|
||||
else {
|
||||
// If this is an existing derivative, it means this bundle has more
|
||||
// than one entity reference field. In that case, we only want to add
|
||||
// the field to the process pipeline and make it overwritable.
|
||||
$this->derivatives[$derivative_key]['process'] += $derivative['process'];
|
||||
$this->derivatives[$derivative_key]['destination']['overwrite_properties'] += $derivative['destination']['overwrite_properties'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\MigrateDestinationPluginManager;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\Migration;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Migration plugin class for migrations dealing with field config and values.
|
||||
*/
|
||||
class FieldMigration extends Migration implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* Defines which configuration option has the migration processing function.
|
||||
*
|
||||
* Default method is 'field_plugin_method'. For backwards compatibility,
|
||||
* this constant is overridden in the CckMigration class, in order to
|
||||
* fallback to the old 'cck_plugin_method'.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const PLUGIN_METHOD = 'field_plugin_method';
|
||||
|
||||
/**
|
||||
* Flag indicating whether the field data has been filled already.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $init = FALSE;
|
||||
|
||||
/**
|
||||
* List of field plugin IDs which have already run.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $processedFieldTypes = [];
|
||||
|
||||
/**
|
||||
* Already-instantiated field plugins, keyed by ID.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[]
|
||||
*/
|
||||
protected $fieldPluginCache;
|
||||
|
||||
/**
|
||||
* The field plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
|
||||
*/
|
||||
protected $fieldPluginManager;
|
||||
|
||||
/**
|
||||
* Already-instantiated cckfield plugins, keyed by ID.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[]
|
||||
*/
|
||||
protected $cckPluginCache;
|
||||
|
||||
/**
|
||||
* The cckfield plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
/**
|
||||
* Constructs a FieldMigration.
|
||||
*
|
||||
* @param array $configuration
|
||||
* Plugin configuration.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager
|
||||
* The cckfield plugin manager.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager
|
||||
* The field plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
|
||||
* The migration plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigratePluginManager $source_plugin_manager
|
||||
* The source migration plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigratePluginManager $process_plugin_manager
|
||||
* The process migration plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager
|
||||
* The destination migration plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigratePluginManager $idmap_plugin_manager
|
||||
* The ID map migration plugin manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManager $source_plugin_manager, MigratePluginManager $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManager $idmap_plugin_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration_plugin_manager, $source_plugin_manager, $process_plugin_manager, $destination_plugin_manager, $idmap_plugin_manager);
|
||||
$this->cckPluginManager = $cck_manager;
|
||||
$this->fieldPluginManager = $field_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('plugin.manager.migrate.cckfield'),
|
||||
$container->get('plugin.manager.migrate.field'),
|
||||
$container->get('plugin.manager.migration'),
|
||||
$container->get('plugin.manager.migrate.source'),
|
||||
$container->get('plugin.manager.migrate.process'),
|
||||
$container->get('plugin.manager.migrate.destination'),
|
||||
$container->get('plugin.manager.migrate.id_map')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProcess() {
|
||||
if (!$this->init) {
|
||||
$this->init = TRUE;
|
||||
$source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin();
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
try {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Kill the rest of the method.
|
||||
$source_plugin = [];
|
||||
}
|
||||
}
|
||||
foreach ($source_plugin as $row) {
|
||||
$field_type = $row->getSourceProperty('type');
|
||||
|
||||
try {
|
||||
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this);
|
||||
$manager = $this->fieldPluginManager;
|
||||
}
|
||||
catch (PluginNotFoundException $ex) {
|
||||
try {
|
||||
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this);
|
||||
$manager = $this->cckPluginManager;
|
||||
}
|
||||
catch (PluginNotFoundException $ex) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->processedFieldTypes[$field_type]) && $manager->hasDefinition($plugin_id)) {
|
||||
$this->processedFieldTypes[$field_type] = TRUE;
|
||||
// Allow the field plugin to alter the migration as necessary so that
|
||||
// it knows how to handle fields of this type.
|
||||
if (!isset($this->fieldPluginCache[$field_type])) {
|
||||
$this->fieldPluginCache[$field_type] = $manager->createInstance($plugin_id, [], $this);
|
||||
}
|
||||
}
|
||||
$method = $this->pluginDefinition[static::PLUGIN_METHOD];
|
||||
call_user_func([$this->fieldPluginCache[$field_type], $method], $this);
|
||||
}
|
||||
}
|
||||
return parent::getProcess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
|
||||
|
||||
@trigger_error('CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;
|
||||
|
||||
/**
|
||||
* The base class for all field plugins.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
abstract class CckFieldPluginBase extends FieldPluginBase implements MigrateCckFieldInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
// Provide a bridge to the old method declared on the interface and now an
|
||||
// abstract method in this class.
|
||||
return $this->processCckFieldValues($migration, $field_name, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field bundle migrations.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
* @param string $field_name
|
||||
* The field name we're processing the value for.
|
||||
* @param array $data
|
||||
* The array of field data from FieldValues::fieldData().
|
||||
*/
|
||||
abstract public function processCckFieldValues(MigrationInterface $migration, $field_name, $data);
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig as BaseEntityFieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Deprecated. Destination with Drupal specific config dependencies.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "md_entity:field_storage_config"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.2.x and will be removed in Drupal 9.0.x. Use
|
||||
* \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
|
||||
* instead.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
|
||||
*/
|
||||
class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig {
|
||||
|
||||
/**
|
||||
* The field type plugin manager.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
|
||||
*/
|
||||
protected $fieldTypePluginManager;
|
||||
|
||||
/**
|
||||
* Construct a new plugin.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The storage for this entity type.
|
||||
* @param array $bundles
|
||||
* The list of bundles this entity type has.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The configuration factory.
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
|
||||
* The field type plugin manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, FieldTypePluginManagerInterface $field_type_plugin_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $config_factory, $field_type_plugin_manager);
|
||||
$this->languageManager = $language_manager;
|
||||
$this->configFactory = $config_factory;
|
||||
$this->fieldTypePluginManager = $field_type_plugin_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
$entity_type_id = static::getEntityTypeId($plugin_id);
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('entity.manager')->getStorage($entity_type_id),
|
||||
array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)),
|
||||
$container->get('language_manager'),
|
||||
$container->get('config.factory'),
|
||||
$container->get('plugin.manager.field.field_type')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
$this->dependencies = parent::calculateDependencies();
|
||||
// Add a dependency on the module that provides the field type using the
|
||||
// source plugin configuration.
|
||||
$source_configuration = $this->migration->getSourceConfiguration();
|
||||
if (isset($source_configuration['constants']['type'])) {
|
||||
$field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']);
|
||||
$this->addDependency('module', $field_type['provider']);
|
||||
}
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static function getEntityTypeId($plugin_id) {
|
||||
return 'field_storage_config';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\field;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
|
||||
|
||||
/**
|
||||
* The base class for all field plugins.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigratePluginManager
|
||||
* @see \Drupal\migrate_drupal\Annotation\MigrateField
|
||||
* @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
* @see plugin_api
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
abstract class FieldPluginBase extends PluginBase implements MigrateFieldInterface {
|
||||
|
||||
/**
|
||||
* Alters the migration for field definitions.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
|
||||
* alterFieldMigration() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944598
|
||||
* @see ::alterFieldMigration()
|
||||
*/
|
||||
public function processField(MigrationInterface $migration) {
|
||||
@trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
|
||||
$this->alterFieldMigration($migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterFieldMigration(MigrationInterface $migration) {
|
||||
$process[0]['map'][$this->pluginId][$this->pluginId] = $this->pluginId;
|
||||
$migration->mergeProcessOfProperty('type', $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alert field instance migration.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
|
||||
* alterFieldInstanceMigration() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944598
|
||||
* @see ::alterFieldInstanceMigration()
|
||||
*/
|
||||
public function processFieldInstance(MigrationInterface $migration) {
|
||||
@trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldInstanceMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
|
||||
$this->alterFieldInstanceMigration($migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterFieldInstanceMigration(MigrationInterface $migration) {
|
||||
// Nothing to do by default with field instances.
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter field widget migration.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
|
||||
* alterFieldWidgetMigration() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944598
|
||||
* @see ::alterFieldWidgetMigration()
|
||||
*/
|
||||
public function processFieldWidget(MigrationInterface $migration) {
|
||||
@trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldWidgetMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
|
||||
$this->alterFieldWidgetMigration($migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterFieldWidgetMigration(MigrationInterface $migration) {
|
||||
$process = [];
|
||||
foreach ($this->getFieldWidgetMap() as $source_widget => $destination_widget) {
|
||||
$process['type']['map'][$source_widget] = $destination_widget;
|
||||
}
|
||||
$migration->mergeProcessOfProperty('options/type', $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterType(Row $row) {
|
||||
return $row->getSourceProperty('formatter/type');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetType(Row $row) {
|
||||
return $row->getSourceProperty('widget/type');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetMap() {
|
||||
// By default, use the plugin ID for the widget types.
|
||||
return [
|
||||
$this->pluginId => $this->pluginId . '_default',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter field formatter migration.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
|
||||
* alterFieldFormatterMigration() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944598
|
||||
* @see ::processFieldFormatter()
|
||||
*/
|
||||
public function processFieldFormatter(MigrationInterface $migration) {
|
||||
@trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldFormatterMigration() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
|
||||
$this->alterFieldFormatterMigration($migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterFieldFormatterMigration(MigrationInterface $migration) {
|
||||
$process = [];
|
||||
// Some migrate field plugin IDs are prefixed with 'd6_' or 'd7_'. Since the
|
||||
// plugin ID is used in the static map as the module name, we have to remove
|
||||
// this prefix from the plugin ID.
|
||||
$plugin_id = preg_replace('/d[67]_/', '', $this->pluginId);
|
||||
foreach ($this->getFieldFormatterMap() as $source_format => $destination_format) {
|
||||
$process[0]['map'][$plugin_id][$source_format] = $destination_format;
|
||||
}
|
||||
$migration->mergeProcessOfProperty('options/type', $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the process pipeline for field values.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use
|
||||
* defineValueProcessPipeline() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944598
|
||||
* @see ::defineValueProcessPipeline()
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
@trigger_error('Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.', E_USER_DEPRECATED);
|
||||
return $this->defineValueProcessPipeline($migration, $field_name, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'get',
|
||||
'source' => $field_name,
|
||||
];
|
||||
$migration->mergeProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldType(Row $row) {
|
||||
$field_type = $row->getSourceProperty('type');
|
||||
|
||||
if (isset($this->pluginDefinition['type_map'][$field_type])) {
|
||||
return $this->pluginDefinition['type_map'][$field_type];
|
||||
}
|
||||
else {
|
||||
return $field_type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "nodereference",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "nodereference" = "entity_reference",
|
||||
* },
|
||||
* source_module = "nodereference",
|
||||
* destination_module = "core",
|
||||
* )
|
||||
*/
|
||||
class NodeReference extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
'plugin' => 'get',
|
||||
'source' => 'nid',
|
||||
],
|
||||
],
|
||||
];
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "userreference",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "userreference" = "entity_reference",
|
||||
* },
|
||||
* source_module = "userreference",
|
||||
* destination_module = "core",
|
||||
* )
|
||||
*/
|
||||
class UserReference extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
'plugin' => 'migration_lookup',
|
||||
'migration' => 'd6_user',
|
||||
'source' => 'uid',
|
||||
],
|
||||
],
|
||||
];
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Source plugin to get content entities from the current version of Drupal.
|
||||
*
|
||||
* This plugin uses the Entity API to export entity data. If the source entity
|
||||
* type has custom field storage fields or computed fields, this class will need
|
||||
* to be extended and the new class will need to load/calculate the values for
|
||||
* those fields.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - entity_type: The entity type ID of the entities being exported. This is
|
||||
* calculated dynamically by the deriver so it is only needed if the deriver
|
||||
* is not utilized, i.e., a custom source plugin.
|
||||
* - bundle: (optional) If the entity type is bundleable, only return entities
|
||||
* of this bundle.
|
||||
* - include_translations: (optional) Indicates if the entity translations
|
||||
* should be included, defaults to TRUE.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* This will return all nodes, from every bundle and every translation. It does
|
||||
* not return all revisions, just the default one.
|
||||
* @code
|
||||
* source:
|
||||
* plugin: content_entity:node
|
||||
* @endcode
|
||||
*
|
||||
* This will only return nodes of type 'article' in their default language.
|
||||
* @code
|
||||
* source:
|
||||
* plugin: content_entity:node
|
||||
* bundle: article
|
||||
* include_translations: false
|
||||
* @endcode
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "content_entity",
|
||||
* source_module = "migrate_drupal",
|
||||
* deriver = "\Drupal\migrate_drupal\Plugin\migrate\source\ContentEntityDeriver",
|
||||
* )
|
||||
*/
|
||||
class ContentEntity extends SourcePluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle info service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The entity type definition.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The plugin's default configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultConfiguration = [
|
||||
'bundle' => NULL,
|
||||
'include_translations' => TRUE,
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
|
||||
if (empty($plugin_definition['entity_type'])) {
|
||||
throw new InvalidPluginDefinitionException($plugin_id, 'Missing required "entity_type" definition.');
|
||||
}
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->entityTypeBundleInfo = $entity_type_bundle_info;
|
||||
$this->entityType = $this->entityTypeManager->getDefinition($plugin_definition['entity_type']);
|
||||
if (!$this->entityType instanceof ContentEntityTypeInterface) {
|
||||
throw new InvalidPluginDefinitionException($plugin_id, sprintf('The entity type (%s) is not supported. The "content_entity" source plugin only supports content entities.', $plugin_definition['entity_type']));
|
||||
}
|
||||
if (!empty($configuration['bundle'])) {
|
||||
if (!$this->entityType->hasKey('bundle')) {
|
||||
throw new \InvalidArgumentException(sprintf('A bundle was provided but the entity type (%s) is not bundleable.', $plugin_definition['entity_type']));
|
||||
}
|
||||
$bundle_info = array_keys($this->entityTypeBundleInfo->getBundleInfo($this->entityType->id()));
|
||||
if (!in_array($configuration['bundle'], $bundle_info, TRUE)) {
|
||||
throw new \InvalidArgumentException(sprintf('The provided bundle (%s) is not valid for the (%s) entity type.', $configuration['bundle'], $plugin_definition['entity_type']));
|
||||
}
|
||||
}
|
||||
parent::__construct($configuration + $this->defaultConfiguration, $plugin_id, $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_field.manager'),
|
||||
$container->get('entity_type.bundle.info')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString() {
|
||||
return (string) $this->entityType->getPluralLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the iterator with the source data.
|
||||
*
|
||||
* @return \Generator
|
||||
* A data generator for this source.
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$ids = $this->query()->execute();
|
||||
return $this->yieldEntities($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and yields entities, one at a time.
|
||||
*
|
||||
* @param array $ids
|
||||
* The entity IDs.
|
||||
*
|
||||
* @return \Generator
|
||||
* An iterable of the loaded entities.
|
||||
*/
|
||||
protected function yieldEntities(array $ids) {
|
||||
$storage = $this->entityTypeManager
|
||||
->getStorage($this->entityType->id());
|
||||
foreach ($ids as $id) {
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $storage->load($id);
|
||||
yield $this->toArray($entity);
|
||||
if ($this->configuration['include_translations']) {
|
||||
foreach ($entity->getTranslationLanguages(FALSE) as $language) {
|
||||
yield $this->toArray($entity->getTranslation($language->getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an entity to an array.
|
||||
*
|
||||
* Makes all IDs into flat values. All other values are returned as per
|
||||
* $entity->toArray(), which is a nested array.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
|
||||
* The entity to convert.
|
||||
*
|
||||
* @return array
|
||||
* The entity, represented as an array.
|
||||
*/
|
||||
protected function toArray(ContentEntityInterface $entity) {
|
||||
$return = $entity->toArray();
|
||||
// This is necessary because the IDs must be flat. They cannot be nested for
|
||||
// the ID map.
|
||||
foreach (array_keys($this->getIds()) as $id) {
|
||||
/** @var \Drupal\Core\TypedData\Plugin\DataType\ItemList $value */
|
||||
$value = $entity->get($id);
|
||||
// Force the IDs on top of the previous values.
|
||||
$return[$id] = $value->first()->getString();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query to retrieve the entities.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\Query\QueryInterface
|
||||
* The query.
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->entityTypeManager
|
||||
->getStorage($this->entityType->id())
|
||||
->getQuery()
|
||||
->accessCheck(FALSE);
|
||||
if (!empty($this->configuration['bundle'])) {
|
||||
$query->condition($this->entityType->getKey('bundle'), $this->configuration['bundle']);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count($refresh = FALSE) {
|
||||
// If no translations are included, then a simple query is possible.
|
||||
if (!$this->configuration['include_translations']) {
|
||||
return parent::count($refresh);
|
||||
}
|
||||
// @TODO: Determine a better way to retrieve a valid count for translations.
|
||||
// https://www.drupal.org/project/drupal/issues/2937166
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doCount() {
|
||||
return $this->query()->count()->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
// Retrieving fields from a non-fieldable content entity will throw a
|
||||
// LogicException. Return an empty list of fields instead.
|
||||
if (!$this->entityType->entityClassImplements('Drupal\Core\Entity\FieldableEntityInterface')) {
|
||||
return [];
|
||||
}
|
||||
$field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id());
|
||||
if (!empty($this->configuration['bundle'])) {
|
||||
$field_definitions += $this->entityFieldManager->getFieldDefinitions($this->entityType->id(), $this->configuration['bundle']);
|
||||
}
|
||||
$fields = array_map(function ($definition) {
|
||||
return (string) $definition->getLabel();
|
||||
}, $field_definitions);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$id_key = $this->entityType->getKey('id');
|
||||
$ids[$id_key] = $this->getDefinitionFromEntity($id_key);
|
||||
if ($this->entityType->isTranslatable()) {
|
||||
$langcode_key = $this->entityType->getKey('langcode');
|
||||
$ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key);
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the field definition from a specific entity base field.
|
||||
*
|
||||
* @param string $key
|
||||
* The field ID key.
|
||||
*
|
||||
* @return array
|
||||
* An associative array with a structure that contains the field type, keyed
|
||||
* as 'type', together with field storage settings as they are returned by
|
||||
* FieldStorageDefinitionInterface::getSettings().
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::getDefinitionFromEntity()
|
||||
*/
|
||||
protected function getDefinitionFromEntity($key) {
|
||||
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
|
||||
$field_definition = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id())[$key];
|
||||
return [
|
||||
'type' => $field_definition->getType(),
|
||||
] + $field_definition->getSettings();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Deriver for content entity source plugins.
|
||||
*/
|
||||
class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a new ContentEntityDeriver.
|
||||
*
|
||||
* @param string $base_plugin_id
|
||||
* The base plugin ID.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct($base_plugin_id, EntityTypeManagerInterface $entityTypeManager) {
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$base_plugin_id,
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$this->derivatives = [];
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $id => $definition) {
|
||||
if ($definition instanceof ContentEntityTypeInterface) {
|
||||
$this->derivatives[$id] = $base_plugin_definition;
|
||||
// Provide entity_type so the source can be used apart from a deriver.
|
||||
$this->derivatives[$id]['entity_type'] = $id;
|
||||
}
|
||||
}
|
||||
return parent::getDerivativeDefinitions($base_plugin_definition);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\DependentPluginInterface;
|
||||
use Drupal\Core\Entity\DependencyTrait;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* A base class for source plugins using a Drupal database as a source.
|
||||
*
|
||||
* Provides general purpose helper methods that are commonly needed
|
||||
* when writing source plugins that use a Drupal database as a source, for
|
||||
* example:
|
||||
* - Check if the given module exists in the source database.
|
||||
* - Read Drupal configuration variables from the source database.
|
||||
*
|
||||
* For a full list, refer to the methods of this class.
|
||||
*
|
||||
* For available configuration keys, refer to the parent classes:
|
||||
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
|
||||
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
|
||||
*/
|
||||
abstract class DrupalSqlBase extends SqlBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
|
||||
|
||||
use DependencyTrait;
|
||||
|
||||
/**
|
||||
* The contents of the system table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $systemData;
|
||||
|
||||
/**
|
||||
* If the source provider is missing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $requirements = TRUE;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state);
|
||||
$this->entityManager = $entity_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all system data information from the source Drupal database.
|
||||
*
|
||||
* @return array
|
||||
* List of system table information keyed by type and name.
|
||||
*/
|
||||
public function getSystemData() {
|
||||
if (!isset($this->systemData)) {
|
||||
$this->systemData = [];
|
||||
try {
|
||||
$results = $this->select('system', 's')
|
||||
->fields('s')
|
||||
->execute();
|
||||
foreach ($results as $result) {
|
||||
$this->systemData[$result['type']][$result['name']] = $result;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// The table might not exist for example in tests.
|
||||
}
|
||||
}
|
||||
return $this->systemData;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('state'),
|
||||
$container->get('entity.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkRequirements() {
|
||||
parent::checkRequirements();
|
||||
if ($this->pluginDefinition['requirements_met'] === TRUE) {
|
||||
if (isset($this->pluginDefinition['source_module'])) {
|
||||
if ($this->moduleExists($this->pluginDefinition['source_module'])) {
|
||||
if (isset($this->pluginDefinition['minimum_schema_version']) && !$this->getModuleSchemaVersion($this->pluginDefinition['source_module']) < $this->pluginDefinition['minimum_schema_version']) {
|
||||
throw new RequirementsException('Required minimum schema version ' . $this->pluginDefinition['minimum_schema_version'], ['minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RequirementsException('The module ' . $this->pluginDefinition['source_module'] . ' is not enabled in the source site.', ['source_module' => $this->pluginDefinition['source_module']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a module schema_version from the source Drupal database.
|
||||
*
|
||||
* @param string $module
|
||||
* Name of module.
|
||||
*
|
||||
* @return mixed
|
||||
* The current module schema version on the origin system table or FALSE if
|
||||
* not found.
|
||||
*/
|
||||
protected function getModuleSchemaVersion($module) {
|
||||
$system_data = $this->getSystemData();
|
||||
return isset($system_data['module'][$module]['schema_version']) ? $system_data['module'][$module]['schema_version'] : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given module is enabled in the source Drupal database.
|
||||
*
|
||||
* @param string $module
|
||||
* Name of module to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if module is enabled on the origin system, FALSE if not.
|
||||
*/
|
||||
protected function moduleExists($module) {
|
||||
$system_data = $this->getSystemData();
|
||||
return !empty($system_data['module'][$module]['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a variable from a source Drupal database.
|
||||
*
|
||||
* @param $name
|
||||
* Name of the variable.
|
||||
* @param $default
|
||||
* The default value.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function variableGet($name, $default) {
|
||||
try {
|
||||
$result = $this->select('variable', 'v')
|
||||
->fields('v', ['value'])
|
||||
->condition('name', $name)
|
||||
->execute()
|
||||
->fetchField();
|
||||
}
|
||||
// The table might not exist.
|
||||
catch (\Exception $e) {
|
||||
$result = FALSE;
|
||||
}
|
||||
return $result !== FALSE ? unserialize($result) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
// Generic handling for Drupal source plugin constants.
|
||||
if (isset($this->configuration['constants']['entity_type'])) {
|
||||
$this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
|
||||
}
|
||||
if (isset($this->configuration['constants']['module'])) {
|
||||
$this->addDependency('module', $this->configuration['constants']['module']);
|
||||
}
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\DependentPluginInterface;
|
||||
use Drupal\Core\Entity\DependencyTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\source\EmptySource as BaseEmptySource;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
|
||||
/**
|
||||
* Source returning an empty row with Drupal specific config dependencies.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "md_empty",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class EmptySource extends BaseEmptySource implements ContainerFactoryPluginInterface, DependentPluginInterface {
|
||||
|
||||
use DependencyTrait;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
|
||||
$this->entityManager = $entity_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('entity.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
// The empty source plugin supports the entity_type constant.
|
||||
if (isset($this->configuration['constants']['entity_type'])) {
|
||||
$this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
|
||||
}
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Drupal variable source from database.
|
||||
*
|
||||
* This source class always returns a single row and as such is not a good
|
||||
* example for any normal source class returning multiple rows.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "variable",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class Variable extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* The variable names to fetch.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $variables;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->variables = $this->configuration['variables'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
return new \ArrayIterator([$this->values()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the values of the variables specified in the plugin configuration.
|
||||
*
|
||||
* @return array
|
||||
* An associative array where the keys are the variables specified in the
|
||||
* plugin configuration and the values are the values found in the source.
|
||||
* Only those values are returned that are actually in the database.
|
||||
*/
|
||||
protected function values() {
|
||||
// Create an ID field so we can record migration in the map table.
|
||||
// Arbitrarily, use the first variable name.
|
||||
$values['id'] = reset($this->variables);
|
||||
return $values + array_map('unserialize', $this->prepareQuery()->execute()->fetchAllKeyed());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count($refresh = FALSE) {
|
||||
return intval($this->query()->countQuery()->execute()->fetchField() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array_combine($this->variables, $this->variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->getDatabase()
|
||||
->select('variable', 'v')
|
||||
->fields('v', ['name', 'value'])
|
||||
->condition('name', $this->variables, 'IN');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['id']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Multiple variables source from database.
|
||||
*
|
||||
* Unlike the variable source plugin, this one returns one row per
|
||||
* variable.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "variable_multirow",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class VariableMultiRow extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('variable', 'v')
|
||||
->fields('v', ['name', 'value'])
|
||||
// Cast scalars to array so we can consistently use an IN condition.
|
||||
->condition('name', (array) $this->configuration['variables'], 'IN');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'name' => $this->t('Name'),
|
||||
'value' => $this->t('Value'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
if ($value = $row->getSourceProperty('value')) {
|
||||
$row->setSourceProperty('value', unserialize($value));
|
||||
}
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['name']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Gets Drupal i18n_variable source from database.
|
||||
*
|
||||
* @deprecated in Drupal 8.7.x and will be removed in Drupal 9.0.x.
|
||||
* Use \Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3006487
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "variable_translation",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class D6VariableTranslation extends VariableTranslation {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\D6VariableTranslation is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\VariableTranslation. See https://www.drupal.org/node/3006487.', E_USER_DEPRECATED);
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal i18n_variable source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_variable_translation",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class VariableTranslation extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* The variable names to fetch.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $variables;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->variables = $this->configuration['variables'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
return new \ArrayIterator($this->values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the values of the variables specified in the plugin configuration.
|
||||
*
|
||||
* @return array
|
||||
* An associative array where the keys are the variables specified in the
|
||||
* plugin configuration and the values are the values found in the source.
|
||||
* A key/value pair is added for the language code. Only those values are
|
||||
* returned that are actually in the database.
|
||||
*/
|
||||
protected function values() {
|
||||
$values = [];
|
||||
$result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
|
||||
foreach ($result as $i18n_variable) {
|
||||
$values[]['language'] = $i18n_variable->language;
|
||||
}
|
||||
$result = $this->prepareQuery()->execute()->FetchAll();
|
||||
foreach ($result as $i18n_variable) {
|
||||
foreach ($values as $key => $value) {
|
||||
if ($values[$key]['language'] === $i18n_variable->language) {
|
||||
$values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count($refresh = FALSE) {
|
||||
return $this->initializeIterator()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array_combine($this->variables, $this->variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->getDatabase()
|
||||
->select('i18n_variable', 'v')
|
||||
->fields('v')
|
||||
->condition('name', (array) $this->configuration['variables'], 'IN');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['language']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\VariableTranslation', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Drupal i18n_variable source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "i18n_variable",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x and will be removed in Drupal 9.0.x. Use
|
||||
* \Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2898649
|
||||
*/
|
||||
class i18nVariable extends VariableTranslation {}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Base class for D7 source plugins which need to collect field values from
|
||||
* the Field API.
|
||||
*/
|
||||
abstract class FieldableEntity extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* Returns all non-deleted field instances attached to a specific entity type.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type ID.
|
||||
* @param string|null $bundle
|
||||
* (optional) The bundle.
|
||||
*
|
||||
* @return array[]
|
||||
* The field instances, keyed by field name.
|
||||
*/
|
||||
protected function getFields($entity_type, $bundle = NULL) {
|
||||
$query = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci')
|
||||
->condition('fci.entity_type', $entity_type)
|
||||
->condition('fci.bundle', isset($bundle) ? $bundle : $entity_type)
|
||||
->condition('fci.deleted', 0);
|
||||
|
||||
// Join the 'field_config' table and add the 'translatable' setting to the
|
||||
// query.
|
||||
$query->leftJoin('field_config', 'fc', 'fci.field_id = fc.id');
|
||||
$query->addField('fc', 'translatable');
|
||||
|
||||
return $query->execute()->fetchAllAssoc('field_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves field values for a single field of a single entity.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param string $field
|
||||
* The field name.
|
||||
* @param int $entity_id
|
||||
* The entity ID.
|
||||
* @param int|null $revision_id
|
||||
* (optional) The entity revision ID.
|
||||
* @param string $language
|
||||
* (optional) The field language.
|
||||
*
|
||||
* @return array
|
||||
* The raw field values, keyed by delta.
|
||||
*/
|
||||
protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL, $language = NULL) {
|
||||
$table = (isset($revision_id) ? 'field_revision_' : 'field_data_') . $field;
|
||||
$query = $this->select($table, 't')
|
||||
->fields('t')
|
||||
->condition('entity_type', $entity_type)
|
||||
->condition('entity_id', $entity_id)
|
||||
->condition('deleted', 0);
|
||||
if (isset($revision_id)) {
|
||||
$query->condition('revision_id', $revision_id);
|
||||
}
|
||||
// Add 'language' as a query condition if it has been defined by Entity
|
||||
// Translation.
|
||||
if ($language) {
|
||||
$query->condition('language', $language);
|
||||
}
|
||||
$values = [];
|
||||
foreach ($query->execute() as $row) {
|
||||
foreach ($row as $key => $value) {
|
||||
$delta = $row['delta'];
|
||||
if (strpos($key, $field) === 0) {
|
||||
$column = substr($key, strlen($field) + 1);
|
||||
$values[$delta][$column] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an entity type uses Entity Translation.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return bool
|
||||
* Whether the entity type uses entity translation.
|
||||
*/
|
||||
protected function isEntityTranslatable($entity_type) {
|
||||
return in_array($entity_type, $this->variableGet('entity_translation_entity_types', []), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an entity source language from the 'entity_translation' table.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param int $entity_id
|
||||
* The entity ID.
|
||||
*
|
||||
* @return string|bool
|
||||
* The entity source language or FALSE if no source language was found.
|
||||
*/
|
||||
protected function getEntityTranslationSourceLanguage($entity_type, $entity_id) {
|
||||
try {
|
||||
return $this->select('entity_translation', 'et')
|
||||
->fields('et', ['language'])
|
||||
->condition('entity_type', $entity_type)
|
||||
->condition('entity_id', $entity_id)
|
||||
->condition('source', '')
|
||||
->execute()
|
||||
->fetchField();
|
||||
}
|
||||
// The table might not exist.
|
||||
catch (\Exception $e) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Gets Drupal variable_store source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_variable_translation",
|
||||
* source_module = "i18n_variable",
|
||||
* )
|
||||
*/
|
||||
class VariableTranslation extends DrupalSqlBase {
|
||||
/**
|
||||
* The variable names to fetch.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $variables;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->variables = $this->configuration['variables'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
return new \ArrayIterator($this->values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the values of the variables specified in the plugin configuration.
|
||||
*
|
||||
* @return array
|
||||
* An associative array where the keys are the variables specified in the
|
||||
* plugin configuration and the values are the values found in the source.
|
||||
* A key/value pair is added for the language code. Only those values are
|
||||
* returned that are actually in the database.
|
||||
*/
|
||||
protected function values() {
|
||||
$values = [];
|
||||
$result = $this->prepareQuery()->execute()->FetchAllAssoc('realm_key');
|
||||
foreach ($result as $variable_store) {
|
||||
$values[]['language'] = $variable_store['realm_key'];
|
||||
}
|
||||
$result = $this->prepareQuery()->execute()->FetchAll();
|
||||
foreach ($result as $variable_store) {
|
||||
foreach ($values as $key => $value) {
|
||||
if ($values[$key]['language'] === $variable_store['realm_key']) {
|
||||
if ($variable_store['serialized']) {
|
||||
$values[$key][$variable_store['name']] = unserialize($variable_store['value']);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
$values[$key][$variable_store['name']] = $variable_store['value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count($refresh = FALSE) {
|
||||
return $this->initializeIterator()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array_combine($this->variables, $this->variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['language']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('variable_store', 'vs')
|
||||
->fields('vs')
|
||||
->condition('realm', 'language')
|
||||
->condition('name', (array) $this->configuration['variables'], 'IN');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\source\d8;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal config source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d8_config",
|
||||
* source_module = "system",
|
||||
* )
|
||||
*/
|
||||
class Config extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('config', 'c')
|
||||
->fields('c', ['collection', 'name', 'data']);
|
||||
if (!empty($this->configuration['collections'])) {
|
||||
$query->condition('collection', (array) $this->configuration['collections'], 'IN');
|
||||
}
|
||||
if (!empty($this->configuration['names'])) {
|
||||
$query->condition('name', (array) $this->configuration['names'], 'IN');
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'collection' => $this->t('The config object collection.'),
|
||||
'name' => $this->t('The config object name.'),
|
||||
'data' => $this->t('Serialized configuration object data.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['collection']['type'] = 'string';
|
||||
$ids['name']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Tests;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Provides common functionality for testing stubbing.
|
||||
*/
|
||||
trait StubTestTrait {
|
||||
|
||||
/**
|
||||
* Test that creating a stub of the given entity type results in a valid
|
||||
* entity.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type we are stubbing.
|
||||
*/
|
||||
protected function performStubTest($entity_type_id) {
|
||||
$entity_id = $this->createStub($entity_type_id);
|
||||
$this->assertTrue($entity_id, 'Stub successfully created');
|
||||
if ($entity_id) {
|
||||
$violations = $this->validateStub($entity_type_id, $entity_id);
|
||||
if (!$this->assertIdentical(count($violations), 0, 'Stub is a valid entity')) {
|
||||
foreach ($violations as $violation) {
|
||||
$this->fail((string) $violation->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a stub of the given entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type we are stubbing.
|
||||
*
|
||||
* @return int
|
||||
* ID of the created entity.
|
||||
*/
|
||||
protected function createStub($entity_type_id) {
|
||||
// Create a dummy migration to pass to the destination plugin.
|
||||
$definition = [
|
||||
'migration_tags' => ['Stub test'],
|
||||
'source' => ['plugin' => 'empty'],
|
||||
'process' => [],
|
||||
'destination' => ['plugin' => 'entity:' . $entity_type_id],
|
||||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$destination_plugin = $migration->getDestinationPlugin(TRUE);
|
||||
$stub_row = new Row([], [], TRUE);
|
||||
$destination_ids = $destination_plugin->import($stub_row);
|
||||
return reset($destination_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform validation on a stub entity.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type we are stubbing.
|
||||
* @param string $entity_id
|
||||
* ID of the stubbed entity to validate.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
|
||||
* List of constraint violations identified.
|
||||
*/
|
||||
protected function validateStub($entity_type_id, $entity_id) {
|
||||
$controller = \Drupal::entityManager()->getStorage($entity_type_id);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $stub_entity */
|
||||
$stub_entity = $controller->load($entity_id);
|
||||
return $stub_entity->validate();
|
||||
}
|
||||
|
||||
}
|
49616
2017/web/core/modules/migrate_drupal/tests/fixtures/drupal6.php
vendored
Normal file
49616
2017/web/core/modules/migrate_drupal/tests/fixtures/drupal6.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
51861
2017/web/core/modules/migrate_drupal/tests/fixtures/drupal7.php
vendored
Normal file
51861
2017/web/core/modules/migrate_drupal/tests/fixtures/drupal7.php
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate cck field plugin manager test'
|
||||
type: module
|
||||
description: 'Example module demonstrating the cck field plugin manager in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for Migrate CCK Field Plugin Manager testing.
|
||||
*/
|
||||
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
|
||||
function migrate_cckfield_plugin_manager_test_migrate_field_info_alter(array &$definitions) {
|
||||
if (isset($definitions['filefield'])) {
|
||||
$definitions['filefield']['class'] = D6FileField::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_file",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* },
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar"
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$migration->setProcessOfProperty($field_name, [
|
||||
'class' => static::class,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_no_core_version_specified",
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar",
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate field plugin manager test'
|
||||
type: module
|
||||
description: 'Example module demonstrating the field plugin manager in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_field_plugin_manager_test\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "d6_file",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* },
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar"
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends FieldPluginBase {}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_field_plugin_manager_test\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "d6_no_core_version_specified",
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar",
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends FieldPluginBase {}
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate property overwrite test'
|
||||
type: module
|
||||
description: 'Example module demonstrating property overwrite support in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,31 @@
|
|||
id: users
|
||||
label: User migration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d6_user
|
||||
process:
|
||||
# If the entity's ID is migrated, the Migrate API will try to update
|
||||
# an existing entity with that ID. If no entity with that ID already
|
||||
# exists, it will be created.
|
||||
uid: uid
|
||||
name: name
|
||||
mail: mail
|
||||
password: password
|
||||
'signature/value':
|
||||
plugin: default_value
|
||||
default_value: 'The answer is 42.'
|
||||
destination:
|
||||
plugin: entity:user
|
||||
# If the destination is going to update an existing user, you can optionally
|
||||
# specify the properties that should be overwritten. For example, if the
|
||||
# migration tries to import user 31 and user 31 already exists in the
|
||||
# destination database, only the 'name' and 'mail' properties of the user
|
||||
# will be overwritten. If user 31 doesn't exist, it will be created and
|
||||
# the overwrite_properties list will be ignored.
|
||||
overwrite_properties:
|
||||
- name
|
||||
- mail
|
||||
# It's possible to overwrite nested properties too.
|
||||
- 'signature/value'
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFieldBackwardsCompatibilityTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['file', 'migrate_cckfield_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Ensures that the cckfield backwards compatibility layer is invoked.
|
||||
*
|
||||
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*/
|
||||
public function testBackwardsCompatibility() {
|
||||
$migration = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->getDefinition('d6_node:story');
|
||||
|
||||
$this->assertSame(D6FileField::class, $migration['process']['field_test_filefield']['class']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Test that no dummy migrate_map tables are created.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class IdMapTableNoDummyTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
|
||||
*/
|
||||
protected $pluginManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->pluginManager = $this->container->get('plugin.manager.migration');
|
||||
$this->pluginManager->createInstance('d6_user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that dummy map tables do not exist.
|
||||
*/
|
||||
public function testNoDummyTables() {
|
||||
$database = \Drupal::database();
|
||||
$tables = $database->schema()->findTables('%migrate_map%');
|
||||
$dummy_tables = preg_grep("/.*migrate_map_([0-9a-fA-F]){13}/", $tables);
|
||||
$this->assertCount(0, $dummy_tables);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
||||
/**
|
||||
* Tests the cck field plugin manager.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateCckField plugins are used.
|
||||
*/
|
||||
public function testPluginSelection() {
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
|
||||
|
||||
$this->assertSame('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_file', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_file' was not found.");
|
||||
}
|
||||
|
||||
// Test fallback when no core version is specified.
|
||||
$this->assertSame('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupalTestBase extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installConfig(['migrate_drupal', 'system']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a database fixture into the source database connection.
|
||||
*
|
||||
* @param string $path
|
||||
* Path to the dump file.
|
||||
*/
|
||||
protected function loadFixture($path) {
|
||||
$default_db = Database::getConnection()->getKey();
|
||||
Database::setActiveConnection($this->sourceDatabase->getKey());
|
||||
|
||||
if (substr($path, -3) == '.gz') {
|
||||
$path = 'compress.zlib://' . $path;
|
||||
}
|
||||
require $path;
|
||||
|
||||
Database::setActiveConnection($default_db);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
||||
/**
|
||||
* Tests the field plugin manager.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'image', 'text', 'link', 'migrate_field_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateField plugins are used.
|
||||
*/
|
||||
public function testPluginSelection() {
|
||||
$plugin_manager = $this->container->get('plugin.manager.migrate.field');
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
|
||||
}
|
||||
|
||||
$this->assertIdentical('link', $plugin_manager->getPluginIdFromFieldType('link', ['core' => 6]));
|
||||
$this->assertIdentical('link_field', $plugin_manager->getPluginIdFromFieldType('link_field', ['core' => 7]));
|
||||
$this->assertIdentical('image', $plugin_manager->getPluginIdFromFieldType('image', ['core' => 7]));
|
||||
$this->assertIdentical('file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 7]));
|
||||
$this->assertIdentical('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
|
||||
$this->assertIdentical('d6_text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
|
||||
$this->assertIdentical('d7_text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 7]));
|
||||
|
||||
// Test fallback when no core version is specified.
|
||||
$this->assertIdentical('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
|
||||
|
||||
use Drupal\ban\Plugin\migrate\destination\BlockedIP;
|
||||
use Drupal\color\Plugin\migrate\destination\Color;
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
|
||||
use Drupal\migrate\Plugin\migrate\destination\Config;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\path\Plugin\migrate\destination\UrlAlias;
|
||||
use Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers;
|
||||
use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
|
||||
use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
|
||||
use Drupal\user\Plugin\migrate\destination\UserData;
|
||||
|
||||
/**
|
||||
* Tests that all migrations are tagged as either content or configuration.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class DestinationCategoryTest extends MigrateDrupalTestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateMigrationsTrait;
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManager
|
||||
*/
|
||||
protected $migrationManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
$this->migrationManager = \Drupal::service('plugin.manager.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all D6 migrations are tagged as either Configuration or Content.
|
||||
*/
|
||||
public function testD6Categories() {
|
||||
$migrations = $this->drupal6Migrations();
|
||||
$this->assertArrayHasKey('d6_node:page', $migrations);
|
||||
$this->assertCategories($migrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all D7 migrations are tagged as either Configuration or Content.
|
||||
*/
|
||||
public function testD7Categories() {
|
||||
$migrations = $this->drupal7Migrations();
|
||||
$this->assertArrayHasKey('d7_node:page', $migrations);
|
||||
$this->assertCategories($migrations);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all migrations are tagged as either Configuration or Content.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
|
||||
* The migrations.
|
||||
*/
|
||||
protected function assertCategories($migrations) {
|
||||
foreach ($migrations as $id => $migration) {
|
||||
$object_classes = class_parents($migration->getDestinationPlugin());
|
||||
$object_classes[] = get_class($migration->getDestinationPlugin());
|
||||
|
||||
// Ensure that the destination plugin is an instance of at least one of
|
||||
// the expected classes.
|
||||
if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) {
|
||||
$this->assertNotEmpty(array_intersect($object_classes, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration.");
|
||||
}
|
||||
elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) {
|
||||
$this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content.");
|
||||
}
|
||||
else {
|
||||
$this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration classes.
|
||||
*
|
||||
* Configuration migrations should have a destination plugin that is an
|
||||
* instance of one of the following classes.
|
||||
*
|
||||
* @return array
|
||||
* The configuration class names.
|
||||
*/
|
||||
protected function getConfigurationClasses() {
|
||||
return [
|
||||
Color::class,
|
||||
Config::class,
|
||||
EntityConfigBase::class,
|
||||
ThemeSettings::class,
|
||||
ComponentEntityDisplayBase::class,
|
||||
ShortcutSetUsers::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content classes.
|
||||
*
|
||||
* Content migrations should have a destination plugin that is an instance
|
||||
* of one of the following classes.
|
||||
*
|
||||
* @return array
|
||||
* The content class names.
|
||||
*/
|
||||
protected function getContentClasses() {
|
||||
return [
|
||||
EntityContentBase::class,
|
||||
UrlAlias::class,
|
||||
BlockedIP::class,
|
||||
NodeCounter::class,
|
||||
UserData::class,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,443 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\media\Entity\Media;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests the entity content source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class ContentEntityTest extends KernelTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
use MediaTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'user',
|
||||
'migrate',
|
||||
'migrate_drupal',
|
||||
'system',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'field',
|
||||
'file',
|
||||
'image',
|
||||
'media',
|
||||
'media_test_source',
|
||||
'text',
|
||||
'filter',
|
||||
'language',
|
||||
'content_translation',
|
||||
];
|
||||
|
||||
/**
|
||||
* The bundle used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle = 'article';
|
||||
|
||||
/**
|
||||
* The name of the field used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName = 'field_entity_reference';
|
||||
|
||||
/**
|
||||
* The vocabulary ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $vocabulary = 'fruit';
|
||||
|
||||
/**
|
||||
* The test user.
|
||||
*
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
|
||||
*/
|
||||
protected $migrationPluginManager;
|
||||
|
||||
/**
|
||||
* The source plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateSourcePluginManager
|
||||
*/
|
||||
protected $sourcePluginManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installEntitySchema('media');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('user');
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('user', 'users_data');
|
||||
$this->installSchema('file', 'file_usage');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installConfig($this->modules);
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
// Create article content type.
|
||||
$node_type = NodeType::create(['type' => $this->bundle, 'name' => 'Article']);
|
||||
$node_type->save();
|
||||
|
||||
// Create a vocabulary.
|
||||
$vocabulary = Vocabulary::create([
|
||||
'name' => $this->vocabulary,
|
||||
'description' => $this->vocabulary,
|
||||
'vid' => $this->vocabulary,
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
]);
|
||||
$vocabulary->save();
|
||||
|
||||
// Create a term reference field on node.
|
||||
$this->createEntityReferenceField(
|
||||
'node',
|
||||
$this->bundle,
|
||||
$this->fieldName,
|
||||
'Term reference',
|
||||
'taxonomy_term',
|
||||
'default',
|
||||
['target_bundles' => [$this->vocabulary]],
|
||||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
|
||||
);
|
||||
// Create a term reference field on user.
|
||||
$this->createEntityReferenceField(
|
||||
'user',
|
||||
'user',
|
||||
$this->fieldName,
|
||||
'Term reference',
|
||||
'taxonomy_term',
|
||||
'default',
|
||||
['target_bundles' => [$this->vocabulary]],
|
||||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
|
||||
);
|
||||
|
||||
// Create some data.
|
||||
$this->user = User::create([
|
||||
'name' => 'user123',
|
||||
'uid' => 1,
|
||||
'mail' => 'example@example.com',
|
||||
]);
|
||||
$this->user->save();
|
||||
|
||||
$term = Term::create([
|
||||
'vid' => $this->vocabulary,
|
||||
'name' => 'Apples',
|
||||
'uid' => $this->user->id(),
|
||||
]);
|
||||
$term->save();
|
||||
$this->user->set($this->fieldName, $term->id());
|
||||
$this->user->save();
|
||||
$node = Node::create([
|
||||
'type' => $this->bundle,
|
||||
'title' => 'Apples',
|
||||
$this->fieldName => $term->id(),
|
||||
'uid' => $this->user->id(),
|
||||
]);
|
||||
$node->save();
|
||||
$node->addTranslation('fr', [
|
||||
'title' => 'Pommes',
|
||||
$this->fieldName => $term->id(),
|
||||
])->save();
|
||||
|
||||
$this->sourcePluginManager = $this->container->get('plugin.manager.migrate.source');
|
||||
$this->migrationPluginManager = $this->container->get('plugin.manager.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for missing entity_type.
|
||||
*/
|
||||
public function testConstructorEntityTypeMissing() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [];
|
||||
$plugin_definition = [
|
||||
'entity_type' => '',
|
||||
];
|
||||
$this->setExpectedException(InvalidPluginDefinitionException::class, 'Missing required "entity_type" definition.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for non content entity.
|
||||
*/
|
||||
public function testConstructorNonContentEntity() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'node_type',
|
||||
];
|
||||
$this->setExpectedException(InvalidPluginDefinitionException::class, 'The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:node_type', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for not bundleable entity.
|
||||
*/
|
||||
public function testConstructorNotBundable() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [
|
||||
'bundle' => 'foo',
|
||||
];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'user',
|
||||
];
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'A bundle was provided but the entity type (user) is not bundleable');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:user', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for invalid entity bundle.
|
||||
*/
|
||||
public function testConstructorInvalidBundle() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [
|
||||
'bundle' => 'foo',
|
||||
];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'node',
|
||||
];
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'The provided bundle (foo) is not valid for the (node) entity type.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:node', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user source plugin.
|
||||
*/
|
||||
public function testUserSource() {
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:user'));
|
||||
$user_source = $this->sourcePluginManager->createInstance('content_entity:user', $configuration, $migration);
|
||||
$this->assertSame('users', $user_source->__toString());
|
||||
$this->assertEquals(1, $user_source->count());
|
||||
$ids = $user_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('uid', $ids);
|
||||
$fields = $user_source->fields();
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$this->assertArrayHasKey('pass', $fields);
|
||||
$this->assertArrayHasKey('mail', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('roles', $fields);
|
||||
$user_source->rewind();
|
||||
$values = $user_source->current()->getSource();
|
||||
$this->assertEquals('example@example.com', $values['mail'][0]['value']);
|
||||
$this->assertEquals('user123', $values['name'][0]['value']);
|
||||
$this->assertEquals(1, $values['uid']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests file source plugin.
|
||||
*/
|
||||
public function testFileSource() {
|
||||
$file = File::create([
|
||||
'filename' => 'foo.txt',
|
||||
'uid' => $this->user->id(),
|
||||
'uri' => 'public://foo.txt',
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:file'));
|
||||
$file_source = $this->sourcePluginManager->createInstance('content_entity:file', $configuration, $migration);
|
||||
$this->assertSame('files', $file_source->__toString());
|
||||
$this->assertEquals(1, $file_source->count());
|
||||
$ids = $file_source->getIds();
|
||||
$this->assertArrayHasKey('fid', $ids);
|
||||
$fields = $file_source->fields();
|
||||
$this->assertArrayHasKey('fid', $fields);
|
||||
$this->assertArrayHasKey('filemime', $fields);
|
||||
$this->assertArrayHasKey('filename', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('uri', $fields);
|
||||
$file_source->rewind();
|
||||
$values = $file_source->current()->getSource();
|
||||
$this->assertEquals('text/plain', $values['filemime'][0]['value']);
|
||||
$this->assertEquals('public://foo.txt', $values['uri'][0]['value']);
|
||||
$this->assertEquals('foo.txt', $values['filename'][0]['value']);
|
||||
$this->assertEquals(1, $values['fid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests node source plugin.
|
||||
*/
|
||||
public function testNodeSource() {
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:node'));
|
||||
$node_source = $this->sourcePluginManager->createInstance('content_entity:node', ['bundle' => $this->bundle], $migration);
|
||||
$this->assertSame('content items', $node_source->__toString());
|
||||
$ids = $node_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('nid', $ids);
|
||||
$fields = $node_source->fields();
|
||||
$this->assertArrayHasKey('nid', $fields);
|
||||
$this->assertArrayHasKey('vid', $fields);
|
||||
$this->assertArrayHasKey('title', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('sticky', $fields);
|
||||
$node_source->rewind();
|
||||
$values = $node_source->current()->getSource();
|
||||
$this->assertEquals($this->bundle, $values['type'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['nid']);
|
||||
$this->assertEquals('en', $values['langcode']);
|
||||
$this->assertEquals(1, $values['status'][0]['value']);
|
||||
$this->assertEquals('Apples', $values['title'][0]['value']);
|
||||
$this->assertEquals(1, $values['default_langcode'][0]['value']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
$node_source->next();
|
||||
$values = $node_source->current()->getSource();
|
||||
$this->assertEquals($this->bundle, $values['type'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['nid']);
|
||||
$this->assertEquals('fr', $values['langcode']);
|
||||
$this->assertEquals(1, $values['status'][0]['value']);
|
||||
$this->assertEquals('Pommes', $values['title'][0]['value']);
|
||||
$this->assertEquals(0, $values['default_langcode'][0]['value']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests media source plugin.
|
||||
*/
|
||||
public function testMediaSource() {
|
||||
$values = [
|
||||
'id' => 'image',
|
||||
'label' => 'Image',
|
||||
'source' => 'test',
|
||||
'new_revision' => FALSE,
|
||||
];
|
||||
$media_type = $this->createMediaType('test', $values);
|
||||
$media = Media::create([
|
||||
'name' => 'Foo media',
|
||||
'uid' => $this->user->id(),
|
||||
'bundle' => $media_type->id(),
|
||||
]);
|
||||
$media->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
'bundle' => 'image',
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:media'));
|
||||
$media_source = $this->sourcePluginManager->createInstance('content_entity:media', $configuration, $migration);
|
||||
$this->assertSame('media items', $media_source->__toString());
|
||||
$this->assertEquals(1, $media_source->count());
|
||||
$ids = $media_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('mid', $ids);
|
||||
$fields = $media_source->fields();
|
||||
$this->assertArrayHasKey('bundle', $fields);
|
||||
$this->assertArrayHasKey('mid', $fields);
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$this->assertArrayHasKey('status', $fields);
|
||||
$media_source->rewind();
|
||||
$values = $media_source->current()->getSource();
|
||||
$this->assertEquals(1, $values['mid']);
|
||||
$this->assertEquals('Foo media', $values['name'][0]['value']);
|
||||
$this->assertNull($values['thumbnail'][0]['title']);
|
||||
$this->assertEquals(1, $values['uid'][0]['target_id']);
|
||||
$this->assertEquals('image', $values['bundle'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests term source plugin.
|
||||
*/
|
||||
public function testTermSource() {
|
||||
$term2 = Term::create([
|
||||
'vid' => $this->vocabulary,
|
||||
'name' => 'Granny Smith',
|
||||
'uid' => $this->user->id(),
|
||||
'parent' => 1,
|
||||
]);
|
||||
$term2->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
'bundle' => $this->vocabulary,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:taxonomy_term'));
|
||||
$term_source = $this->sourcePluginManager->createInstance('content_entity:taxonomy_term', $configuration, $migration);
|
||||
$this->assertSame('taxonomy terms', $term_source->__toString());
|
||||
$this->assertEquals(2, $term_source->count());
|
||||
$ids = $term_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('tid', $ids);
|
||||
$fields = $term_source->fields();
|
||||
$this->assertArrayHasKey('vid', $fields);
|
||||
$this->assertArrayHasKey('tid', $fields);
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$term_source->rewind();
|
||||
$values = $term_source->current()->getSource();
|
||||
$this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['tid']);
|
||||
// @TODO: Add test coverage for parent in
|
||||
// https://www.drupal.org/project/drupal/issues/2940198
|
||||
$this->assertEquals('Apples', $values['name'][0]['value']);
|
||||
$term_source->next();
|
||||
$values = $term_source->current()->getSource();
|
||||
$this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
|
||||
$this->assertEquals(2, $values['tid']);
|
||||
// @TODO: Add test coverage for parent in
|
||||
// https://www.drupal.org/project/drupal/issues/2940198
|
||||
$this->assertEquals('Granny Smith', $values['name'][0]['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a migration definition.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin id.
|
||||
*
|
||||
* @return array
|
||||
* The definition.
|
||||
*/
|
||||
protected function migrationDefinition($plugin_id) {
|
||||
return [
|
||||
'source' => [
|
||||
'plugin' => $plugin_id,
|
||||
],
|
||||
'process' => [],
|
||||
'destination' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the variable multirow source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableMultiRowTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['variable'] = [
|
||||
['name' => 'foo', 'value' => 'i:1;'],
|
||||
['name' => 'bar', 'value' => 'b:0;'],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'name' => 'foo',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'bar',
|
||||
'value' => FALSE,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected count.
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
|
||||
// The source plugin configuration.
|
||||
$tests[0]['configuration']['variables'] = [
|
||||
'foo',
|
||||
'bar',
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\Variable
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['variable'] = [
|
||||
['name' => 'foo', 'value' => 'i:1;'],
|
||||
['name' => 'bar', 'value' => 'b:0;'],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'id' => 'foo',
|
||||
'foo' => 1,
|
||||
'bar' => FALSE,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected count.
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
|
||||
// The source plugin configuration.
|
||||
$tests[0]['configuration']['variables'] = [
|
||||
'foo',
|
||||
'bar',
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class i18nVariableTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['i18n_variable'] = [
|
||||
[
|
||||
'name' => 'site_slogan',
|
||||
'language' => 'fr',
|
||||
'value' => 's:19:"Migrate est génial";',
|
||||
],
|
||||
[
|
||||
'name' => 'site_name',
|
||||
'language' => 'fr',
|
||||
'value' => 's:11:"nom de site";',
|
||||
],
|
||||
[
|
||||
'name' => 'site_slogan',
|
||||
'language' => 'mi',
|
||||
'value' => 's:19:"Ko whakamataku heke";',
|
||||
],
|
||||
[
|
||||
'name' => 'site_name',
|
||||
'language' => 'mi',
|
||||
'value' => 's:9:"ingoa_pae";',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'Migrate est génial',
|
||||
'site_name' => 'nom de site',
|
||||
],
|
||||
[
|
||||
'language' => 'mi',
|
||||
'site_slogan' => 'Ko whakamataku heke',
|
||||
'site_name' => 'ingoa_pae',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected count.
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
|
||||
// The migration configuration.
|
||||
$tests[0]['configuration']['variables'] = [
|
||||
'site_slogan',
|
||||
'site_name',
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d7\VariableTranslation
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableTranslationTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['variable_store'] = [
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'fr',
|
||||
'name' => 'site_slogan',
|
||||
'value' => 'fr - site slogan',
|
||||
'serialized' => '0',
|
||||
],
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'fr',
|
||||
'name' => 'user_mail_status_blocked_subject',
|
||||
'value' => 'fr - BEGONE!',
|
||||
'serialized' => '0',
|
||||
],
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'is',
|
||||
'name' => 'site_slogan',
|
||||
'value' => 's:16:"is - site slogan";',
|
||||
'serialized' => '1',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'fr - site slogan',
|
||||
'user_mail_status_blocked_subject' => 'fr - BEGONE!',
|
||||
],
|
||||
[
|
||||
'language' => 'is',
|
||||
'site_slogan' => 'is - site slogan',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected count.
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
|
||||
// The migration configuration.
|
||||
$tests[0]['configuration']['variables'] = [
|
||||
'site_slogan',
|
||||
'user_mail_status_blocked_subject',
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the config source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d8\Config
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class ConfigTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$data = [];
|
||||
|
||||
// The source database tables.
|
||||
$data[0]['source_data'] = [
|
||||
'config' => [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:14:"af - Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => '',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:9:"Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => 'language.de',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:14:"de - Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => 'b:0;',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$data[0]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'user.settings',
|
||||
'data' => [
|
||||
'anonymous' => 'af - Anonymous',
|
||||
],
|
||||
],
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => FALSE,
|
||||
],
|
||||
];
|
||||
$data[0]['expected_count'] = NULL;
|
||||
$data[0]['configuration'] = [
|
||||
'names' => [
|
||||
'user.settings',
|
||||
'bar',
|
||||
],
|
||||
'collections' => [
|
||||
'language.af',
|
||||
],
|
||||
];
|
||||
|
||||
// Test with name and no collection in configuration.
|
||||
$data[1]['source_data'] = $data[0]['source_data'];
|
||||
$data[1]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => FALSE,
|
||||
],
|
||||
];
|
||||
$data[1]['expected_count'] = NULL;
|
||||
$data[1]['configuration'] = [
|
||||
'names' => [
|
||||
'bar',
|
||||
],
|
||||
];
|
||||
|
||||
// Test with collection and no name in configuration.
|
||||
$data[2]['source_data'] = $data[0]['source_data'];
|
||||
$data[2]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.de',
|
||||
'name' => 'user.settings',
|
||||
'data' => [
|
||||
'anonymous' => 'de - Anonymous',
|
||||
],
|
||||
],
|
||||
];
|
||||
$data[2]['expected_count'] = NULL;
|
||||
$data[2]['configuration'] = [
|
||||
'collections' => [
|
||||
'language.de',
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
use Drupal\user\Entity\User;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class EntityContentBaseTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_overwrite_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a field on the user entity so that we can test nested property
|
||||
// overwrites.
|
||||
// @see static::testOverwriteSelectedNestedProperty()
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'signature',
|
||||
'entity_type' => 'user',
|
||||
'type' => 'text_long',
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => 'signature',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
])->save();
|
||||
|
||||
User::create([
|
||||
'uid' => 2,
|
||||
'name' => 'Ford Prefect',
|
||||
'mail' => 'ford.prefect@localhost',
|
||||
'signature' => [
|
||||
[
|
||||
'value' => 'Bring a towel.',
|
||||
'format' => 'filtered_html',
|
||||
],
|
||||
],
|
||||
'init' => 'proto@zo.an',
|
||||
])->save();
|
||||
|
||||
$this->executeMigrations(['d6_filter_format', 'd6_user_role']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests overwriting all mapped properties in the destination entity (default
|
||||
* behavior).
|
||||
*/
|
||||
public function testOverwriteAllMappedProperties() {
|
||||
$this->executeMigration('d6_user');
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = User::load(2);
|
||||
$this->assertIdentical('john.doe', $account->label());
|
||||
$this->assertIdentical('john.doe@example.com', $account->getEmail());
|
||||
$this->assertIdentical('doe@example.com', $account->getInitialEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests overwriting selected properties in the destination entity, specified
|
||||
* in the destination configuration.
|
||||
*/
|
||||
public function testOverwriteProperties() {
|
||||
// Execute the migration in migrate_overwrite_test, which documents how
|
||||
// property overwrites work.
|
||||
$this->executeMigration('users');
|
||||
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = User::load(2);
|
||||
$this->assertIdentical('john.doe', $account->label());
|
||||
$this->assertIdentical('john.doe@example.com', $account->getEmail());
|
||||
$this->assertIdentical('The answer is 42.', $account->signature->value);
|
||||
// This value is not overwritten because it's not listed in
|
||||
// overwrite_properties.
|
||||
$this->assertIdentical('proto@zo.an', $account->getInitialEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that translation destination fails for untranslatable entities.
|
||||
*/
|
||||
public function testUntranslatable() {
|
||||
$this->enableModules(['language_test']);
|
||||
$this->installEntitySchema('no_language_entity_test');
|
||||
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration([
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'ids' => ['id' => ['type' => 'integer']],
|
||||
'data_rows' => [['id' => 1]],
|
||||
],
|
||||
'process' => [
|
||||
'id' => 'id',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:no_language_entity_test',
|
||||
'translations' => TRUE,
|
||||
],
|
||||
]);
|
||||
|
||||
$message = $this->prophesize(MigrateMessageInterface::class);
|
||||
// Match the expected message. Can't use default argument types, because
|
||||
// we need to convert to string from TranslatableMarkup.
|
||||
$argument = Argument::that(function ($msg) {
|
||||
return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE;
|
||||
});
|
||||
$message->display($argument, Argument::any())
|
||||
->shouldBeCalled();
|
||||
|
||||
$executable = new MigrateExecutable($migration, $message->reveal());
|
||||
$executable->import();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
|
||||
|
||||
/**
|
||||
* Tests follow-up migrations.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class FollowUpMigrationsTest extends MigrateNodeTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// A requirement for d6_node_translation.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_content_settings',
|
||||
'd6_node',
|
||||
'd6_node_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test entity reference translations.
|
||||
*/
|
||||
public function testEntityReferenceTranslations() {
|
||||
// Test the entity reference field before the follow-up migrations.
|
||||
$node = Node::load(10);
|
||||
$this->assertSame('13', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('13', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('20', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('20', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(12)->getTranslation('en');
|
||||
$this->assertSame('10', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('11', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('11', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
// Run the follow-up migrations.
|
||||
$migration_plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
$migration_plugin_manager->clearCachedDefinitions();
|
||||
$follow_up_migrations = $migration_plugin_manager->createInstances('d6_entity_reference_translation');
|
||||
$this->executeMigrations(array_keys($follow_up_migrations));
|
||||
|
||||
// Test the entity reference field after the follow-up migrations.
|
||||
$node = Node::load(10);
|
||||
$this->assertSame('12', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('12', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('12', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('12', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(12)->getTranslation('en');
|
||||
$this->assertSame('10', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('10', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $translation->get('field_reference_2')->target_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Audit\AuditResult;
|
||||
use Drupal\migrate\Audit\IdAuditor;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
|
||||
|
||||
/**
|
||||
* Tests the migration auditor for ID conflicts.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDrupal6AuditIdsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateTestContentEntitiesTrait;
|
||||
use ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
|
||||
// Install required entity schemas.
|
||||
$this->installEntitySchemas();
|
||||
|
||||
// Install required schemas.
|
||||
$this->installSchema('book', ['book']);
|
||||
$this->installSchema('dblog', ['watchdog']);
|
||||
$this->installSchema('forum', ['forum_index']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('search', ['search_dataset']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('tracker', ['tracker_node', 'tracker_user']);
|
||||
|
||||
// Enable content moderation for nodes of type page.
|
||||
$this->installEntitySchema('content_moderation_state');
|
||||
$this->installConfig('content_moderation');
|
||||
NodeType::create(['type' => 'page'])->save();
|
||||
$workflow = $this->createEditorialWorkflow();
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
|
||||
$workflow->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multiple migrations to the same destination with no ID conflicts.
|
||||
*/
|
||||
public function testMultipleMigrationWithoutIdConflicts() {
|
||||
// Create a node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d6_node:page migration mapping table to simulate a
|
||||
// previously migrated node.
|
||||
$id_map = $this->getMigration('d6_node:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d6_node migrations for the page & article node type.
|
||||
// There should be no conflicts since the highest destination ID should be
|
||||
// equal to the highest migrated ID, as found in the aggregated mapping
|
||||
// tables of the two node migrations.
|
||||
$migrations = [
|
||||
$this->getMigration('d6_node:page'),
|
||||
$this->getMigration('d6_node:article'),
|
||||
];
|
||||
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with no ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithNoIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 6');
|
||||
|
||||
// Audit all Drupal 6 migrations that support it. There should be no
|
||||
// conflicts since no content has been created.
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithIdConflicts() {
|
||||
// Get all Drupal 6 migrations.
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 6');
|
||||
|
||||
// Create content.
|
||||
$this->createContent();
|
||||
|
||||
// Audit the IDs of all migrations. There should be conflicts since content
|
||||
// has been created.
|
||||
$conflicts = array_map(
|
||||
function (AuditResult $result) {
|
||||
return $result->passed() ? NULL : $result->getMigration()->getBaseId();
|
||||
},
|
||||
(new IdAuditor())->auditMultiple($migrations)
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'd6_aggregator_feed',
|
||||
'd6_aggregator_item',
|
||||
'd6_comment',
|
||||
'd6_custom_block',
|
||||
'd6_file',
|
||||
'd6_menu_links',
|
||||
'd6_node',
|
||||
'd6_node_revision',
|
||||
'd6_taxonomy_term',
|
||||
'd6_term_node_revision',
|
||||
'd6_user',
|
||||
'node_translation_menu_links',
|
||||
];
|
||||
$this->assertEmpty(array_diff(array_filter($conflicts), $expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests draft revisions ID conflicts.
|
||||
*/
|
||||
public function testDraftRevisionIdConflicts() {
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Create a draft revision.
|
||||
$node->moderation_state->value = 'draft';
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d6_node_revision:page migration mapping table to
|
||||
// simulate a previously migrated node revision.
|
||||
$id_map = $this->getMigration('d6_node_revision:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d6_node_revision migration. There should be
|
||||
// conflicts since a draft revision has been created.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d6_node_revision:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID conflicts for inaccessible nodes.
|
||||
*/
|
||||
public function testNodeGrantsIdConflicts() {
|
||||
// Enable the node_test module to restrict access to page nodes.
|
||||
$this->enableModules(['node_test']);
|
||||
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Audit the IDs of the d6_node migration. There should be conflicts
|
||||
// even though the new node is not accessible.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d6_node:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal 6 migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupal6TestBase extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'datetime',
|
||||
'filter',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'options',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal6.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all user migrations.
|
||||
*
|
||||
* @param bool $include_pictures
|
||||
* If TRUE, migrates user pictures.
|
||||
*/
|
||||
protected function migrateUsers($include_pictures = TRUE) {
|
||||
$this->executeMigrations(['d6_filter_format', 'd6_user_role']);
|
||||
|
||||
if ($include_pictures) {
|
||||
$this->installEntitySchema('file');
|
||||
$this->executeMigrations([
|
||||
'd6_file',
|
||||
'd6_user_picture_file',
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
'user_picture_entity_display',
|
||||
'user_picture_entity_form_display',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->executeMigration('d6_user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates node types.
|
||||
*/
|
||||
protected function migrateContentTypes() {
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigration('d6_node_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all field migrations.
|
||||
*/
|
||||
protected function migrateFields() {
|
||||
$this->migrateContentTypes();
|
||||
$this->executeMigrations([
|
||||
'd6_field',
|
||||
'd6_field_instance',
|
||||
'd6_field_instance_widget_settings',
|
||||
'd6_view_modes',
|
||||
'd6_field_formatter_settings',
|
||||
'd6_upload_field',
|
||||
'd6_upload_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all content migrations.
|
||||
*
|
||||
* @param array $include
|
||||
* Extra things to include as part of the migrations. Values may be
|
||||
* 'revisions' or 'translations'.
|
||||
*/
|
||||
protected function migrateContent($include = []) {
|
||||
if (in_array('translations', $include)) {
|
||||
$this->executeMigrations(['language']);
|
||||
}
|
||||
$this->migrateUsers(FALSE);
|
||||
$this->migrateFields();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->executeMigrations(['d6_node_settings', 'd6_node']);
|
||||
|
||||
if (in_array('translations', $include)) {
|
||||
$this->executeMigrations(['translations']);
|
||||
}
|
||||
if (in_array('revisions', $include)) {
|
||||
$this->executeMigrations(['d6_node_revision']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all taxonomy migrations.
|
||||
*/
|
||||
protected function migrateTaxonomy() {
|
||||
$this->migrateContentTypes();
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->executeMigrations([
|
||||
'd6_taxonomy_vocabulary',
|
||||
'd6_vocabulary_field',
|
||||
'd6_vocabulary_field_instance',
|
||||
'd6_vocabulary_entity_display',
|
||||
'd6_vocabulary_entity_form_display',
|
||||
'd6_taxonomy_term',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
|
||||
|
||||
/**
|
||||
* Tests follow-up migrations.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use FileMigrationSetupTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'comment',
|
||||
'datetime',
|
||||
'file',
|
||||
'image',
|
||||
'language',
|
||||
'link',
|
||||
'menu_ui',
|
||||
// A requirement for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fileMigrationSetup();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node_type',
|
||||
'd7_language_content_settings',
|
||||
'd7_comment_type',
|
||||
'd7_taxonomy_vocabulary',
|
||||
'd7_field',
|
||||
'd7_field_instance',
|
||||
'd7_node',
|
||||
'd7_node_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFileMigrationInfo() {
|
||||
return [
|
||||
'path' => 'public://sites/default/files/cube.jpeg',
|
||||
'size' => '3620',
|
||||
'base_path' => 'public://',
|
||||
'plugin_id' => 'd7_file',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test entity reference translations.
|
||||
*/
|
||||
public function testEntityReferenceTranslations() {
|
||||
// Test the entity reference field before the follow-up migrations.
|
||||
$node = Node::load(2);
|
||||
$this->assertSame('5', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('5', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('is');
|
||||
$this->assertSame('4', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(4);
|
||||
$this->assertSame('3', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('3', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('en');
|
||||
$this->assertSame('2', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
// Run the follow-up migrations.
|
||||
$migration_plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
$migration_plugin_manager->clearCachedDefinitions();
|
||||
$follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation');
|
||||
$this->executeMigrations(array_keys($follow_up_migrations));
|
||||
|
||||
// Test the entity reference field after the follow-up migrations.
|
||||
$node = Node::load(2);
|
||||
$this->assertSame('4', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('is');
|
||||
$this->assertSame('4', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(4);
|
||||
$this->assertSame('2', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('en');
|
||||
$this->assertSame('2', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $translation->get('field_reference_2')->target_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Audit\AuditResult;
|
||||
use Drupal\migrate\Audit\IdAuditor;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
|
||||
|
||||
/**
|
||||
* Tests the migration auditor for ID conflicts.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDrupal7AuditIdsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateTestContentEntitiesTrait;
|
||||
use ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
|
||||
// Install required entity schemas.
|
||||
$this->installEntitySchemas();
|
||||
|
||||
// Install required schemas.
|
||||
$this->installSchema('book', ['book']);
|
||||
$this->installSchema('dblog', ['watchdog']);
|
||||
$this->installSchema('forum', ['forum_index']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('search', ['search_dataset']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('tracker', ['tracker_node', 'tracker_user']);
|
||||
|
||||
// Enable content moderation for nodes of type page.
|
||||
$this->installEntitySchema('content_moderation_state');
|
||||
$this->installConfig('content_moderation');
|
||||
NodeType::create(['type' => 'page'])->save();
|
||||
$workflow = $this->createEditorialWorkflow();
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
|
||||
$workflow->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multiple migrations to the same destination with no ID conflicts.
|
||||
*/
|
||||
public function testMultipleMigrationWithoutIdConflicts() {
|
||||
// Create a node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d7_node:page migration mapping table to simulate a
|
||||
// previously migrated node.
|
||||
$id_map = $this->getMigration('d7_node:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d7_node migrations for the page & article node type.
|
||||
// There should be no conflicts since the highest destination ID should be
|
||||
// equal to the highest migrated ID, as found in the aggregated mapping
|
||||
// tables of the two node migrations.
|
||||
$migrations = [
|
||||
$this->getMigration('d7_node:page'),
|
||||
$this->getMigration('d7_node:article'),
|
||||
];
|
||||
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with no ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithNoIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 7');
|
||||
|
||||
// Audit the IDs of all Drupal 7 migrations. There should be no conflicts
|
||||
// since no content has been created.
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 7');
|
||||
|
||||
// Create content.
|
||||
$this->createContent();
|
||||
|
||||
// Audit the IDs of all Drupal 7 migrations. There should be conflicts since
|
||||
// content has been created.
|
||||
$conflicts = array_map(
|
||||
function (AuditResult $result) {
|
||||
return $result->passed() ? NULL : $result->getMigration()->getBaseId();
|
||||
},
|
||||
(new IdAuditor())->auditMultiple($migrations)
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'd7_aggregator_feed',
|
||||
'd7_aggregator_item',
|
||||
'd7_comment',
|
||||
'd7_custom_block',
|
||||
'd7_file',
|
||||
'd7_file_private',
|
||||
'd7_menu_links',
|
||||
'd7_node',
|
||||
'd7_node_revision',
|
||||
'd7_taxonomy_term',
|
||||
'd7_user',
|
||||
'node_translation_menu_links',
|
||||
];
|
||||
$this->assertEmpty(array_diff(array_filter($conflicts), $expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests draft revisions ID conflicts.
|
||||
*/
|
||||
public function testDraftRevisionIdConflicts() {
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Create a draft revision.
|
||||
$node->moderation_state->value = 'draft';
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d7_node_revision:page migration mapping table to
|
||||
// simulate a previously migrated node revision.
|
||||
$id_map = $this->getMigration('d7_node_revision:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d7_node_revision migration. There should be
|
||||
// conflicts since a draft revision has been created.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d7_node_revision:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID conflicts for inaccessible nodes.
|
||||
*/
|
||||
public function testNodeGrantsIdConflicts() {
|
||||
// Enable the node_test module to restrict access to page nodes.
|
||||
$this->enableModules(['node_test']);
|
||||
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Audit the IDs of the d7_node migration. There should be conflicts
|
||||
// even though the new node is not accessible.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d7_node:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal 7 migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupal7TestBase extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal7.php';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\dependencies;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Ensure the consistency among the dependencies for migrate.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDependenciesTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['aggregator', 'comment'];
|
||||
|
||||
/**
|
||||
* Tests that the order is correct when loading several migrations.
|
||||
*/
|
||||
public function testMigrateDependenciesOrder() {
|
||||
$migration_items = ['d6_comment', 'd6_filter_format', 'd6_node:page'];
|
||||
$migrations = $this->container->get('plugin.manager.migration')->createInstances($migration_items);
|
||||
$expected_order = ['d6_filter_format', 'd6_node:page', 'd6_comment'];
|
||||
$this->assertIdentical(array_keys($migrations), $expected_order);
|
||||
$expected_requirements = [
|
||||
// d6_comment depends on d6_node:*, which the deriver expands into every
|
||||
// variant of d6_node.
|
||||
'd6_node:article',
|
||||
'd6_node:company',
|
||||
'd6_node:employee',
|
||||
'd6_node:event',
|
||||
'd6_node:forum',
|
||||
'd6_node:page',
|
||||
'd6_user',
|
||||
'd6_node_type',
|
||||
'd6_node_settings',
|
||||
'd6_filter_format',
|
||||
'd6_node:sponsor',
|
||||
'd6_node:story',
|
||||
'd6_node:test_event',
|
||||
'd6_node:test_page',
|
||||
'd6_node:test_planet',
|
||||
'd6_node:test_story',
|
||||
'd6_comment_type',
|
||||
'd6_comment_entity_display',
|
||||
'd6_comment_entity_form_display',
|
||||
];
|
||||
// Migration dependencies for comment include dependencies for node
|
||||
// migration as well.
|
||||
$actual_requirements = $migrations['d6_comment']->get('requirements');
|
||||
$this->assertIdentical(count($actual_requirements), count($expected_requirements));
|
||||
foreach ($expected_requirements as $requirement) {
|
||||
$this->assertIdentical($actual_requirements[$requirement], $requirement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests dependencies on the migration of aggregator feeds & items.
|
||||
*/
|
||||
public function testAggregatorMigrateDependencies() {
|
||||
/** @var \Drupal\migrate\Plugin\Migration $migration */
|
||||
$migration = $this->getMigration('d6_aggregator_item');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$this->startCollectingMessages();
|
||||
$executable->import();
|
||||
$this->assertEqual($this->migrateMessages['error'], [new FormattableMarkup('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', ['@id' => $migration->id()])]);
|
||||
$this->collectMessages = FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Traits;
|
||||
|
||||
trait CreateMigrationsTrait {
|
||||
|
||||
/**
|
||||
* Create instances of all Drupal 6 migrations.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations
|
||||
*/
|
||||
public function drupal6Migrations() {
|
||||
$dirs = \Drupal::service('module_handler')->getModuleDirectories();
|
||||
$migrate_drupal_directory = $dirs['migrate_drupal'];
|
||||
$this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal6.php");
|
||||
return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 6');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instances of all Drupal 7 migrations.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations
|
||||
*/
|
||||
public function drupal7Migrations() {
|
||||
$dirs = \Drupal::service('module_handler')->getModuleDirectories();
|
||||
$migrate_drupal_directory = $dirs['migrate_drupal'];
|
||||
$this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal7.php");
|
||||
return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 7');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Traits;
|
||||
|
||||
/**
|
||||
* Provides helper methods for creating test content.
|
||||
*/
|
||||
trait CreateTestContentEntitiesTrait {
|
||||
|
||||
/**
|
||||
* Gets required modules.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getRequiredModules() {
|
||||
return [
|
||||
'aggregator',
|
||||
'block_content',
|
||||
'comment',
|
||||
'field',
|
||||
'file',
|
||||
'link',
|
||||
'menu_link_content',
|
||||
'migrate_drupal',
|
||||
'node',
|
||||
'options',
|
||||
'system',
|
||||
'taxonomy',
|
||||
'text',
|
||||
'user',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Install required entity schemas.
|
||||
*/
|
||||
protected function installEntitySchemas() {
|
||||
$this->installEntitySchema('aggregator_feed');
|
||||
$this->installEntitySchema('aggregator_item');
|
||||
$this->installEntitySchema('block_content');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installEntitySchema('menu_link_content');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create several pieces of generic content.
|
||||
*/
|
||||
protected function createContent() {
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
// Create an aggregator feed.
|
||||
if ($entity_type_manager->hasDefinition('aggregator_feed')) {
|
||||
$feed = $entity_type_manager->getStorage('aggregator_feed')->create([
|
||||
'title' => 'feed',
|
||||
'url' => 'http://www.example.com',
|
||||
]);
|
||||
$feed->save();
|
||||
|
||||
// Create an aggregator feed item.
|
||||
$item = $entity_type_manager->getStorage('aggregator_item')->create([
|
||||
'title' => 'feed item',
|
||||
'fid' => $feed->id(),
|
||||
'link' => 'http://www.example.com',
|
||||
]);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
// Create a block content.
|
||||
if ($entity_type_manager->hasDefinition('block_content')) {
|
||||
$block = $entity_type_manager->getStorage('block_content')->create([
|
||||
'info' => 'block',
|
||||
'type' => 'block',
|
||||
]);
|
||||
$block->save();
|
||||
}
|
||||
|
||||
// Create a node.
|
||||
if ($entity_type_manager->hasDefinition('node')) {
|
||||
$node = $entity_type_manager->getStorage('node')->create([
|
||||
'type' => 'page',
|
||||
'title' => 'page',
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Create a comment.
|
||||
if ($entity_type_manager->hasDefinition('comment')) {
|
||||
$comment = $entity_type_manager->getStorage('comment')->create([
|
||||
'comment_type' => 'comment',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'entity_id' => $node->id(),
|
||||
]);
|
||||
$comment->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a file.
|
||||
if ($entity_type_manager->hasDefinition('file')) {
|
||||
$file = $entity_type_manager->getStorage('file')->create([
|
||||
'uri' => 'public://example.txt',
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
|
||||
// Create a menu link.
|
||||
if ($entity_type_manager->hasDefinition('menu_link_content')) {
|
||||
$menu_link = $entity_type_manager->getStorage('menu_link_content')->create([
|
||||
'title' => 'menu link',
|
||||
'link' => ['uri' => 'http://www.example.com'],
|
||||
'menu_name' => 'tools',
|
||||
]);
|
||||
$menu_link->save();
|
||||
}
|
||||
|
||||
// Create a taxonomy term.
|
||||
if ($entity_type_manager->hasDefinition('taxonomy_term')) {
|
||||
$term = $entity_type_manager->getStorage('taxonomy_term')->create([
|
||||
'name' => 'term',
|
||||
'vid' => 'term',
|
||||
]);
|
||||
$term->save();
|
||||
}
|
||||
|
||||
// Create a user.
|
||||
if ($entity_type_manager->hasDefinition('user')) {
|
||||
$user = $entity_type_manager->getStorage('user')->create([
|
||||
'name' => 'user',
|
||||
'mail' => 'user@example.com',
|
||||
]);
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create several pieces of generic content.
|
||||
*/
|
||||
protected function createContentPostUpgrade() {
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
// Create a block content.
|
||||
if ($entity_type_manager->hasDefinition('block_content')) {
|
||||
$block = $entity_type_manager->getStorage('block_content')->create([
|
||||
'info' => 'Post upgrade block',
|
||||
'type' => 'block',
|
||||
]);
|
||||
$block->save();
|
||||
}
|
||||
|
||||
// Create a node.
|
||||
if ($entity_type_manager->hasDefinition('node')) {
|
||||
$node = $entity_type_manager->getStorage('node')->create([
|
||||
'type' => 'page',
|
||||
'title' => 'Post upgrade page',
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Create a comment.
|
||||
if ($entity_type_manager->hasDefinition('comment')) {
|
||||
$comment = $entity_type_manager->getStorage('comment')->create([
|
||||
'comment_type' => 'comment',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'entity_id' => $node->id(),
|
||||
]);
|
||||
$comment->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a file.
|
||||
if ($entity_type_manager->hasDefinition('file')) {
|
||||
$file = $entity_type_manager->getStorage('file')->create([
|
||||
'uri' => 'public://post_upgrade_example.txt',
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
|
||||
// Create a menu link.
|
||||
if ($entity_type_manager->hasDefinition('menu_link_content')) {
|
||||
$menu_link = $entity_type_manager->getStorage('menu_link_content')->create([
|
||||
'title' => 'post upgrade menu link',
|
||||
'link' => ['uri' => 'http://www.drupal.org'],
|
||||
'menu_name' => 'tools',
|
||||
]);
|
||||
$menu_link->save();
|
||||
}
|
||||
|
||||
// Create a taxonomy term.
|
||||
if ($entity_type_manager->hasDefinition('taxonomy_term')) {
|
||||
$term = $entity_type_manager->getStorage('taxonomy_term')->create([
|
||||
'name' => 'post upgrade term',
|
||||
'vid' => 'term',
|
||||
]);
|
||||
$term->save();
|
||||
}
|
||||
|
||||
// Create a user.
|
||||
if ($entity_type_manager->hasDefinition('user')) {
|
||||
$user = $entity_type_manager->getStorage('user')->create([
|
||||
'name' => 'universe',
|
||||
'mail' => 'universe@example.com',
|
||||
]);
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class DrupalSqlBaseTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'DrupalSqlBase',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* Minimum database contents needed to test DrupalSqlBase.
|
||||
*/
|
||||
protected $databaseContents = [
|
||||
'system' => [
|
||||
[
|
||||
'filename' => 'sites/all/modules/module1',
|
||||
'name' => 'module1',
|
||||
'type' => 'module',
|
||||
'status' => 0,
|
||||
'schema_version' => -1,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @covers ::checkRequirements
|
||||
*/
|
||||
public function testSourceProviderNotActive() {
|
||||
$plugin_definition['requirements_met'] = TRUE;
|
||||
$plugin_definition['source_module'] = 'module1';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_manager);
|
||||
$plugin->setDatabase($this->getDatabase($this->databaseContents));
|
||||
$system_data = $plugin->getSystemData();
|
||||
$this->setExpectedException(RequirementsException::class, 'The module module1 is not enabled in the source site.');
|
||||
try {
|
||||
$plugin->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Ensure requirements are set on the exception.
|
||||
$this->assertEquals(['source_module' => 'module1'], $e->getRequirements());
|
||||
// Re-throw so PHPUnit can assert the exception.
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkRequirements
|
||||
*/
|
||||
public function testSourceDatabaseError() {
|
||||
$plugin_definition['requirements_met'] = TRUE;
|
||||
$plugin_definition['source_module'] = 'module1';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$plugin = new TestDrupalSqlBase([], 'test', $plugin_definition, $this->getMigration(), $state, $entity_manager);
|
||||
$system_data = $plugin->getSystemData();
|
||||
$this->setExpectedException(RequirementsException::class, 'No database connection configured for source plugin test');
|
||||
$plugin->checkRequirements();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Extends the DrupalSqlBase abstract class.
|
||||
*/
|
||||
class TestDrupalSqlBase extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks DrupalSqlBase to set a new database connection for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $database
|
||||
* The new connection to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSourceSqlTestCase
|
||||
*/
|
||||
public function setDatabase(Connection $database) {
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Base class for variable multirow source unit tests.
|
||||
*/
|
||||
abstract class VariableMultiRowTestBase extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow';
|
||||
|
||||
// The fake Migration configuration entity.
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'source' => [
|
||||
'plugin' => 'd6_variable_multirow',
|
||||
'variables' => [
|
||||
'foo',
|
||||
'bar',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
protected $expectedResults = [
|
||||
['name' => 'foo', 'value' => 1],
|
||||
['name' => 'bar', 'value' => FALSE],
|
||||
];
|
||||
|
||||
protected $databaseContents = [
|
||||
'variable' => [
|
||||
['name' => 'foo', 'value' => 'i:1;'],
|
||||
['name' => 'bar', 'value' => 'b:0;'],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\Variable';
|
||||
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => ['field' => 'test'],
|
||||
'source' => [
|
||||
'plugin' => 'd6_variable',
|
||||
'variables' => [
|
||||
'foo',
|
||||
'bar',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'id' => 'foo',
|
||||
'foo' => 1,
|
||||
'bar' => FALSE,
|
||||
],
|
||||
];
|
||||
|
||||
protected $databaseContents = [
|
||||
'variable' => [
|
||||
['name' => 'foo', 'value' => 'i:1;'],
|
||||
['name' => 'bar', 'value' => 'b:0;'],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
/**
|
||||
* Tests the D6 SQL base class.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class Drupal6SqlBaseTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'Drupal6SqlBase',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* Minimum database contents needed to test Drupal6SqlBase.
|
||||
*/
|
||||
protected $databaseContents = [
|
||||
'system' => [
|
||||
[
|
||||
'filename' => 'sites/all/modules/module1',
|
||||
'name' => 'module1',
|
||||
'type' => 'module',
|
||||
'status' => 1,
|
||||
'schema_version' => -1,
|
||||
],
|
||||
[
|
||||
'filename' => 'sites/all/modules/module2',
|
||||
'name' => 'module2',
|
||||
'type' => 'module',
|
||||
'status' => 0,
|
||||
'schema_version' => 7201,
|
||||
],
|
||||
[
|
||||
'filename' => 'sites/all/modules/test2',
|
||||
'name' => 'test2',
|
||||
'type' => 'theme',
|
||||
'status' => 1,
|
||||
'schema_version' => -1,
|
||||
],
|
||||
],
|
||||
'variable' => [
|
||||
[
|
||||
'name' => 'my_variable',
|
||||
'value' => 'b:1;',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$plugin = 'placeholder_id';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, [], $this->getMigration(), $state, $entity_manager);
|
||||
$this->base->setDatabase($this->getDatabase($this->databaseContents));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::getSystemData().
|
||||
*/
|
||||
public function testGetSystemData() {
|
||||
$system_data = $this->base->getSystemData();
|
||||
// Should be 1 theme and 2 modules.
|
||||
$this->assertEquals(1, count($system_data['theme']));
|
||||
$this->assertEquals(2, count($system_data['module']));
|
||||
|
||||
// Calling again should be identical.
|
||||
$this->assertSame($system_data, $this->base->getSystemData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::moduleExists().
|
||||
*/
|
||||
public function testDrupal6ModuleExists() {
|
||||
// This module should exist.
|
||||
$this->assertTrue($this->base->moduleExistsWrapper('module1'));
|
||||
|
||||
// These modules should not exist.
|
||||
$this->assertFalse($this->base->moduleExistsWrapper('module2'));
|
||||
$this->assertFalse($this->base->moduleExistsWrapper('module3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::getModuleSchemaVersion().
|
||||
*/
|
||||
public function testGetModuleSchemaVersion() {
|
||||
// Non-existent module.
|
||||
$this->assertFalse($this->base->getModuleSchemaVersionWrapper('module3'));
|
||||
|
||||
// Disabled module should still return schema version.
|
||||
$this->assertEquals(7201, $this->base->getModuleSchemaVersionWrapper('module2'));
|
||||
|
||||
// Enabled module.
|
||||
$this->assertEquals(-1, $this->base->getModuleSchemaVersionWrapper('module1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::variableGet().
|
||||
*/
|
||||
public function testVariableGet() {
|
||||
// Test default value.
|
||||
$this->assertEquals('my_default', $this->base->variableGetWrapper('non_existent_variable', 'my_default'));
|
||||
|
||||
// Test non-default.
|
||||
$this->assertSame(TRUE, $this->base->variableGetWrapper('my_variable', FALSE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Extends the Drupal6SqlBase abstract class.
|
||||
*/
|
||||
class TestDrupal6SqlBase extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'filename' => t('The path of the primary file for this item.'),
|
||||
'name' => t('The name of the item; e.g. node.'),
|
||||
'type' => t('The type of the item, either module, theme, or theme_engine.'),
|
||||
'owner' => t("A theme's 'parent'. Can be either a theme or an engine."),
|
||||
'status' => t('Boolean indicating whether or not this item is enabled.'),
|
||||
'throttle' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'),
|
||||
'bootstrap' => t("Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted)."),
|
||||
'schema_version' => t("The module's database schema version number."),
|
||||
'weight' => t("The order in which this module's hooks should be invoked."),
|
||||
'info' => t("A serialized array containing information from the module's .info file."),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->database
|
||||
->select('system', 's')
|
||||
->fields('s', ['filename', 'name', 'schema_version']);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks Drupal6SqlBase to set a new database connection for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $database
|
||||
* The new connection to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
|
||||
*/
|
||||
public function setDatabase(Connection $database) {
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks Drupal6SqlBase to set a new module handler for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The new module handler to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
|
||||
*/
|
||||
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method moduleExists().
|
||||
*/
|
||||
public function moduleExistsWrapper($module) {
|
||||
return parent::moduleExists($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method getModuleSchemaVersion().
|
||||
*/
|
||||
public function getModuleSchemaVersionWrapper($module) {
|
||||
return parent::getModuleSchemaVersion($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method variableGet().
|
||||
*/
|
||||
public function variableGetWrapper($name, $default) {
|
||||
return parent::variableGet($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class VariableTranslationTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation';
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => ['field' => 'test'],
|
||||
'source' => [
|
||||
'plugin' => 'variable_translation',
|
||||
'variables' => [
|
||||
'site_slogan',
|
||||
'site_name',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected results from the source.
|
||||
*/
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'Migrate est génial',
|
||||
'site_name' => 'nom de site',
|
||||
],
|
||||
[
|
||||
'language' => 'mi',
|
||||
'site_slogan' => 'Ko whakamataku heke',
|
||||
'site_name' => 'ingoa_pae',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Database contents for tests.
|
||||
*/
|
||||
protected $databaseContents = [
|
||||
'i18n_variable' => [
|
||||
['name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'],
|
||||
['name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'],
|
||||
['name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'],
|
||||
['name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class i18nVariableTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable';
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => ['field' => 'test'],
|
||||
'source' => [
|
||||
'plugin' => 'i18n_variable',
|
||||
'variables' => [
|
||||
'site_slogan',
|
||||
'site_name',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected results from the source.
|
||||
*/
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'Migrate est génial',
|
||||
'site_name' => 'nom de site',
|
||||
],
|
||||
[
|
||||
'language' => 'mi',
|
||||
'site_slogan' => 'Ko whakamataku heke',
|
||||
'site_name' => 'ingoa_pae',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Database contents for tests.
|
||||
*/
|
||||
protected $databaseContents = [
|
||||
'i18n_variable' => [
|
||||
['name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'],
|
||||
['name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'],
|
||||
['name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'],
|
||||
['name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
Reference in a new issue