Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -103,7 +103,7 @@ use Drupal\migrate\Row;
|
|||
*/
|
||||
function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
|
||||
if ($migration->id() == 'd6_filter_formats') {
|
||||
$value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')))->fetchField();
|
||||
$value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', [':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')])->fetchField();
|
||||
if ($value) {
|
||||
$row->setSourceProperty('settings:mymodule:foo', unserialize($value));
|
||||
}
|
||||
|
|
|
@ -5,11 +5,6 @@
|
|||
* Contains install and update functions for Migrate.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.0.0-beta
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Remove load plugin references from existing migrations.
|
||||
*/
|
||||
|
@ -21,7 +16,3 @@ function migrate_update_8001() {
|
|||
$migration->save(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.0.0-beta".
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ function migrate_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.migrate':
|
||||
$output = '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>';
|
||||
$output .= t('The Migrate module provides a framework for migrating data, usually from an external source into your site. It does not provide a user interface. For more information, see the <a href=":migrate">online documentation for the Migrate module</a>.', array(':migrate' => 'https://www.drupal.org/documentation/modules/migrate'));
|
||||
$output .= t('The Migrate module provides a framework for migrating data, usually from an external source into your site. It does not provide a user interface. For more information, see the <a href=":migrate">online documentation for the Migrate module</a>.', [':migrate' => 'https://www.drupal.org/documentation/modules/migrate']);
|
||||
$output .= '</p>';
|
||||
return $output;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,12 @@ services:
|
|||
plugin.manager.migrate.id_map:
|
||||
class: Drupal\migrate\Plugin\MigratePluginManager
|
||||
arguments: [id_map, '@container.namespaces', '@cache.discovery', '@module_handler']
|
||||
cache.discovery_migration:
|
||||
class: Drupal\Core\Cache\CacheBackendInterface
|
||||
tags:
|
||||
- { name: cache.bin }
|
||||
factory: cache_factory:get
|
||||
arguments: [discovery_migration]
|
||||
plugin.manager.migration:
|
||||
class: Drupal\migrate\Plugin\MigrationPluginManager
|
||||
arguments: ['@module_handler', '@cache.discovery', '@language_manager']
|
||||
arguments: ['@module_handler', '@cache.discovery_migration', '@language_manager']
|
||||
|
|
|
@ -56,7 +56,7 @@ class RequirementsException extends \RuntimeException {
|
|||
$output = '';
|
||||
foreach ($this->requirements as $requirement_type => $requirements) {
|
||||
if (!is_array($requirements)) {
|
||||
$requirements = array($requirements);
|
||||
$requirements = [$requirements];
|
||||
}
|
||||
|
||||
foreach ($requirements as $value) {
|
||||
|
|
|
@ -65,7 +65,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $counts = array();
|
||||
protected $counts = [];
|
||||
|
||||
/**
|
||||
* The source.
|
||||
|
@ -151,10 +151,10 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
// Only begin the import operation if the migration is currently idle.
|
||||
if ($this->migration->getStatus() !== MigrationInterface::STATUS_IDLE) {
|
||||
$this->message->display($this->t('Migration @id is busy with another operation: @status',
|
||||
array(
|
||||
[
|
||||
'@id' => $this->migration->id(),
|
||||
'@status' => $this->t($this->migration->getStatusLabel()),
|
||||
)), 'error');
|
||||
]), 'error');
|
||||
return MigrationInterface::RESULT_FAILED;
|
||||
}
|
||||
$this->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration, $this->message));
|
||||
|
@ -167,11 +167,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
$this->message->display(
|
||||
$this->t(
|
||||
'Migration @id did not meet the requirements. @message @requirements',
|
||||
array(
|
||||
[
|
||||
'@id' => $this->migration->id(),
|
||||
'@message' => $e->getMessage(),
|
||||
'@requirements' => $e->getRequirementsString(),
|
||||
)
|
||||
]
|
||||
),
|
||||
'error'
|
||||
);
|
||||
|
@ -189,7 +189,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
}
|
||||
catch (\Exception $e) {
|
||||
$this->message->display(
|
||||
$this->t('Migration failed with source plugin exception: @e', array('@e' => $e->getMessage())), 'error');
|
||||
$this->t('Migration failed with source plugin exception: @e', ['@e' => $e->getMessage()]), 'error');
|
||||
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
|
||||
return MigrationInterface::RESULT_FAILED;
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
$save = TRUE;
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus());
|
||||
$this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus());
|
||||
$this->saveMessage($e->getMessage(), $e->getLevel());
|
||||
$save = FALSE;
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED);
|
||||
$id_map->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED);
|
||||
if (!$id_map->messageCount()) {
|
||||
$message = $this->t('New object was not saved, no error provided');
|
||||
$this->saveMessage($message);
|
||||
|
@ -239,11 +239,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
}
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus());
|
||||
$this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus());
|
||||
$this->saveMessage($e->getMessage(), $e->getLevel());
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->migration->getIdMap()->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED);
|
||||
$this->migration->getIdMap()->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED);
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
catch (\Exception $e) {
|
||||
$this->message->display(
|
||||
$this->t('Migration failed with source plugin exception: @e',
|
||||
array('@e' => $e->getMessage())), 'error');
|
||||
['@e' => $e->getMessage()]), 'error');
|
||||
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
|
||||
return MigrationInterface::RESULT_FAILED;
|
||||
}
|
||||
|
@ -356,9 +356,9 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
// plugin) and in this case the current value needs to be iterated
|
||||
// and each scalar separately transformed.
|
||||
if ($multiple && !$definition['handle_multiples']) {
|
||||
$new_value = array();
|
||||
$new_value = [];
|
||||
if (!is_array($value)) {
|
||||
throw new MigrateException(sprintf('Pipeline failed for destination %s: %s got instead of an array,', $destination, $value));
|
||||
throw new MigrateException(sprintf('Pipeline failed at %s plugin for destination %s: %s received instead of an array,', $plugin->getPluginId(), $destination, $value));
|
||||
}
|
||||
$break = FALSE;
|
||||
foreach ($value as $scalar_value) {
|
||||
|
@ -460,11 +460,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
$this->message->display(
|
||||
$this->t(
|
||||
'Memory usage is @usage (@pct% of limit @limit), reclaiming memory.',
|
||||
array(
|
||||
[
|
||||
'@pct' => round($pct_memory * 100),
|
||||
'@usage' => $this->formatSize($usage),
|
||||
'@limit' => $this->formatSize($this->memoryLimit),
|
||||
)
|
||||
]
|
||||
),
|
||||
'warning'
|
||||
);
|
||||
|
@ -476,11 +476,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
$this->message->display(
|
||||
$this->t(
|
||||
'Memory usage is now @usage (@pct% of limit @limit), not enough reclaimed, starting new batch',
|
||||
array(
|
||||
[
|
||||
'@pct' => round($pct_memory * 100),
|
||||
'@usage' => $this->formatSize($usage),
|
||||
'@limit' => $this->formatSize($this->memoryLimit),
|
||||
)
|
||||
]
|
||||
),
|
||||
'warning'
|
||||
);
|
||||
|
@ -490,11 +490,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
|
|||
$this->message->display(
|
||||
$this->t(
|
||||
'Memory usage is now @usage (@pct% of limit @limit), reclaimed enough, continuing',
|
||||
array(
|
||||
[
|
||||
'@pct' => round($pct_memory * 100),
|
||||
'@usage' => $this->formatSize($usage),
|
||||
'@limit' => $this->formatSize($this->memoryLimit),
|
||||
)
|
||||
]
|
||||
),
|
||||
'warning');
|
||||
return FALSE;
|
||||
|
|
|
@ -14,10 +14,10 @@ class MigrateMessage implements MigrateMessageInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $map = array(
|
||||
protected $map = [
|
||||
'status' => RfcLogLevel::INFO,
|
||||
'error' => RfcLogLevel::ERROR,
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -12,7 +12,7 @@ class MigrateEntity implements ContainerDeriverInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $derivatives = array();
|
||||
protected $derivatives = [];
|
||||
|
||||
/**
|
||||
* The entity definitions
|
||||
|
@ -59,12 +59,12 @@ class MigrateEntity implements ContainerDeriverInterface {
|
|||
$class = is_subclass_of($entity_info->getClass(), 'Drupal\Core\Config\Entity\ConfigEntityInterface') ?
|
||||
'Drupal\migrate\Plugin\migrate\destination\EntityConfigBase' :
|
||||
'Drupal\migrate\Plugin\migrate\destination\EntityContentBase';
|
||||
$this->derivatives[$entity_type] = array(
|
||||
$this->derivatives[$entity_type] = [
|
||||
'id' => "entity:$entity_type",
|
||||
'class' => $class,
|
||||
'requirements_met' => 1,
|
||||
'provider' => $entity_info->getProvider(),
|
||||
);
|
||||
];
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class MigrateEntityRevision implements ContainerDeriverInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $derivatives = array();
|
||||
protected $derivatives = [];
|
||||
|
||||
/**
|
||||
* The entity definitions
|
||||
|
@ -57,12 +57,12 @@ class MigrateEntityRevision implements ContainerDeriverInterface {
|
|||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityDefinitions as $entity_type => $entity_info) {
|
||||
if ($entity_info->getKey('revision')) {
|
||||
$this->derivatives[$entity_type] = array(
|
||||
$this->derivatives[$entity_type] = [
|
||||
'id' => "entity_revision:$entity_type",
|
||||
'class' => 'Drupal\migrate\Plugin\migrate\destination\EntityRevision',
|
||||
'requirements_met' => 1,
|
||||
'provider' => $entity_info->getProvider(),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
|
|
|
@ -73,7 +73,7 @@ class AnnotatedClassDiscoveryAutomatedProviders extends AnnotatedClassDiscovery
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinitions() {
|
||||
$definitions = array();
|
||||
$definitions = [];
|
||||
|
||||
$reader = $this->getAnnotationReader();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class ProviderFilterDecorator implements DiscoveryInterface {
|
|||
* A callable, gets passed a provider name, should return TRUE if the
|
||||
* provider exists and FALSE if not.
|
||||
*
|
||||
* @return array|\mixed[] $definitions
|
||||
* @return array|\mixed[]
|
||||
* An array of plugin definitions. If a definition is an array and has a
|
||||
* provider key that provider is guaranteed to exist.
|
||||
*/
|
||||
|
|
|
@ -106,7 +106,7 @@ interface MigrateDestinationInterface extends PluginInspectionInterface {
|
|||
* @return mixed
|
||||
* The entity ID or an indication of success.
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array());
|
||||
public function import(Row $row, array $old_destination_id_values = []);
|
||||
|
||||
/**
|
||||
* Delete the specified destination object from the target Drupal.
|
||||
|
|
|
@ -54,7 +54,7 @@ class MigrateDestinationPluginManager extends MigratePluginManager {
|
|||
*
|
||||
* A specific createInstance method is necessary to pass the migration on.
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array(), MigrationInterface $migration = NULL) {
|
||||
public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
|
||||
if (substr($plugin_id, 0, 7) == 'entity:' && !$this->entityManager->getDefinition(substr($plugin_id, 7), FALSE)) {
|
||||
$plugin_id = 'null';
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class MigratePluginManager extends DefaultPluginManager implements MigratePlugin
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array(), MigrationInterface $migration = NULL) {
|
||||
public function createInstance($plugin_id, array $configuration = [], MigrationInterface $migration = NULL) {
|
||||
$plugin_definition = $this->getDefinition($plugin_id);
|
||||
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
|
||||
// If the plugin provides a factory method, pass the container to it.
|
||||
|
|
|
@ -346,9 +346,9 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
|
|||
}
|
||||
$index = serialize($process);
|
||||
if (!isset($this->processPlugins[$index])) {
|
||||
$this->processPlugins[$index] = array();
|
||||
$this->processPlugins[$index] = [];
|
||||
foreach ($this->getProcessNormalized($process) as $property => $configurations) {
|
||||
$this->processPlugins[$index][$property] = array();
|
||||
$this->processPlugins[$index][$property] = [];
|
||||
foreach ($configurations as $configuration) {
|
||||
if (isset($configuration['source'])) {
|
||||
$this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance('get', $configuration, $this);
|
||||
|
@ -376,16 +376,16 @@ class Migration extends PluginBase implements MigrationInterface, RequirementsIn
|
|||
* The normalized process configuration.
|
||||
*/
|
||||
protected function getProcessNormalized(array $process) {
|
||||
$normalized_configurations = array();
|
||||
$normalized_configurations = [];
|
||||
foreach ($process as $destination => $configuration) {
|
||||
if (is_string($configuration)) {
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'plugin' => 'get',
|
||||
'source' => $configuration,
|
||||
);
|
||||
];
|
||||
}
|
||||
if (isset($configuration['plugin'])) {
|
||||
$configuration = array($configuration);
|
||||
$configuration = [$configuration];
|
||||
}
|
||||
$normalized_configurations[$destination] = $configuration;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ class MigrationPluginManager extends DefaultPluginManager implements MigrationPl
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaults = array(
|
||||
protected $defaults = [
|
||||
'class' => '\Drupal\migrate\Plugin\Migration',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The interface the plugins should implement.
|
||||
|
@ -55,7 +55,7 @@ class MigrationPluginManager extends DefaultPluginManager implements MigrationPl
|
|||
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager) {
|
||||
$this->factory = new ContainerFactory($this, $this->pluginInterface);
|
||||
$this->alterInfo('migration_plugins');
|
||||
$this->setCacheBackend($cache_backend, 'migration_plugins', array('migration_plugins'));
|
||||
$this->setCacheBackend($cache_backend, 'migration_plugins', ['migration_plugins']);
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class MigrationPluginManager extends DefaultPluginManager implements MigrationPl
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array()) {
|
||||
public function createInstance($plugin_id, array $configuration = []) {
|
||||
$instances = $this->createInstances([$plugin_id], [$plugin_id => $configuration]);
|
||||
return reset($instances);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class MigrationPluginManager extends DefaultPluginManager implements MigrationPl
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstances($migration_id, array $configuration = array()) {
|
||||
public function createInstances($migration_id, array $configuration = []) {
|
||||
if (empty($migration_id)) {
|
||||
$migration_id = array_keys($this->getDefinitions());
|
||||
}
|
||||
|
@ -222,9 +222,9 @@ class MigrationPluginManager extends DefaultPluginManager implements MigrationPl
|
|||
* The dynamic ID mapping.
|
||||
*/
|
||||
protected function addDependency(array &$graph, $id, $dependency, $dynamic_ids) {
|
||||
$dependencies = isset($dynamic_ids[$dependency]) ? $dynamic_ids[$dependency] : array($dependency);
|
||||
$dependencies = isset($dynamic_ids[$dependency]) ? $dynamic_ids[$dependency] : [$dependency];
|
||||
if (!isset($graph[$id]['edges'])) {
|
||||
$graph[$id]['edges'] = array();
|
||||
$graph[$id]['edges'] = [];
|
||||
}
|
||||
$graph[$id]['edges'] += array_combine($dependencies, $dependencies);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ interface MigrationPluginManagerInterface extends PluginManagerInterface {
|
|||
* @throws \Drupal\Component\Plugin\Exception\PluginException
|
||||
* If an instance cannot be created, such as if the ID is invalid.
|
||||
*/
|
||||
public function createInstances($id, array $configuration = array());
|
||||
public function createInstances($id, array $configuration = []);
|
||||
|
||||
/**
|
||||
* Creates a stub migration plugin from a definition array.
|
||||
|
|
|
@ -15,8 +15,8 @@ abstract class ComponentEntityDisplayBase extends DestinationBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
$values = array();
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$values = [];
|
||||
// array_intersect_key() won't work because the order is important because
|
||||
// this is also the return value.
|
||||
foreach (array_keys($this->getIds()) as $id) {
|
||||
|
@ -24,7 +24,7 @@ abstract class ComponentEntityDisplayBase extends DestinationBase {
|
|||
}
|
||||
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
|
||||
if (!$row->getDestinationProperty('hidden')) {
|
||||
$entity->setComponent($values['field_name'], $row->getDestinationProperty('options') ?: array());
|
||||
$entity->setComponent($values['field_name'], $row->getDestinationProperty('options') ?: []);
|
||||
}
|
||||
else {
|
||||
$entity->removeComponent($values['field_name']);
|
||||
|
|
|
@ -83,7 +83,7 @@ class Config extends DestinationBase implements ContainerFactoryPluginInterface,
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
if ($this->isTranslationDestination()) {
|
||||
$this->config = $this->language_manager->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $this->config->getName());
|
||||
}
|
||||
|
|
|
@ -3,10 +3,16 @@
|
|||
namespace Drupal\migrate\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\language\ConfigurableLanguageManager;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class for importing configuration entities.
|
||||
|
@ -20,10 +26,67 @@ use Drupal\migrate\Row;
|
|||
*/
|
||||
class EntityConfigBase extends Entity {
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The configuration factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface;
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* Construct a new entity.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles);
|
||||
$this->languageManager = $language_manager;
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
if ($row->isStub()) {
|
||||
throw new MigrateException('Config entities can not be stubbed.');
|
||||
}
|
||||
|
@ -39,17 +102,37 @@ class EntityConfigBase extends Entity {
|
|||
}
|
||||
}
|
||||
$entity = $this->getEntity($row, $old_destination_id_values);
|
||||
$entity->save();
|
||||
// Translations are already saved in updateEntity by configuration override.
|
||||
if (!$this->isTranslationDestination()) {
|
||||
$entity->save();
|
||||
}
|
||||
if (count($ids) > 1) {
|
||||
// This can only be a config entity, content entities have their ID key
|
||||
// and that's it.
|
||||
$return = array();
|
||||
$return = [];
|
||||
foreach ($id_keys as $id_key) {
|
||||
$return[] = $entity->get($id_key);
|
||||
if (($this->isTranslationDestination()) && ($id_key == 'langcode')) {
|
||||
// Config entities do not have a language property, get the language
|
||||
// code from the destination.
|
||||
$return[] = $row->getDestinationProperty($id_key);
|
||||
}
|
||||
else {
|
||||
$return[] = $entity->get($id_key);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
return array($entity->id());
|
||||
return [$entity->id()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this destination is for translations.
|
||||
*
|
||||
* @return bool
|
||||
* Whether this destination is for translations.
|
||||
*/
|
||||
protected function isTranslationDestination() {
|
||||
return !empty($this->configuration['translations']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,6 +141,9 @@ class EntityConfigBase extends Entity {
|
|||
public function getIds() {
|
||||
$id_key = $this->getKey('id');
|
||||
$ids[$id_key]['type'] = 'string';
|
||||
if ($this->isTranslationDestination()) {
|
||||
$ids['langcode']['type'] = 'string';
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
@ -70,11 +156,28 @@ class EntityConfigBase extends Entity {
|
|||
* The row object to update from.
|
||||
*/
|
||||
protected function updateEntity(EntityInterface $entity, Row $row) {
|
||||
foreach ($row->getRawDestination() as $property => $value) {
|
||||
$this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value);
|
||||
// This is a translation if the language in the active config does not
|
||||
// match the language of this row.
|
||||
$translation = FALSE;
|
||||
if ($row->hasDestinationProperty('langcode') && $this->languageManager instanceof ConfigurableLanguageManager) {
|
||||
$config = $entity->getConfigDependencyName();
|
||||
$langcode = $this->configFactory->get('langcode');
|
||||
if ($langcode != $row->getDestinationProperty('langcode')) {
|
||||
$translation = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setRollbackAction($row->getIdMap());
|
||||
if ($translation) {
|
||||
$config_override = $this->languageManager->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $config);
|
||||
$config_override->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $row->getDestinationProperty('property')), $row->getDestinationProperty('translation'));
|
||||
$config_override->save();
|
||||
}
|
||||
else {
|
||||
foreach ($row->getRawDestination() as $property => $value) {
|
||||
$this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value);
|
||||
}
|
||||
$this->setRollbackAction($row->getIdMap());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,11 +214,41 @@ class EntityConfigBase extends Entity {
|
|||
* The generated entity ID.
|
||||
*/
|
||||
protected function generateId(Row $row, array $ids) {
|
||||
$id_values = array();
|
||||
$id_values = [];
|
||||
foreach ($ids as $id) {
|
||||
if ($this->isTranslationDestination() && $id == 'langcode') {
|
||||
continue;
|
||||
}
|
||||
$id_values[] = $row->getDestinationProperty($id);
|
||||
}
|
||||
return implode('.', $id_values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rollback(array $destination_identifier) {
|
||||
if ($this->isTranslationDestination()) {
|
||||
// The entity id does not include the langcode.
|
||||
$id_values = [];
|
||||
foreach ($destination_identifier as $key => $value) {
|
||||
if ($this->isTranslationDestination() && $key == 'langcode') {
|
||||
continue;
|
||||
}
|
||||
$id_values[] = $value;
|
||||
}
|
||||
$entity_id = implode('.', $id_values);
|
||||
$language = $destination_identifier['langcode'];
|
||||
|
||||
$config = $this->storage->load($entity_id)->getConfigDependencyName();
|
||||
$config_override = $this->languageManager->getLanguageConfigOverride($language, $config);
|
||||
// Rollback the translation.
|
||||
$config_override->delete();
|
||||
}
|
||||
else {
|
||||
$destination_identifier = implode('.', $destination_identifier);
|
||||
parent::rollback([$destination_identifier]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ class EntityContentBase extends Entity {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
|
||||
$entity = $this->getEntity($row, $old_destination_id_values);
|
||||
if (!$entity) {
|
||||
|
@ -105,9 +105,9 @@ class EntityContentBase extends Entity {
|
|||
* @return array
|
||||
* An array containing the entity ID.
|
||||
*/
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
|
||||
$entity->save();
|
||||
return array($entity->id());
|
||||
return [$entity->id()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,15 +18,10 @@ class EntityFieldInstance extends EntityConfigBase {
|
|||
$ids['entity_type']['type'] = 'string';
|
||||
$ids['bundle']['type'] = 'string';
|
||||
$ids['field_name']['type'] = 'string';
|
||||
if ($this->isTranslationDestination()) {
|
||||
$ids['langcode']['type'] = 'string';
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rollback(array $destination_identifier) {
|
||||
$destination_identifier = implode('.', $destination_identifier);
|
||||
parent::rollback(array($destination_identifier));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class EntityFieldStorageConfig extends EntityConfigBase {
|
|||
*/
|
||||
public function rollback(array $destination_identifier) {
|
||||
$destination_identifier = implode('.', $destination_identifier);
|
||||
parent::rollback(array($destination_identifier));
|
||||
parent::rollback([$destination_identifier]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,9 +63,9 @@ class EntityRevision extends EntityContentBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
|
||||
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
|
||||
$entity->save();
|
||||
return array($entity->getRevisionId());
|
||||
return [$entity->getRevisionId()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ class EntityViewMode extends EntityConfigBase {
|
|||
*/
|
||||
public function rollback(array $destination_identifier) {
|
||||
$destination_identifier = implode('.', $destination_identifier);
|
||||
parent::rollback(array($destination_identifier));
|
||||
parent::rollback([$destination_identifier]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,20 +19,20 @@ class NullDestination extends DestinationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields(MigrationInterface $migration = NULL) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,14 +115,14 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sourceIds = array();
|
||||
protected $sourceIds = [];
|
||||
|
||||
/**
|
||||
* The destination identifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $destinationIds = array();
|
||||
protected $destinationIds = [];
|
||||
|
||||
/**
|
||||
* The current row.
|
||||
|
@ -136,7 +136,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $currentKey = array();
|
||||
protected $currentKey = [];
|
||||
|
||||
/**
|
||||
* Constructs an SQL object.
|
||||
|
@ -208,7 +208,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
protected function sourceIdFields() {
|
||||
if (!isset($this->sourceIdFields)) {
|
||||
// Build the source and destination identifier maps.
|
||||
$this->sourceIdFields = array();
|
||||
$this->sourceIdFields = [];
|
||||
$count = 1;
|
||||
foreach ($this->migration->getSourcePlugin()->getIds() as $field => $schema) {
|
||||
$this->sourceIdFields[$field] = 'sourceid' . $count++;
|
||||
|
@ -225,7 +225,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
protected function destinationIdFields() {
|
||||
if (!isset($this->destinationIdFields)) {
|
||||
$this->destinationIdFields = array();
|
||||
$this->destinationIdFields = [];
|
||||
$count = 1;
|
||||
foreach ($this->migration->getDestinationPlugin()->getIds() as $field => $schema) {
|
||||
$this->destinationIdFields[$field] = 'destid' . $count++;
|
||||
|
@ -312,19 +312,21 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
// Generate appropriate schema info for the map and message tables,
|
||||
// and map from the source field names to the map/msg field names.
|
||||
$count = 1;
|
||||
$source_id_schema = array();
|
||||
$source_id_schema = [];
|
||||
$indexes = [];
|
||||
foreach ($this->migration->getSourcePlugin()->getIds() as $id_definition) {
|
||||
$mapkey = 'sourceid' . $count++;
|
||||
$indexes['source'][] = $mapkey;
|
||||
$source_id_schema[$mapkey] = $this->getFieldSchema($id_definition);
|
||||
$source_id_schema[$mapkey]['not null'] = TRUE;
|
||||
}
|
||||
|
||||
$source_ids_hash[static::SOURCE_IDS_HASH] = array(
|
||||
$source_ids_hash[static::SOURCE_IDS_HASH] = [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
);
|
||||
];
|
||||
$fields = $source_ids_hash + $source_id_schema;
|
||||
|
||||
// Add destination identifiers to map table.
|
||||
|
@ -336,68 +338,69 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
$fields[$mapkey] = $this->getFieldSchema($id_definition);
|
||||
$fields[$mapkey]['not null'] = FALSE;
|
||||
}
|
||||
$fields['source_row_status'] = array(
|
||||
$fields['source_row_status'] = [
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
'description' => 'Indicates current status of the source row',
|
||||
);
|
||||
$fields['rollback_action'] = array(
|
||||
];
|
||||
$fields['rollback_action'] = [
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
'description' => 'Flag indicating what to do for this item on rollback',
|
||||
);
|
||||
$fields['last_imported'] = array(
|
||||
];
|
||||
$fields['last_imported'] = [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'UNIX timestamp of the last time this row was imported',
|
||||
);
|
||||
$fields['hash'] = array(
|
||||
];
|
||||
$fields['hash'] = [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Hash of source row data, for detecting changes',
|
||||
);
|
||||
$schema = array(
|
||||
];
|
||||
$schema = [
|
||||
'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
|
||||
'fields' => $fields,
|
||||
'primary key' => array(static::SOURCE_IDS_HASH),
|
||||
);
|
||||
'primary key' => [static::SOURCE_IDS_HASH],
|
||||
'indexes' => $indexes,
|
||||
];
|
||||
$this->getDatabase()->schema()->createTable($this->mapTableName, $schema);
|
||||
|
||||
// Now do the message table.
|
||||
if (!$this->getDatabase()->schema()->tableExists($this->messageTableName())) {
|
||||
$fields = array();
|
||||
$fields['msgid'] = array(
|
||||
$fields = [];
|
||||
$fields['msgid'] = [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
);
|
||||
];
|
||||
$fields += $source_ids_hash;
|
||||
|
||||
$fields['level'] = array(
|
||||
$fields['level'] = [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
);
|
||||
$fields['message'] = array(
|
||||
];
|
||||
$fields['message'] = [
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$schema = array(
|
||||
];
|
||||
$schema = [
|
||||
'description' => 'Messages generated during a migration process',
|
||||
'fields' => $fields,
|
||||
'primary key' => array('msgid'),
|
||||
);
|
||||
'primary key' => ['msgid'],
|
||||
];
|
||||
$this->getDatabase()->schema()->createTable($this->messageTableName(), $schema);
|
||||
}
|
||||
}
|
||||
|
@ -406,33 +409,33 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName,
|
||||
'rollback_action')) {
|
||||
$this->getDatabase()->schema()->addField($this->mapTableName, 'rollback_action',
|
||||
array(
|
||||
[
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Flag indicating what to do for this item on rollback',
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, 'hash')) {
|
||||
$this->getDatabase()->schema()->addField($this->mapTableName, 'hash',
|
||||
array(
|
||||
[
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Hash of source row data, for detecting changes',
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, static::SOURCE_IDS_HASH)) {
|
||||
$this->getDatabase()->schema()->addField($this->mapTableName, static::SOURCE_IDS_HASH, array(
|
||||
$this->getDatabase()->schema()->addField($this->mapTableName, static::SOURCE_IDS_HASH, [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -482,7 +485,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function getRowBySource(array $source_id_values) {
|
||||
$query = $this->getDatabase()->select($this->mapTableName(), 'map')
|
||||
->fields('map');
|
||||
->fields('map');
|
||||
$query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
|
||||
$result = $query->execute();
|
||||
return $result->fetchAssoc();
|
||||
|
@ -493,7 +496,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function getRowByDestination(array $destination_id_values) {
|
||||
$query = $this->getDatabase()->select($this->mapTableName(), 'map')
|
||||
->fields('map');
|
||||
->fields('map');
|
||||
foreach ($this->destinationIdFields() as $field_name => $destination_id) {
|
||||
$query->condition("map.$destination_id", $destination_id_values[$field_name], '=');
|
||||
}
|
||||
|
@ -505,12 +508,12 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRowsNeedingUpdate($count) {
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
$result = $this->getDatabase()->select($this->mapTableName(), 'map')
|
||||
->fields('map')
|
||||
->condition('source_row_status', MigrateIdMapInterface::STATUS_NEEDS_UPDATE)
|
||||
->range(0, $count)
|
||||
->execute();
|
||||
->fields('map')
|
||||
->condition('source_row_status', MigrateIdMapInterface::STATUS_NEEDS_UPDATE)
|
||||
->range(0, $count)
|
||||
->execute();
|
||||
foreach ($result as $row) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
@ -538,7 +541,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function lookupDestinationId(array $source_id_values) {
|
||||
$results = $this->lookupDestinationIds($source_id_values);
|
||||
return $results ? reset($results) : array();
|
||||
return $results ? reset($results) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,7 +549,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function lookupDestinationIds(array $source_id_values) {
|
||||
if (empty($source_id_values)) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
// Canonicalize the keys into a hash of DB-field => value.
|
||||
|
@ -602,7 +605,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
if (!isset($source_id_values[$field_name])) {
|
||||
$this->message->display($this->t(
|
||||
'Did not save to map table due to NULL value for key field @field',
|
||||
array('@field' => $field_name)), 'error');
|
||||
['@field' => $field_name]), 'error');
|
||||
return;
|
||||
}
|
||||
$fields[$key_name] = $source_id_values[$field_name];
|
||||
|
@ -612,11 +615,11 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
return;
|
||||
}
|
||||
|
||||
$fields += array(
|
||||
$fields += [
|
||||
'source_row_status' => (int) $source_row_status,
|
||||
'rollback_action' => (int) $rollback_action,
|
||||
'hash' => $row->getHash(),
|
||||
);
|
||||
];
|
||||
$count = 0;
|
||||
foreach ($destination_id_values as $dest_id) {
|
||||
$fields['destid' . ++$count] = $dest_id;
|
||||
|
@ -680,7 +683,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function prepareUpdate() {
|
||||
$this->getDatabase()->update($this->mapTableName())
|
||||
->fields(array('source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE))
|
||||
->fields(['source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
@ -699,7 +702,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function importedCount() {
|
||||
return $this->getDatabase()->select($this->mapTableName())
|
||||
->condition('source_row_status', array(MigrateIdMapInterface::STATUS_IMPORTED, MigrateIdMapInterface::STATUS_NEEDS_UPDATE), 'IN')
|
||||
->condition('source_row_status', [MigrateIdMapInterface::STATUS_IMPORTED, MigrateIdMapInterface::STATUS_NEEDS_UPDATE], 'IN')
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
@ -794,7 +797,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
$query = $this->getDatabase()
|
||||
->update($this->mapTableName())
|
||||
->fields(array('source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE));
|
||||
->fields(['source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE]);
|
||||
|
||||
foreach ($this->sourceIdFields() as $field_name => $source_id) {
|
||||
$query->condition($source_id, $source_id_values[$field_name]);
|
||||
|
@ -818,13 +821,13 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of Iterator::rewind().
|
||||
* Implementation of \Iterator::rewind().
|
||||
*
|
||||
* This is called before beginning a foreach loop.
|
||||
*/
|
||||
public function rewind() {
|
||||
$this->currentRow = NULL;
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
foreach ($this->sourceIdFields() as $field) {
|
||||
$fields[] = $field;
|
||||
}
|
||||
|
@ -839,7 +842,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of Iterator::current().
|
||||
* Implementation of \Iterator::current().
|
||||
*
|
||||
* This is called when entering a loop iteration, returning the current row.
|
||||
*/
|
||||
|
@ -848,7 +851,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of Iterator::key().
|
||||
* Implementation of \Iterator::key().
|
||||
*
|
||||
* This is called when entering a loop iteration, returning the key of the
|
||||
* current row. It must be a scalar - we will serialize to fulfill the
|
||||
|
@ -863,7 +866,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function currentDestination() {
|
||||
if ($this->valid()) {
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->destinationIdFields() as $destination_field_name => $idmap_field_name) {
|
||||
if (!is_null($this->currentRow[$idmap_field_name])) {
|
||||
$result[$destination_field_name] = $this->currentRow[$idmap_field_name];
|
||||
|
@ -881,7 +884,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
*/
|
||||
public function currentSource() {
|
||||
if ($this->valid()) {
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->sourceIdFields() as $field_name => $source_id) {
|
||||
$result[$field_name] = $this->currentKey[$source_id];
|
||||
}
|
||||
|
@ -893,14 +896,14 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of Iterator::next().
|
||||
* Implementation of \Iterator::next().
|
||||
*
|
||||
* This is called at the bottom of the loop implicitly, as well as explicitly
|
||||
* from rewind().
|
||||
*/
|
||||
public function next() {
|
||||
$this->currentRow = $this->result->fetchAssoc();
|
||||
$this->currentKey = array();
|
||||
$this->currentKey = [];
|
||||
if ($this->currentRow) {
|
||||
foreach ($this->sourceIdFields() as $map_field) {
|
||||
$this->currentKey[$map_field] = $this->currentRow[$map_field];
|
||||
|
@ -911,7 +914,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of Iterator::valid().
|
||||
* Implementation of \Iterator::valid().
|
||||
*
|
||||
* This is called at the top of the loop, returning TRUE to process the loop
|
||||
* and FALSE to terminate it.
|
||||
|
|
|
@ -7,15 +7,38 @@ use Drupal\migrate\ProcessPluginBase;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin allows source value to be passed to a callback.
|
||||
* Passes the source value to a callback.
|
||||
*
|
||||
* The current value is passed to a callable that returns the processed value.
|
||||
* This plugin allows simple processing of the value, such as strtolower(). The
|
||||
* callable takes the value as the single mandatory argument. No additional
|
||||
* arguments can be passed to the callback as this would make the migration YAML
|
||||
* file too complex.
|
||||
* The callback process plugin allows simple processing of the value, such as
|
||||
* strtolower(). The callable takes the source value as the single mandatory
|
||||
* argument. No additional arguments can be passed to the callback.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2181783 Online handbook documentation for callback process plugin @endlink
|
||||
* Available configuration keys:
|
||||
* - callable: The name of the callable method.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* destination_field:
|
||||
* plugin: callback
|
||||
* callable: strtolower
|
||||
* source: source_field
|
||||
* @endcode
|
||||
*
|
||||
* An example where the callable is a static method in a class:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* destination_field:
|
||||
* plugin: callback
|
||||
* callable:
|
||||
* - '\Drupal\Component\Utility\Unicode'
|
||||
* - strtolower
|
||||
* source: source_field
|
||||
* @endcode
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "callback"
|
||||
|
|
|
@ -8,9 +8,48 @@ use Drupal\migrate\ProcessPluginBase;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Concatenates the strings in the current value.
|
||||
* Concatenates a set of strings.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2345927 Online handbook documentation for concat process plugin @endlink
|
||||
* The concat plugin is used to concatenate strings. For example, imploding a
|
||||
* set of strings into a single string.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - delimiter: (optional) A delimiter, or glue string, to insert between the
|
||||
* strings.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_text_field:
|
||||
* plugin: concat
|
||||
* source:
|
||||
* - foo
|
||||
* - bar
|
||||
* @endcode
|
||||
*
|
||||
* This will set new_text_field to the concatenation of the 'foo' and 'bar'
|
||||
* source values. For example, if the 'foo' property is "wambooli" and the 'bar'
|
||||
* property is "pastafazoul", new_text_field will be "wamboolipastafazoul".
|
||||
*
|
||||
* You can also specify a delimiter.
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_text_field:
|
||||
* plugin: concat
|
||||
* source:
|
||||
* - foo
|
||||
* - bar
|
||||
* delimiter: /
|
||||
* @endcode
|
||||
*
|
||||
* This will set new_text_field to the concatenation of the 'foo' source value,
|
||||
* the delimiter and the 'bar' source value. For example, using the values above
|
||||
* and "/" as the delimiter, if the 'foo' property is "wambooli" and the 'bar'
|
||||
* property is "pastafazoul", new_text_field will be "wambooli/pastafazoul".
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "concat",
|
||||
|
@ -21,8 +60,6 @@ class Concat extends ProcessPluginBase {
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Concatenates the strings in the current value.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (is_array($value)) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\migrate\Plugin\migrate\process;
|
||||
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -22,11 +22,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity query factory.
|
||||
* The entity storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactoryInterface
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
protected $entityStorage;
|
||||
|
||||
/**
|
||||
* The current migration.
|
||||
|
@ -38,10 +38,10 @@ class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, QueryFactory $entity_query_factory) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->migration = $migration;
|
||||
$this->entityQueryFactory = $entity_query_factory;
|
||||
$this->entityStorage = $entity_type_manager->getStorage($this->configuration['entity_type']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface
|
|||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('entity.query')
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,7 @@ class DedupeEntity extends DedupeBase implements ContainerFactoryPluginInterface
|
|||
protected function exists($value) {
|
||||
// Plugins are cached so for every run we need a new query object.
|
||||
$query = $this
|
||||
->entityQueryFactory
|
||||
->get($this->configuration['entity_type'], 'AND')
|
||||
->entityStorage->getQuery()
|
||||
->condition($this->configuration['field'], $value);
|
||||
if (!empty($this->configuration['migrated'])) {
|
||||
// Check if each entity is in the ID map.
|
||||
|
|
|
@ -7,9 +7,38 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin sets missing values on the destination.
|
||||
* Returns a given default value if the input is empty.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2135313 Online handbook documentation for default_value process plugin @endlink
|
||||
* The default_value process plugin provides the ability to set a fixed default
|
||||
* value. The plugin returns a default value if the input value is considered
|
||||
* empty (NULL, FALSE, 0, '0', an empty string, or an empty array). The strict
|
||||
* configuration key can be used to set the default only when the incoming
|
||||
* value is NULL.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - default_value: The fixed default value to apply.
|
||||
* - strict: (optional) Use strict value checking. Defaults to false.
|
||||
* - FALSE: Apply default when input value is empty().
|
||||
* - TRUE: Apply default when input value is NULL.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* uid:
|
||||
* -
|
||||
* plugin: migration
|
||||
* migration: users
|
||||
* source: author
|
||||
* -
|
||||
* plugin: default_value
|
||||
* default_value: 44
|
||||
* @endcode
|
||||
*
|
||||
* This will look up the source value of author in the users migration and if
|
||||
* not found, set the destination property uid to 44.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "default_value"
|
||||
|
|
|
@ -12,7 +12,42 @@ use GuzzleHttp\Client;
|
|||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Downloads a file from a remote location into the local file system.
|
||||
* Downloads a file from a HTTP(S) remote location into the local file system.
|
||||
*
|
||||
* The source value is an array of two values:
|
||||
* - source URL, e.g. 'http://www.example.com/img/foo.img'
|
||||
* - destination URI, e.g. 'public://images/foo.img'
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - rename: (optional) If set, a unique destination URI is generated. If not
|
||||
* set, the destination URI will be overwritten if it exists.
|
||||
* - guzzle_options: (optional)
|
||||
* @link http://docs.guzzlephp.org/en/latest/request-options.html Array of request options for Guzzle. @endlink
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* plugin: download
|
||||
* source:
|
||||
* - source_url
|
||||
* - destination_uri
|
||||
* @endcode
|
||||
*
|
||||
* This will download source_url to destination_uri.
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* plugin: download
|
||||
* source:
|
||||
* - source_url
|
||||
* - destination_uri
|
||||
* rename: true
|
||||
* @endcode
|
||||
*
|
||||
* This will download source_url to destination_uri and ensure that the
|
||||
* destination URI is unique. If a file with the same name exists at the
|
||||
* destination, a numbered suffix like '_0' will be appended to make it unique.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "download"
|
||||
|
|
|
@ -8,9 +8,84 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin explodes a delimited string into an array of values.
|
||||
* Splits the source string into an array of strings, using a delimiter.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2674504 Online handbook documentation for explode process plugin @endlink
|
||||
* This plugin creates an array of strings by splitting the source parameter on
|
||||
* boundaries formed by the delimiter.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - source: The source string.
|
||||
* - limit: (optional)
|
||||
* - If limit is set and positive, the returned array will contain a maximum
|
||||
* of limit elements with the last element containing the rest of string.
|
||||
* - If limit is set and negative, all components except the last -limit are
|
||||
* returned.
|
||||
* - If the limit parameter is zero, then this is treated as 1.
|
||||
* - delimiter: The boundary string.
|
||||
* - strict: (optional) When this boolean is TRUE, the source should be strictly
|
||||
* a string. If FALSE is passed, the source value is casted to a string before
|
||||
* being split. Also, in this case, the values casting to empty strings are
|
||||
* converted to empty arrays, instead of an array with a single empty string
|
||||
* item ['']. Defaults to TRUE.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: explode
|
||||
* source: foo
|
||||
* delimiter: /
|
||||
* @endcode
|
||||
*
|
||||
* If foo is "node/1", then bar will be ['node', '1']. The PHP equivalent of
|
||||
* this would be:
|
||||
*
|
||||
* @code
|
||||
* $bar = explode('/', $foo);
|
||||
* @endcode
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: explode
|
||||
* source: foo
|
||||
* limit: 1
|
||||
* delimiter: /
|
||||
* @endcode
|
||||
*
|
||||
* If foo is "node/1/edit", then bar will be ['node', '1/edit']. The PHP
|
||||
* equivalent of this would be:
|
||||
*
|
||||
* @code
|
||||
* $bar = explode('/', $foo, 1);
|
||||
* @endcode
|
||||
*
|
||||
* If the 'strict' configuration is set to FALSE, the input value is casted to a
|
||||
* string before being spilt:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: explode
|
||||
* source: foo
|
||||
* delimiter: /
|
||||
* strict: false
|
||||
* @endcode
|
||||
*
|
||||
* If foo is 123 (as integer), then bar will be ['123']. If foo is TRUE, then
|
||||
* bar will be ['1']. The PHP equivalent of this would be:
|
||||
*
|
||||
* @code
|
||||
* $bar = explode('/', (string) 123);
|
||||
* $bar = explode('/', (string) TRUE);
|
||||
* @endcode
|
||||
*
|
||||
* If the 'strict' configuration is set to FALSE, the source value casting to
|
||||
* an empty string are converted to an empty array. For example, with the last
|
||||
* configuration, if foo is '', NULL or FALSE, then bar will be [].
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "explode"
|
||||
|
@ -22,18 +97,29 @@ class Explode extends ProcessPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (is_string($value)) {
|
||||
if (!empty($this->configuration['delimiter'])) {
|
||||
$limit = isset($this->configuration['limit']) ? $this->configuration['limit'] : PHP_INT_MAX;
|
||||
return explode($this->configuration['delimiter'], $value, $limit);
|
||||
}
|
||||
else {
|
||||
throw new MigrateException('delimiter is empty');
|
||||
}
|
||||
if (empty($this->configuration['delimiter'])) {
|
||||
throw new MigrateException('delimiter is empty');
|
||||
}
|
||||
else {
|
||||
|
||||
$strict = array_key_exists('strict', $this->configuration) ? $this->configuration['strict'] : TRUE;
|
||||
if ($strict && !is_string($value)) {
|
||||
throw new MigrateException(sprintf('%s is not a string', var_export($value, TRUE)));
|
||||
}
|
||||
elseif (!$strict) {
|
||||
// Check if the incoming value can cast to a string.
|
||||
$original = $value;
|
||||
if (!is_string($original) && ($original != ($value = @strval($value)))) {
|
||||
throw new MigrateException(sprintf('%s cannot be casted to a string', var_export($original, TRUE)));
|
||||
}
|
||||
// Empty strings should be exploded to empty arrays.
|
||||
if ($value === '') {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
$limit = isset($this->configuration['limit']) ? $this->configuration['limit'] : PHP_INT_MAX;
|
||||
|
||||
return explode($this->configuration['delimiter'], $value, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,52 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin extracts a value from an array.
|
||||
* Extracts a value from an array.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2152731 Online handbook documentation for extract process plugin @endlink
|
||||
* The extract process plugin is used to pull data from an input array, which
|
||||
* may have multiple levels. One use case is extracting data from field arrays
|
||||
* in previous versions of Drupal. For instance, in Drupal 7, a field array
|
||||
* would be indexed first by language, then by delta, then finally a key such as
|
||||
* 'value'.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - source: The input value - must be an array.
|
||||
* - index: The array of keys to access the value.
|
||||
* - default: (optional) A default value to assign to the destination if the
|
||||
* key does not exist.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_text_field:
|
||||
* plugin: extract
|
||||
* source: some_text_field
|
||||
* index:
|
||||
* - und
|
||||
* - 0
|
||||
* - value
|
||||
* @endcode
|
||||
*
|
||||
* The PHP equivalent of this would be:
|
||||
* @code
|
||||
* $destination['new_text_field'] = $source['some_text_field']['und'][0]['value'];
|
||||
* @endcode
|
||||
* If a default value is specified, it will be returned if the index does not
|
||||
* exist in the input array.
|
||||
*
|
||||
* @code
|
||||
* plugin: extract
|
||||
* source: some_text_field
|
||||
* default: 'Default title'
|
||||
* index:
|
||||
* - title
|
||||
* @endcode
|
||||
*
|
||||
* If $source['some_text_field']['title'] doesn't exist, then the plugin will
|
||||
* return "Default title".
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "extract",
|
||||
|
|
|
@ -14,7 +14,36 @@ use Drupal\migrate\Row;
|
|||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Copy a file from one place into another.
|
||||
* Copies or moves a local file from one place into another.
|
||||
*
|
||||
* The file can be moved, reused, or set to be automatically renamed if a
|
||||
* duplicate exists.
|
||||
*
|
||||
* The source value is an array of two values:
|
||||
* - source: The source path or URI, e.g. '/path/to/foo.txt' or
|
||||
* 'public://bar.txt'.
|
||||
* - destination: The destination path or URI, e.g. '/path/to/bar.txt' or
|
||||
* 'public://foo.txt'.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - move: (optional) Boolean, if TRUE, move the file, otherwise copy the file.
|
||||
* Defaults to FALSE.
|
||||
* - rename: (optional) Boolean, if TRUE, rename the file by appending a number
|
||||
* until the name is unique. Defaults to FALSE.
|
||||
* - reuse: (optional) Boolean, if TRUE, reuse the current file in its existing
|
||||
* location rather than move/copy/rename the file. Defaults to FALSE.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* path_to_file:
|
||||
* plugin: file_copy
|
||||
* source: /path/to/file.png
|
||||
* destination: /new/path/to/file.png
|
||||
* @endcode
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "file_copy"
|
||||
|
@ -60,11 +89,11 @@ class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterf
|
|||
* An instance of the download plugin for handling remote URIs.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, StreamWrapperManagerInterface $stream_wrappers, FileSystemInterface $file_system, MigrateProcessInterface $download_plugin) {
|
||||
$configuration += array(
|
||||
$configuration += [
|
||||
'move' => FALSE,
|
||||
'rename' => FALSE,
|
||||
'reuse' => FALSE,
|
||||
);
|
||||
];
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->streamWrapperManager = $stream_wrappers;
|
||||
$this->fileSystem = $file_system;
|
||||
|
|
|
@ -6,13 +6,34 @@ use Drupal\migrate\ProcessPluginBase;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin flattens the current value.
|
||||
* Flattens the source value.
|
||||
*
|
||||
* During some types of processing (e.g. user permission splitting), what was
|
||||
* once a single value gets transformed into multiple values. This plugin will
|
||||
* flatten them back down to single values again.
|
||||
* The flatten process plugin converts a nested array into a flat array. For
|
||||
* example [[1, 2, [3, 4]], [5], 6] becomes [1, 2, 3, 4, 5, 6]. During some
|
||||
* types of processing (e.g. user permission splitting), what was once a
|
||||
* one-dimensional array gets transformed into a multidimensional array. This
|
||||
* plugin will flatten them back down to one-dimensional arrays again.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2154215 Online handbook documentation for flatten process plugin @endlink
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* tags:
|
||||
* -
|
||||
* plugin: default_value
|
||||
* source: foo
|
||||
* default_value: [bar, [qux, quux]]
|
||||
* -
|
||||
* plugin: flatten
|
||||
* @endcode
|
||||
*
|
||||
* In this example, the default_value process returns [bar, [qux, quux]] (given
|
||||
* a NULL value of foo). At this point, Migrate would try to import two
|
||||
* items: bar and [qux, quux]. The latter is not a valid one and won't be
|
||||
* imported. We need to pass the values through the flatten processor to obtain
|
||||
* a three items array [bar, qux, quux], suitable for import.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "flatten",
|
||||
|
@ -24,7 +45,7 @@ class Flatten extends ProcessPluginBase {
|
|||
/**
|
||||
* Flatten nested array values to single array values.
|
||||
*
|
||||
* For example, array(array(1, 2, array(3, 4))) becomes array(1, 2, 3, 4).
|
||||
* For example, [[1, 2, [3, 4]]] becomes [1, 2, 3, 4].
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($value)), FALSE);
|
||||
|
|
|
@ -7,9 +7,87 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This plugin copies from the source to the destination.
|
||||
* Gets the source value.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2135307 Online handbook documentation for get process plugin @endlink
|
||||
* Available configuration keys:
|
||||
* - source: Source property.
|
||||
*
|
||||
* The get plugin returns the value of the property given by the "source"
|
||||
* configuration key.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: get
|
||||
* source: foo
|
||||
* @endcode
|
||||
*
|
||||
* This copies the source value of foo to the destination property "bar".
|
||||
*
|
||||
* Since get is the default process plugin, it can be shorthanded like this:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar: foo
|
||||
* @endcode
|
||||
*
|
||||
* get also supports a list of source properties.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: get
|
||||
* source:
|
||||
* - foo1
|
||||
* - foo2
|
||||
* @endcode
|
||||
*
|
||||
* This copies the array of source values [foo1, foo2] to the destination
|
||||
* property "bar".
|
||||
*
|
||||
* If the list of source properties contains an empty element then the current
|
||||
* value will be used. This makes it impossible to reach a source property with
|
||||
* an empty string as its name.
|
||||
*
|
||||
* get also supports copying destination values. These are indicated by a
|
||||
* starting @ sign. Values using @ must be wrapped in quotes.
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* foo:
|
||||
* plugin: machine_name
|
||||
* source: baz
|
||||
* bar:
|
||||
* plugin: get
|
||||
* source: '@foo'
|
||||
* @endcode
|
||||
*
|
||||
* This will simply copy the destination value of foo to the destination
|
||||
* property bar. foo configuration is included for illustration purposes.
|
||||
*
|
||||
* Because of this, if your source or destination property actually starts with
|
||||
* a @ you need to double those starting characters up. This means that if a
|
||||
* destination property happens to start with a @ and you want to refer it,
|
||||
* you'll need to start with three @ characters -- one to indicate the
|
||||
* destination and two for escaping the real @.
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* @foo:
|
||||
* plugin: machine_name
|
||||
* source: baz
|
||||
* bar:
|
||||
* plugin: get
|
||||
* source: '@@@foo'
|
||||
* @endcode
|
||||
*
|
||||
* This should occur extremely rarely.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "get"
|
||||
|
@ -29,8 +107,8 @@ class Get extends ProcessPluginBase {
|
|||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$source = $this->configuration['source'];
|
||||
$properties = is_string($source) ? array($source) : $source;
|
||||
$return = array();
|
||||
$properties = is_string($source) ? [$source] : $source;
|
||||
$return = [];
|
||||
foreach ($properties as $property) {
|
||||
if ($property || (string) $property === '0') {
|
||||
$is_source = TRUE;
|
||||
|
|
|
@ -51,7 +51,7 @@ class Iterator extends ProcessPluginBase {
|
|||
* The transformed key.
|
||||
*/
|
||||
protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) {
|
||||
$process = array('key' => $this->configuration['key']);
|
||||
$process = ['key' => $this->configuration['key']];
|
||||
$migrate_executable->processRow($row, $process, $key);
|
||||
return $row->getDestinationProperty('key');
|
||||
}
|
||||
|
|
|
@ -11,13 +11,28 @@ use Drupal\migrate\Row;
|
|||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* This plugin creates a machine name.
|
||||
* Creates a machine name.
|
||||
*
|
||||
* The current value gets transliterated, non-alphanumeric characters removed
|
||||
* and replaced by an underscore and multiple underscores are collapsed into
|
||||
* one.
|
||||
* The machine_name process plugin takes the source value and runs it through
|
||||
* the transliteration service. This makes the source value lowercase,
|
||||
* replaces anything that is not a number or a letter with an underscore,
|
||||
* and removes duplicate underscores.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2135323 Online handbook documentation for machine_name process plugin @endlink
|
||||
* Letters will have language decorations and accents removed.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* bar:
|
||||
* plugin: machine_name
|
||||
* source: foo
|
||||
* @endcode
|
||||
*
|
||||
* If the value of foo in the source is 'áéí!' then the destination value of bar
|
||||
* will be 'aei_'.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "machine_name"
|
||||
|
|
|
@ -75,23 +75,23 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
|
|||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$migration_ids = $this->configuration['migration'];
|
||||
if (!is_array($migration_ids)) {
|
||||
$migration_ids = array($migration_ids);
|
||||
$migration_ids = [$migration_ids];
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
$value = [$value];
|
||||
}
|
||||
$this->skipOnEmpty($value);
|
||||
$self = FALSE;
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
|
||||
$destination_ids = NULL;
|
||||
$source_id_values = array();
|
||||
$source_id_values = [];
|
||||
$migrations = $this->migrationPluginManager->createInstances($migration_ids);
|
||||
foreach ($migrations as $migration_id => $migration) {
|
||||
if ($migration_id == $this->migration->id()) {
|
||||
$self = TRUE;
|
||||
}
|
||||
if (isset($this->configuration['source_ids'][$migration_id])) {
|
||||
$configuration = array('source' => $this->configuration['source_ids'][$migration_id]);
|
||||
$configuration = ['source' => $this->configuration['source_ids'][$migration_id]];
|
||||
$source_id_values[$migration_id] = $this->processPluginManager
|
||||
->createInstance('get', $configuration, $this->migration)
|
||||
->transform(NULL, $migrate_executable, $row, $destination_property);
|
||||
|
@ -128,7 +128,7 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
|
|||
// We already have the source ID values but need to key them for the Row
|
||||
// constructor.
|
||||
$source_ids = $migration->getSourcePlugin()->getIds();
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach (array_keys($source_ids) as $index => $source_id) {
|
||||
$values[$source_id] = $source_id_values[$migration->id()][$index];
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
|
|||
|
||||
// Do a normal migration with the stub row.
|
||||
$migrate_executable->processRow($stub_row, $process);
|
||||
$destination_ids = array();
|
||||
$destination_ids = [];
|
||||
try {
|
||||
$destination_ids = $destination_plugin->import($stub_row);
|
||||
}
|
||||
|
|
|
@ -11,10 +11,47 @@ use Drupal\migrate\ProcessPluginBase;
|
|||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Sets the destination route information based on the source link_path.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2750777 Online handbook documentation for route process plugin @endlink
|
||||
* The source value is an array of two values:
|
||||
* - link_path: The path or URL of the route.
|
||||
* - options: An array of URL options, e.g. query string, attributes, etc.
|
||||
*
|
||||
* * @MigrateProcessPlugin(
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_route_field:
|
||||
* plugin: route
|
||||
* source:
|
||||
* - 'https://www.drupal.org'
|
||||
* -
|
||||
* attributes:
|
||||
* title: Drupal
|
||||
* @endcode
|
||||
*
|
||||
* This will set new_route_field to be a route with the URL
|
||||
* "https://www.drupal.org" and title attribute "Drupal".
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* another_route_field:
|
||||
* plugin: route
|
||||
* source:
|
||||
* - 'user/login'
|
||||
* -
|
||||
* query:
|
||||
* destination: 'node/1'
|
||||
* @endcode
|
||||
*
|
||||
* This will set another_route_field to be a route to the user login page
|
||||
* (user/login) with a query string of "destination=node/1".
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "route"
|
||||
* )
|
||||
*/
|
||||
|
@ -64,12 +101,12 @@ class Route extends ProcessPluginBase implements ContainerFactoryPluginInterface
|
|||
}
|
||||
|
||||
$extracted = $this->pathValidator->getUrlIfValidWithoutAccessCheck($link_path);
|
||||
$route = array();
|
||||
$route = [];
|
||||
|
||||
if ($extracted) {
|
||||
if ($extracted->isExternal()) {
|
||||
$route['route_name'] = NULL;
|
||||
$route['route_parameters'] = array();
|
||||
$route['route_parameters'] = [];
|
||||
$route['options'] = $options;
|
||||
$route['url'] = $extracted->getUri();
|
||||
}
|
||||
|
|
|
@ -9,9 +9,47 @@ use Drupal\migrate\Row;
|
|||
use Drupal\migrate\MigrateSkipRowException;
|
||||
|
||||
/**
|
||||
* If the source evaluates to empty, we skip processing or the whole row.
|
||||
* Skips processing the current row when the input value is empty.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2228793 Online handbook documentation for skip_on_empty process plugin @endlink
|
||||
* The skip_on_empty process plugin checks to see if the current input value
|
||||
* is empty (empty string, NULL, FALSE, 0, '0', or an empty array). If so, the
|
||||
* further processing of the property or the entire row (depending on the chosen
|
||||
* method) is skipped and will not be migrated.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - method: (optional) What to do if the input value is empty. Possible values:
|
||||
* - row: Skips the entire row when an empty value is encountered.
|
||||
* - process: Prevents further processing of the input property when the value
|
||||
* is empty.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* field_type_exists:
|
||||
* plugin: skip_on_empty
|
||||
* method: row
|
||||
* source: field_name
|
||||
* @endcode
|
||||
*
|
||||
* If field_name is empty, skips the entire row.
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* parent:
|
||||
* -
|
||||
* plugin: skip_on_empty
|
||||
* method: process
|
||||
* source: parent
|
||||
* -
|
||||
* plugin: migration
|
||||
* migration: d6_taxonomy_term
|
||||
* @endcode
|
||||
*
|
||||
* If parent is empty, any further processing of the property is skipped - thus,
|
||||
* the next plugin (migration) will not be run.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "skip_on_empty"
|
||||
|
@ -20,7 +58,24 @@ use Drupal\migrate\MigrateSkipRowException;
|
|||
class SkipOnEmpty extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Skips the current row when value is not set.
|
||||
*
|
||||
* @param mixed $value
|
||||
* The input value.
|
||||
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
|
||||
* The migration in which this process is being executed.
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The row from the source to process.
|
||||
* @param string $destination_property
|
||||
* The destination property currently worked on. This is only used together
|
||||
* with the $row above.
|
||||
*
|
||||
* @return mixed
|
||||
* The input value, $value, if it is not empty.
|
||||
*
|
||||
* @throws \Drupal\migrate\MigrateSkipRowException
|
||||
* Thrown if the source property is not set and the row should be skipped,
|
||||
* records with STATUS_IGNORED status in the map.
|
||||
*/
|
||||
public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (!$value) {
|
||||
|
@ -30,7 +85,24 @@ class SkipOnEmpty extends ProcessPluginBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Stops processing the current property when value is not set.
|
||||
*
|
||||
* @param mixed $value
|
||||
* The input value.
|
||||
* @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
|
||||
* The migration in which this process is being executed.
|
||||
* @param \Drupal\migrate\Row $row
|
||||
* The row from the source to process.
|
||||
* @param string $destination_property
|
||||
* The destination property currently worked on. This is only used together
|
||||
* with the $row above.
|
||||
*
|
||||
* @return mixed
|
||||
* The input value, $value, if it is not empty.
|
||||
*
|
||||
* @throws \Drupal\migrate\MigrateSkipProcessException
|
||||
* Thrown if the source property is not set and rest of the process should
|
||||
* be skipped.
|
||||
*/
|
||||
public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (!$value) {
|
||||
|
|
|
@ -8,9 +8,30 @@ use Drupal\migrate\Row;
|
|||
use Drupal\migrate\MigrateSkipRowException;
|
||||
|
||||
/**
|
||||
* If the source evaluates to empty, we skip the current row.
|
||||
* Skips processing the current row when a source value is not set.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2345935 Online handbook documentation for skip_row_if_not_set process plugin @endlink
|
||||
* The skip_row_if_not_set process plugin checks whether a value is set. If the
|
||||
* value is set, it is returned. Otherwise, a MigrateSkipRowException
|
||||
* is thrown.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - index: The source property to check for.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* settings:
|
||||
* # Check if the "contact" key exists in the "data" array.
|
||||
* plugin: skip_row_if_not_set
|
||||
* index: contact
|
||||
* source: data
|
||||
* @endcode
|
||||
*
|
||||
* This will return $data['contact'] if it exists. Otherwise, the row will be
|
||||
* skipped.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "skip_row_if_not_set",
|
||||
|
|
|
@ -31,7 +31,7 @@ class StaticMap extends ProcessPluginBase {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$new_value = array($value);
|
||||
$new_value = [$value];
|
||||
}
|
||||
$new_value = NestedArray::getValue($this->configuration['map'], $new_value, $key_exists);
|
||||
if (!$key_exists) {
|
||||
|
|
|
@ -9,9 +9,44 @@ use Drupal\migrate\MigrateException;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* This plugin returns a substring of the current value.
|
||||
* Returns a substring of the input value.
|
||||
*
|
||||
* @link https://www.drupal.org/node/2771965 Online handbook documentation for substr process plugin @endlink
|
||||
* The substr process plugin returns the portion of the input value specified by
|
||||
* the start and length parameters. This is a wrapper around the PHP substr()
|
||||
* function.
|
||||
*
|
||||
* Available configuration keys:
|
||||
* - start: (optional) The returned string will start this many characters after
|
||||
* the beginning of the string. Defaults to NULL.
|
||||
* - length: (optional) The maximum number of characters in the returned
|
||||
* string. Defaults to NULL.
|
||||
*
|
||||
* If start is NULL and length is an integer, the start position is the
|
||||
* beginning of the string. If start is an integer and length is NULL, the
|
||||
* substring starting from the start position until the end of the string will
|
||||
* be returned. If both start and length are NULL the entire string is returned.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_text_field:
|
||||
* plugin: substr
|
||||
* source: some_text_field
|
||||
* start: 6
|
||||
* length: 10
|
||||
* @endcode
|
||||
*
|
||||
* If some_text_field was 'Marie Skłodowska Curie' then
|
||||
* $destination['new_text_field'] would be 'Skłodowska'.
|
||||
*
|
||||
* The PHP equivalent of this is:
|
||||
*
|
||||
* @code
|
||||
* $destination['new_text_field'] = substr($source['some_text_field'], 6, 10);
|
||||
* @endcode
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "substr"
|
||||
|
|
|
@ -9,10 +9,21 @@ use Drupal\migrate\Row;
|
|||
use GuzzleHttp\Psr7\Uri;
|
||||
|
||||
/**
|
||||
* Apply urlencoding to a URI.
|
||||
* URL-encodes the input value.
|
||||
*
|
||||
* This is needed when the URI is to be opened by a later migration stage, and
|
||||
* the source URI value is not already encoded.
|
||||
* Example:
|
||||
*
|
||||
* @code
|
||||
* process:
|
||||
* new_url:
|
||||
* plugin: urlencode
|
||||
* source: 'http://example.com/a url with spaces.html'
|
||||
* @endcode
|
||||
*
|
||||
* This will convert the source URL 'http://example.com/a url with spaces.html'
|
||||
* into 'http://example.com/a%20url%20with%20spaces.html'.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "urlencode"
|
||||
|
@ -33,7 +44,7 @@ class UrlEncode extends ProcessPluginBase {
|
|||
throw new MigrateException("Value '$value' is not a valid URL");
|
||||
}
|
||||
// Iterate over specific pieces of the URL rawurlencoding each one.
|
||||
$url_parts_to_encode = array('path', 'query', 'fragment');
|
||||
$url_parts_to_encode = ['path', 'query', 'fragment'];
|
||||
foreach ($parsed_url as $parsed_url_key => $parsed_url_value) {
|
||||
if (in_array($parsed_url_key, $url_parts_to_encode)) {
|
||||
// urlencode() would convert spaces to + signs.
|
||||
|
|
|
@ -17,16 +17,16 @@ class EmptySource extends SourcePluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'id' => t('ID'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initializeIterator() {
|
||||
return new \ArrayIterator(array(array('id' => '')));
|
||||
return new \ArrayIterator([['id' => '']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,8 +198,8 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
|
|||
public function prepareRow(Row $row) {
|
||||
$result = TRUE;
|
||||
try {
|
||||
$result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', array($row, $this, $this->migration));
|
||||
$result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', array($row, $this, $this->migration));
|
||||
$result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', [$row, $this, $this->migration]);
|
||||
$result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', [$row, $this, $this->migration]);
|
||||
// We will skip if any hook returned FALSE.
|
||||
$skip = ($result_hook && in_array(FALSE, $result_hook)) || ($result_named_hook && in_array(FALSE, $result_named_hook));
|
||||
$save_to_map = TRUE;
|
||||
|
@ -217,7 +217,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
|
|||
// Make sure we replace any previous messages for this item with any
|
||||
// new ones.
|
||||
if ($save_to_map) {
|
||||
$this->idMap->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED);
|
||||
$this->idMap->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_IGNORED);
|
||||
$this->currentRow = NULL;
|
||||
$this->currentSourceIds = NULL;
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
|
|||
/**
|
||||
* Gets the iterator key.
|
||||
*
|
||||
* Implementation of Iterator::key - called when entering a loop iteration,
|
||||
* Implementation of \Iterator::key() - called when entering a loop iteration,
|
||||
* returning the key of the current row. It must be a scalar - we will
|
||||
* serialize to fulfill the requirement, but using getCurrentIds() is
|
||||
* preferable.
|
||||
|
@ -268,7 +268,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
|
|||
/**
|
||||
* Checks whether the iterator is currently valid.
|
||||
*
|
||||
* Implementation of Iterator::valid() - called at the top of the loop,
|
||||
* Implementation of \Iterator::valid() - called at the top of the loop,
|
||||
* returning TRUE to process the loop and FALSE to terminate it.
|
||||
*/
|
||||
public function valid() {
|
||||
|
@ -278,9 +278,9 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
|
|||
/**
|
||||
* Rewinds the iterator.
|
||||
*
|
||||
* Implementation of Iterator::rewind() - subclasses of MigrateSource should
|
||||
* implement performRewind() to do any class-specific setup for iterating
|
||||
* source records.
|
||||
* Implementation of \Iterator::rewind() - subclasses of SourcePluginBase
|
||||
* should implement initializeIterator() to do any class-specific setup for
|
||||
* iterating source records.
|
||||
*/
|
||||
public function rewind() {
|
||||
$this->getIterator()->rewind();
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
|
||||
namespace Drupal\migrate\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Core\Database\ConnectionNotDefinedException;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\id_map\Sql;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -20,7 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* is present, it is used as a database connection information array to define
|
||||
* the connection.
|
||||
*/
|
||||
abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPluginInterface {
|
||||
abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPluginInterface, RequirementsInterface {
|
||||
|
||||
/**
|
||||
* The query string.
|
||||
|
@ -127,12 +130,17 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
*
|
||||
* @return \Drupal\Core\Database\Connection
|
||||
* The connection to use for this plugin's queries.
|
||||
*
|
||||
* @throws \Drupal\migrate\Exception\RequirementsException
|
||||
* Thrown if no source database connection is configured.
|
||||
*/
|
||||
protected function setUpDatabase(array $database_info) {
|
||||
if (isset($database_info['key'])) {
|
||||
$key = $database_info['key'];
|
||||
}
|
||||
else {
|
||||
// If there is no explicit database configuration at all, fall back to a
|
||||
// connection named 'migrate'.
|
||||
$key = 'migrate';
|
||||
}
|
||||
if (isset($database_info['target'])) {
|
||||
|
@ -144,13 +152,35 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
if (isset($database_info['database'])) {
|
||||
Database::addConnectionInfo($key, $target, $database_info['database']);
|
||||
}
|
||||
return Database::getConnection($target, $key);
|
||||
try {
|
||||
$connection = Database::getConnection($target, $key);
|
||||
}
|
||||
catch (ConnectionNotDefinedException $e) {
|
||||
// If we fell back to the magic 'migrate' connection and it doesn't exist,
|
||||
// treat the lack of the connection as a RequirementsException.
|
||||
if ($key == 'migrate') {
|
||||
throw new RequirementsException("No database connection configured for source plugin " . $this->pluginId, [], 0, $e);
|
||||
}
|
||||
else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkRequirements() {
|
||||
if ($this->pluginDefinition['requirements_met'] === TRUE) {
|
||||
$this->getDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for database select.
|
||||
*/
|
||||
protected function select($table, $alias = NULL, array $options = array()) {
|
||||
protected function select($table, $alias = NULL, array $options = []) {
|
||||
$options['fetch'] = \PDO::FETCH_ASSOC;
|
||||
return $this->getDatabase()->select($table, $alias, $options);
|
||||
}
|
||||
|
@ -171,10 +201,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
}
|
||||
|
||||
/**
|
||||
* Implementation of MigrateSource::performRewind().
|
||||
*
|
||||
* We could simply execute the query and be functionally correct, but
|
||||
* we will take advantage of the PDO-based API to optimize the query up-front.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
// Initialize the batch size.
|
||||
|
@ -193,7 +220,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
$this->prepareQuery();
|
||||
|
||||
// Get the key values, for potential use in joining to the map table.
|
||||
$keys = array();
|
||||
$keys = [];
|
||||
|
||||
// The rules for determining what conditions to add to the query are as
|
||||
// follows (applying first applicable rule):
|
||||
|
@ -247,6 +274,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
$high_water_field = $this->getHighWaterField();
|
||||
$conditions->condition($high_water_field, $high_water, '>');
|
||||
$this->query->orderBy($high_water_field);
|
||||
$condition_added = TRUE;
|
||||
}
|
||||
if ($condition_added) {
|
||||
$this->query->condition($conditions);
|
||||
|
@ -329,7 +357,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
foreach (array('username', 'password', 'host', 'port', 'namespace', 'driver') as $key) {
|
||||
foreach (['username', 'password', 'host', 'port', 'namespace', 'driver'] as $key) {
|
||||
if (isset($source_database_options[$key])) {
|
||||
if ($id_map_database_options[$key] != $source_database_options[$key]) {
|
||||
return FALSE;
|
||||
|
|
|
@ -15,21 +15,21 @@ class Row {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $source = array();
|
||||
protected $source = [];
|
||||
|
||||
/**
|
||||
* The source identifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sourceIds = array();
|
||||
protected $sourceIds = [];
|
||||
|
||||
/**
|
||||
* The destination values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $destination = array();
|
||||
protected $destination = [];
|
||||
|
||||
/**
|
||||
* Level separator of destination and source properties.
|
||||
|
@ -41,11 +41,11 @@ class Row {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $idMap = array(
|
||||
protected $idMap = [
|
||||
'original_hash' => '',
|
||||
'hash' => '',
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether the source has been frozen already.
|
||||
|
|
|
@ -32,7 +32,7 @@ class DummyDestination extends DestinationBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
return ['value' => $row->getDestinationProperty('value')];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
/**
|
||||
* Tests the high water handling.
|
||||
*
|
||||
* @covers \Drupal\migrate_sql_test\Plugin\migrate\source\HighWaterTest
|
||||
* @group migrate
|
||||
*/
|
||||
class HighWaterNotJoinableTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate', 'migrate_drupal', 'migrate_sql_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['high_water_node'] = [
|
||||
[
|
||||
'id' => 1,
|
||||
'title' => 'Item 1',
|
||||
'changed' => 1,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'title' => 'Item 2',
|
||||
'changed' => 2,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'title' => 'Item 3',
|
||||
'changed' => 3,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'id' => 2,
|
||||
'title' => 'Item 2',
|
||||
'changed' => 2,
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'title' => 'Item 3',
|
||||
'changed' => 3,
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
$tests[0]['configuration'] = [
|
||||
'high_water_property' => [
|
||||
'name' => 'changed',
|
||||
],
|
||||
];
|
||||
$tests[0]['high_water'] = $tests[0]['source_data']['high_water_node'][0]['changed'];
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -136,6 +136,64 @@ class HighWaterTest extends MigrateTestBase {
|
|||
$this->assertNodeDoesNotExist('Item 3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests high water property of SqlBase when rows marked for update.
|
||||
*/
|
||||
public function testHighWaterUpdate() {
|
||||
// Assert all of the nodes have been imported.
|
||||
$this->assertNodeExists('Item 1');
|
||||
$this->assertNodeExists('Item 2');
|
||||
$this->assertNodeExists('Item 3');
|
||||
|
||||
// Update Item 1 setting its high_water_property to value that is below
|
||||
// current high water mark.
|
||||
$this->sourceDatabase->update('high_water_node')
|
||||
->fields([
|
||||
'title' => 'Item 1 updated',
|
||||
'changed' => 2,
|
||||
])
|
||||
->condition('title', 'Item 1')
|
||||
->execute();
|
||||
|
||||
// Update Item 2 setting its high_water_property to value equal to
|
||||
// current high water mark.
|
||||
$this->sourceDatabase->update('high_water_node')
|
||||
->fields([
|
||||
'title' => 'Item 2 updated',
|
||||
'changed' => 3,
|
||||
])
|
||||
->condition('title', 'Item 2')
|
||||
->execute();
|
||||
|
||||
// Update Item 3 setting its high_water_property to value that is above
|
||||
// current high water mark.
|
||||
$this->sourceDatabase->update('high_water_node')
|
||||
->fields([
|
||||
'title' => 'Item 3 updated',
|
||||
'changed' => 4,
|
||||
])
|
||||
->condition('title', 'Item 3')
|
||||
->execute();
|
||||
|
||||
// Set all rows as needing an update.
|
||||
$id_map = $this->getMigration('high_water_test')->getIdMap();
|
||||
$id_map->prepareUpdate();
|
||||
|
||||
$this->executeMigration('high_water_test');
|
||||
|
||||
// Item with lower highwater should be updated.
|
||||
$this->assertNodeExists('Item 1 updated');
|
||||
$this->assertNodeDoesNotExist('Item 1');
|
||||
|
||||
// Item with equal highwater should be updated.
|
||||
$this->assertNodeExists('Item 2 updated');
|
||||
$this->assertNodeDoesNotExist('Item 2');
|
||||
|
||||
// Item with greater highwater should be updated.
|
||||
$this->assertNodeExists('Item 3 updated');
|
||||
$this->assertNodeDoesNotExist('Item 3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that node with given title exists.
|
||||
*
|
||||
|
|
|
@ -40,17 +40,17 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
parent::setUp();
|
||||
$this->state = \Drupal::state();
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_SAVE,
|
||||
array($this, 'mapSaveEventRecorder'));
|
||||
[$this, 'mapSaveEventRecorder']);
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_DELETE,
|
||||
array($this, 'mapDeleteEventRecorder'));
|
||||
[$this, 'mapDeleteEventRecorder']);
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::PRE_IMPORT,
|
||||
array($this, 'preImportEventRecorder'));
|
||||
[$this, 'preImportEventRecorder']);
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_IMPORT,
|
||||
array($this, 'postImportEventRecorder'));
|
||||
[$this, 'postImportEventRecorder']);
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::PRE_ROW_SAVE,
|
||||
array($this, 'preRowSaveEventRecorder'));
|
||||
[$this, 'preRowSaveEventRecorder']);
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
|
||||
array($this, 'postRowSaveEventRecorder'));
|
||||
[$this, 'postRowSaveEventRecorder']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,11 +129,11 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function mapSaveEventRecorder(MigrateMapSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.map_save_event', array(
|
||||
$this->state->set('migrate_events_test.map_save_event', [
|
||||
'event_name' => $name,
|
||||
'map' => $event->getMap(),
|
||||
'fields' => $event->getFields(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,11 +145,11 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function mapDeleteEventRecorder(MigrateMapDeleteEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.map_delete_event', array(
|
||||
$this->state->set('migrate_events_test.map_delete_event', [
|
||||
'event_name' => $name,
|
||||
'map' => $event->getMap(),
|
||||
'source_id' => $event->getSourceId(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,10 +161,10 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function preImportEventRecorder(MigrateImportEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.pre_import_event', array(
|
||||
$this->state->set('migrate_events_test.pre_import_event', [
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,10 +176,10 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function postImportEventRecorder(MigrateImportEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.post_import_event', array(
|
||||
$this->state->set('migrate_events_test.post_import_event', [
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,11 +191,11 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function preRowSaveEventRecorder(MigratePreRowSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.pre_row_save_event', array(
|
||||
$this->state->set('migrate_events_test.pre_row_save_event', [
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
'row' => $event->getRow(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,12 +207,12 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
* The event name.
|
||||
*/
|
||||
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
|
||||
$this->state->set('migrate_events_test.post_row_save_event', array(
|
||||
$this->state->set('migrate_events_test.post_row_save_event', [
|
||||
'event_name' => $name,
|
||||
'migration' => $event->getMigration(),
|
||||
'row' => $event->getRow(),
|
||||
'destination_id_values' => $event->getDestinationIdValues(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,8 @@ class MigrateExternalTranslatedTest extends MigrateTestBase {
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @todo: Remove migrate_drupal when https://www.drupal.org/node/2560795 is
|
||||
* fixed.
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'language', 'node', 'field', 'migrate_drupal', 'migrate_external_translated_test'];
|
||||
public static $modules = ['system', 'user', 'language', 'node', 'field', 'migrate_external_translated_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -30,7 +27,7 @@ class MigrateExternalTranslatedTest extends MigrateTestBase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('node', array('node_access'));
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('node');
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class MigrateInterruptionTest extends KernelTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE,
|
||||
array($this, 'postRowSaveEventRecorder'));
|
||||
[$this, 'postRowSaveEventRecorder']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,7 +89,7 @@ class MigrateMessageTest extends KernelTestBase implements MigrateMessageInterfa
|
|||
public function testMessagesTeed() {
|
||||
// Ask to receive any messages sent to the idmap.
|
||||
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE,
|
||||
array($this, 'mapMessageRecorder'));
|
||||
[$this, 'mapMessageRecorder']);
|
||||
$executable = new MigrateExecutable($this->migration, $this);
|
||||
$executable->import();
|
||||
$this->assertIdentical(count($this->messages), 1);
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
/**
|
||||
* Tests rolling back of imports.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'language', 'config_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests rolling back configuration entity translations.
|
||||
*/
|
||||
public function testConfigEntityRollback() {
|
||||
// We use vocabularies to demonstrate importing and rolling back
|
||||
// configuration entities with translations. First, import vocabularies.
|
||||
$vocabulary_data_rows = [
|
||||
['id' => '1', 'name' => 'categories', 'weight' => '2'],
|
||||
['id' => '2', 'name' => 'tags', 'weight' => '1'],
|
||||
];
|
||||
$ids = ['id' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'id' => 'vocabularies',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $vocabulary_data_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'vid' => 'id',
|
||||
'name' => 'name',
|
||||
'weight' => 'weight',
|
||||
],
|
||||
'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
|
||||
];
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\Migration $vocabulary_migration */
|
||||
$vocabulary_migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$vocabulary_id_map = $vocabulary_migration->getIdMap();
|
||||
|
||||
$this->assertTrue($vocabulary_migration->getDestinationPlugin()
|
||||
->supportsRollback());
|
||||
|
||||
// Import and validate vocabulary config entities were created.
|
||||
$vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
|
||||
$vocabulary_executable->import();
|
||||
foreach ($vocabulary_data_rows as $row) {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
|
||||
$vocabulary = Vocabulary::load($row['id']);
|
||||
$this->assertTrue($vocabulary);
|
||||
$map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
// Second, import translations of the vocabulary name property.
|
||||
$vocabulary_i18n_data_rows = [
|
||||
[
|
||||
'id' => '1',
|
||||
'name' => '1',
|
||||
'language' => 'fr',
|
||||
'property' => 'name',
|
||||
'translation' => 'fr - categories'
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'name' => '2',
|
||||
'language' => 'fr',
|
||||
'property' => 'name',
|
||||
'translation' => 'fr - tags'
|
||||
],
|
||||
];
|
||||
$ids = [
|
||||
'id' => ['type' => 'integer'],
|
||||
'language' => ['type' => 'string'],
|
||||
];
|
||||
$definition = [
|
||||
'id' => 'i18n_vocabularies',
|
||||
'migration_tags' => ['Import and rollback test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $vocabulary_i18n_data_rows,
|
||||
'ids' => $ids,
|
||||
'constants' => [
|
||||
'name' => 'name',
|
||||
]
|
||||
],
|
||||
'process' => [
|
||||
'vid' => 'id',
|
||||
'langcode' => 'language',
|
||||
'property' => 'constants/name',
|
||||
'translation' => 'translation',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:taxonomy_vocabulary',
|
||||
'translations' => 'true',
|
||||
],
|
||||
];
|
||||
|
||||
$vocabulary_i18n__migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$vocabulary_i18n_id_map = $vocabulary_i18n__migration->getIdMap();
|
||||
|
||||
$this->assertTrue($vocabulary_i18n__migration->getDestinationPlugin()
|
||||
->supportsRollback());
|
||||
|
||||
// Import and validate vocabulary config entities were created.
|
||||
$vocabulary_i18n_executable = new MigrateExecutable($vocabulary_i18n__migration, $this);
|
||||
$vocabulary_i18n_executable->import();
|
||||
|
||||
$language_manager = \Drupal::service('language_manager');
|
||||
foreach ($vocabulary_i18n_data_rows as $row) {
|
||||
$langcode = $row['language'];
|
||||
$id = 'taxonomy.vocabulary.' . $row['id'];
|
||||
/** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
|
||||
$config_translation = $language_manager->getLanguageConfigOverride($langcode, $id);
|
||||
$this->assertSame($row['translation'], $config_translation->get('name'));
|
||||
$map_row = $vocabulary_i18n_id_map->getRowBySource(['id' => $row['id'], 'language' => $row['language']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
// Perform the rollback and confirm the translation was deleted and the map
|
||||
// table row removed.
|
||||
$vocabulary_i18n_executable->rollback();
|
||||
foreach ($vocabulary_i18n_data_rows as $row) {
|
||||
$langcode = $row['language'];
|
||||
$id = 'taxonomy.vocabulary.' . $row['id'];
|
||||
/** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
|
||||
$config_translation = $language_manager->getLanguageConfigOverride($langcode, $id);
|
||||
$this->assertNull($config_translation->get('name'));
|
||||
$map_row = $vocabulary_i18n_id_map->getRowBySource(['id' => $row['id'], 'language' => $row['language']]);
|
||||
$this->assertFalse($map_row);
|
||||
}
|
||||
|
||||
// Confirm the original vocabulary still exists.
|
||||
foreach ($vocabulary_data_rows as $row) {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
|
||||
$vocabulary = Vocabulary::load($row['id']);
|
||||
$this->assertTrue($vocabulary);
|
||||
$map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
|
||||
$this->assertNotNull($map_row['destid1']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -135,23 +135,33 @@ abstract class MigrateSourceTestBase extends KernelTestBase {
|
|||
* value (like FALSE or 'nope'), the source plugin will not be counted.
|
||||
* @param array $configuration
|
||||
* (optional) Configuration for the source plugin.
|
||||
* @param mixed $high_water
|
||||
* (optional) The value of the high water field.
|
||||
*
|
||||
* @dataProvider providerSource
|
||||
*/
|
||||
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
|
||||
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
|
||||
$plugin = $this->getPlugin($configuration);
|
||||
|
||||
// All source plugins must define IDs.
|
||||
$this->assertNotEmpty($plugin->getIds());
|
||||
|
||||
// If there is a high water mark, set it in the high water storage.
|
||||
if (isset($high_water)) {
|
||||
$this->container
|
||||
->get('keyvalue')
|
||||
->get('migrate:high_water')
|
||||
->set($this->migration->reveal()->id(), $high_water);
|
||||
}
|
||||
|
||||
if (is_null($expected_count)) {
|
||||
$expected_count = count($expected_data);
|
||||
}
|
||||
// If an expected count was given, assert it only if the plugin is
|
||||
// countable.
|
||||
if (is_numeric($expected_count)) {
|
||||
$this->assertInstanceOf('\Countable', $plugin);
|
||||
$this->assertCount($expected_count, $plugin);
|
||||
$this->assertInstanceOf('\Iterator', $plugin);
|
||||
$this->assertSame($expected_count, iterator_count($plugin));
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
|
|
@ -63,12 +63,14 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
|
|||
* (optional) How many rows the source plugin is expected to return.
|
||||
* @param array $configuration
|
||||
* (optional) Configuration for the source plugin.
|
||||
* @param mixed $high_water
|
||||
* (optional) The value of the high water field.
|
||||
*
|
||||
* @dataProvider providerSource
|
||||
*
|
||||
* @requires extension pdo_sqlite
|
||||
*/
|
||||
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) {
|
||||
public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) {
|
||||
$plugin = $this->getPlugin($configuration);
|
||||
|
||||
// Since we don't yet inject the database connection, we need to use a
|
||||
|
@ -78,7 +80,7 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
|
|||
$property->setAccessible(TRUE);
|
||||
$property->setValue($plugin, $this->getDatabase($source_data));
|
||||
|
||||
parent::testSource($source_data, $expected_data, $expected_count, $configuration);
|
||||
parent::testSource($source_data, $expected_data, $expected_count, $configuration, $high_water);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,13 +33,13 @@ class MigrateStatusTest extends MigrateTestBase {
|
|||
$this->assertIdentical($status, MigrationInterface::STATUS_IDLE);
|
||||
|
||||
// Test setting and retrieving all known status values.
|
||||
$status_list = array(
|
||||
$status_list = [
|
||||
MigrationInterface::STATUS_IDLE,
|
||||
MigrationInterface::STATUS_IMPORTING,
|
||||
MigrationInterface::STATUS_ROLLING_BACK,
|
||||
MigrationInterface::STATUS_STOPPING,
|
||||
MigrationInterface::STATUS_DISABLED,
|
||||
);
|
||||
];
|
||||
foreach ($status_list as $status) {
|
||||
$migration->setStatus($status);
|
||||
$this->assertIdentical($migration->getStatus(), $status);
|
||||
|
|
|
@ -47,7 +47,7 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
|
|||
*/
|
||||
protected $sourceDatabase;
|
||||
|
||||
public static $modules = array('migrate');
|
||||
public static $modules = ['migrate'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -201,7 +201,7 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
|
|||
*/
|
||||
public function startCollectingMessages() {
|
||||
$this->collectMessages = TRUE;
|
||||
$this->migrateMessages = array();
|
||||
$this->migrateMessages = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,9 @@ namespace Drupal\Tests\migrate\Kernel\Plugin;
|
|||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
|
||||
/**
|
||||
* Tests the migration plugin manager.
|
||||
|
@ -79,6 +82,31 @@ class MigrationPluginListTest extends KernelTestBase {
|
|||
|
||||
// Enable migrate_drupal to test that the plugins can now be discovered.
|
||||
$this->enableModules(['migrate_drupal']);
|
||||
|
||||
// Make sure retrieving these migration plugins in the absence of a database
|
||||
// connection does not throw any errors.
|
||||
$migration_plugins = $this->container->get('plugin.manager.migration')->createInstances([]);
|
||||
// Any database-based source plugins should fail a requirements test in the
|
||||
// absence of a source database connection (e.g., a connection with the
|
||||
// 'migrate' key).
|
||||
$source_plugins = array_map(function ($migration_plugin) { return $migration_plugin->getSourcePlugin(); }, $migration_plugins);
|
||||
foreach ($source_plugins as $id => $source_plugin) {
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
try {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
unset($source_plugins[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Without a connection defined, no database-based plugins should be
|
||||
// returned.
|
||||
foreach ($source_plugins as $id => $source_plugin) {
|
||||
$this->assertNotInstanceOf(SqlBase::class, $source_plugin);
|
||||
}
|
||||
|
||||
// Set up a migrate database connection so that plugin discovery works.
|
||||
// Clone the current connection and replace the current prefix.
|
||||
$connection_info = Database::getConnectionInfo('migrate');
|
||||
|
|
|
@ -30,7 +30,7 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
|
||||
$target = 'test_db_target';
|
||||
$key = 'test_migrate_connection';
|
||||
$config = array('target' => $target, 'key' => $key);
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
$sql_base->setConfiguration($config);
|
||||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
|
||||
|
@ -44,7 +44,7 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
$target = 'test_db_target2';
|
||||
$key = 'test_migrate_connection2';
|
||||
$database = Database::getConnectionInfo('default')['default'];
|
||||
$config = array('target' => $target, 'key' => $key, 'database' => $database);
|
||||
$config = ['target' => $target, 'key' => $key, 'database' => $database];
|
||||
$sql_base->setConfiguration($config);
|
||||
|
||||
// Call getDatabase() to get the connection defined.
|
||||
|
|
|
@ -1,218 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\FileCopy;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Tests the copy_file process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class CopyFileTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate', 'system'];
|
||||
|
||||
/**
|
||||
* The file system service.
|
||||
*
|
||||
* @var \Drupal\Core\File\FileSystemInterface
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->fileSystem = $this->container->get('file_system');
|
||||
$this->container->get('stream_wrapper_manager')->registerWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream', StreamWrapperInterface::LOCAL_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful imports/copies.
|
||||
*/
|
||||
public function testSuccessfulCopies() {
|
||||
$file = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_absolute = $this->fileSystem->realpath($file);
|
||||
$data_sets = [
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$this->root . '/core/modules/simpletest/files/image-test.jpg',
|
||||
'public://file1.jpg'
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://test.jpg'
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
list($source_path, $destination_path) = $data;
|
||||
$actual_destination = $this->doImport($source_path, $destination_path);
|
||||
$message = sprintf('File %s exists', $destination_path);
|
||||
$this->assertFileExists($destination_path, $message);
|
||||
// Make sure we didn't accidentally do a move.
|
||||
$this->assertFileExists($source_path, $message);
|
||||
$this->assertSame($actual_destination, $destination_path, 'The import returned the copied filename.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful file reuse.
|
||||
*/
|
||||
public function testSuccessfulReuse() {
|
||||
$source_path = $this->root . '/core/modules/simpletest/files/image-test.jpg';
|
||||
$destination_path = 'public://file1.jpg';
|
||||
$file_reuse = file_unmanaged_copy($source_path, $destination_path);
|
||||
$timestamp = (new \SplFileInfo($file_reuse))->getMTime();
|
||||
$this->assertInternalType('int', $timestamp);
|
||||
|
||||
// We need to make sure the modified timestamp on the file is sooner than
|
||||
// the attempted migration.
|
||||
sleep(1);
|
||||
$configuration = ['reuse' => TRUE];
|
||||
$this->doImport($source_path, $destination_path, $configuration);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertEquals($timestamp, $modified_timestamp);
|
||||
|
||||
$configuration = ['reuse' => FALSE];
|
||||
$this->doImport($source_path, $destination_path, $configuration);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertGreaterThan($timestamp, $modified_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful moves.
|
||||
*/
|
||||
public function testSuccessfulMoves() {
|
||||
$file_1 = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_1_absolute = $this->fileSystem->realpath($file_1);
|
||||
$file_2 = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_2_absolute = $this->fileSystem->realpath($file_2);
|
||||
$local_file = $this->createUri(NULL, NULL, 'public');
|
||||
$data_sets = [
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$local_file,
|
||||
'public://file1.jpg'
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_1_absolute,
|
||||
'temporary://test.jpg'
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_2_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
list($source_path, $destination_path) = $data;
|
||||
$actual_destination = $this->doImport($source_path, $destination_path, ['move' => TRUE]);
|
||||
$message = sprintf('File %s exists', $destination_path);
|
||||
$this->assertFileExists($destination_path, $message);
|
||||
$message = sprintf('File %s does not exist', $source_path);
|
||||
$this->assertFileNotExists($source_path, $message);
|
||||
$this->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that non-existent files throw an exception.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage File '/non/existent/file' does not exist
|
||||
*/
|
||||
public function testNonExistentSourceFile() {
|
||||
$source = '/non/existent/file';
|
||||
$this->doImport($source, 'public://wontmatter.jpg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the 'rename' overwrite mode.
|
||||
*/
|
||||
public function testRenameFile() {
|
||||
$source = $this->createUri(NULL, NULL, 'temporary');
|
||||
$destination = $this->createUri('foo.txt', NULL, 'public');
|
||||
$expected_destination = 'public://foo_0.txt';
|
||||
$actual_destination = $this->doImport($source, $destination, ['rename' => TRUE]);
|
||||
$this->assertFileExists($expected_destination, 'File was renamed on import');
|
||||
$this->assertSame($actual_destination, $expected_destination, 'The importer returned the renamed filename.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Do an import using the destination.
|
||||
*
|
||||
* @param string $source_path
|
||||
* Source path to copy from.
|
||||
* @param string $destination_path
|
||||
* The destination path to copy to.
|
||||
* @param array $configuration
|
||||
* Process plugin configuration settings.
|
||||
*
|
||||
* @throws \Drupal\migrate\MigrateException
|
||||
*/
|
||||
protected function doImport($source_path, $destination_path, $configuration = []) {
|
||||
$plugin = FileCopy::create($this->container, $configuration, 'file_copy', []);
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = new Row();
|
||||
|
||||
$result = $plugin->transform([$source_path, $destination_path], $executable, $row, 'foobaz');
|
||||
|
||||
// Return the imported file Uri.
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file and return the URI of it.
|
||||
*
|
||||
* @param $filepath
|
||||
* Optional string specifying the file path. If none is provided then a
|
||||
* randomly named file will be created in the site's files directory.
|
||||
* @param $contents
|
||||
* Optional contents to save into the file. If a NULL value is provided an
|
||||
* arbitrary string will be used.
|
||||
* @param $scheme
|
||||
* Optional string indicating the stream scheme to use. Drupal core includes
|
||||
* public, private, and temporary. The public wrapper is the default.
|
||||
* @return
|
||||
* File URI.
|
||||
*/
|
||||
protected function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
|
||||
if (!isset($filepath)) {
|
||||
// Prefix with non-latin characters to ensure that all file-related
|
||||
// tests work with international filenames.
|
||||
$filepath = 'Файл для тестирования ' . $this->randomMachineName();
|
||||
}
|
||||
if (empty($scheme)) {
|
||||
$scheme = file_default_scheme();
|
||||
}
|
||||
$filepath = $scheme . '://' . $filepath;
|
||||
|
||||
if (empty($contents)) {
|
||||
$contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
|
||||
}
|
||||
|
||||
file_put_contents($filepath, $contents);
|
||||
$this->assertFileExists($filepath, t('The test file exists on the disk.'));
|
||||
return $filepath;
|
||||
}
|
||||
|
||||
}
|
|
@ -74,6 +74,32 @@ class FileCopyTest extends FileTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful file reuse.
|
||||
*/
|
||||
public function testSuccessfulReuse() {
|
||||
$source_path = $this->root . '/core/modules/simpletest/files/image-test.jpg';
|
||||
$destination_path = 'public://file1.jpg';
|
||||
$file_reuse = file_unmanaged_copy($source_path, $destination_path);
|
||||
$timestamp = (new \SplFileInfo($file_reuse))->getMTime();
|
||||
$this->assertInternalType('int', $timestamp);
|
||||
|
||||
// We need to make sure the modified timestamp on the file is sooner than
|
||||
// the attempted migration.
|
||||
sleep(1);
|
||||
$configuration = ['reuse' => TRUE];
|
||||
$this->doTransform($source_path, $destination_path, $configuration);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertEquals($timestamp, $modified_timestamp);
|
||||
|
||||
$configuration = ['reuse' => FALSE];
|
||||
$this->doTransform($source_path, $destination_path, $configuration);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertGreaterThan($timestamp, $modified_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful moves.
|
||||
*/
|
||||
|
@ -113,13 +139,10 @@ class FileCopyTest extends FileTestBase {
|
|||
|
||||
/**
|
||||
* Test that non-existent files throw an exception.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage File '/non/existent/file' does not exist
|
||||
*/
|
||||
public function testNonExistentSourceFile() {
|
||||
$source = '/non/existent/file';
|
||||
$this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist");
|
||||
$this->doTransform($source, 'public://wontmatter.jpg');
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ class RouteTest extends KernelTestBase {
|
|||
* @param array|string $value
|
||||
* Source link path information.
|
||||
*
|
||||
* @return array $actual
|
||||
* @return array
|
||||
* The route information based on the source link_path.
|
||||
*/
|
||||
protected function doTransform($value) {
|
||||
|
|
|
@ -34,18 +34,18 @@ class RequirementsExceptionTest extends UnitTestCase {
|
|||
* Provides a list of requirements to test.
|
||||
*/
|
||||
public function getRequirementsProvider() {
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'requirements: random_jackson_pivot.',
|
||||
'Single Requirement',
|
||||
array('requirements' => $this->missingRequirements[0]),
|
||||
),
|
||||
array(
|
||||
['requirements' => $this->missingRequirements[0]],
|
||||
],
|
||||
[
|
||||
'requirements: random_jackson_pivot. requirements: 51_Eridani_b.',
|
||||
'Multiple Requirements',
|
||||
array('requirements' => $this->missingRequirements),
|
||||
),
|
||||
);
|
||||
['requirements' => $this->missingRequirements],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The php.ini memory_limit value.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\migrate\Unit;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
@ -40,9 +41,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -91,12 +92,12 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->with(array('id' => 'test'))
|
||||
->will($this->returnValue(array('test')));
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -106,13 +107,13 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
|
||||
$destination->expects($this->once())
|
||||
->method('import')
|
||||
->with($row, array('test'))
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->with($row, ['test'])
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$this->migration
|
||||
->method('getDestinationPlugin')
|
||||
|
@ -133,12 +134,12 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->with(array('id' => 'test'))
|
||||
->will($this->returnValue(array('test')));
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -148,12 +149,12 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
|
||||
$destination->expects($this->once())
|
||||
->method('import')
|
||||
->with($row, array('test'))
|
||||
->with($row, ['test'])
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
$this->migration
|
||||
|
@ -178,7 +179,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -188,13 +189,13 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
|
||||
$destination->expects($this->once())
|
||||
->method('import')
|
||||
->with($row, array('test'))
|
||||
->will($this->returnValue(array()));
|
||||
->with($row, ['test'])
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$this->migration
|
||||
->method('getDestinationPlugin')
|
||||
|
@ -202,7 +203,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('messageCount')
|
||||
|
@ -213,8 +214,8 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->with(array('id' => 'test'))
|
||||
->will($this->returnValue(array('test')));
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
|
||||
$this->message->expects($this->once())
|
||||
->method('display')
|
||||
|
@ -238,7 +239,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -248,12 +249,12 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
|
||||
$destination->expects($this->once())
|
||||
->method('import')
|
||||
->with($row, array('test'))
|
||||
->with($row, ['test'])
|
||||
->will($this->throwException(new MigrateException($exception_message)));
|
||||
|
||||
$this->migration
|
||||
|
@ -262,15 +263,15 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->with(array('id' => 'test'))
|
||||
->will($this->returnValue(array('test')));
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
}
|
||||
|
@ -290,7 +291,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->willReturn(array('id' => 'test'));
|
||||
->willReturn(['id' => 'test']);
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -312,7 +313,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveMessage');
|
||||
|
@ -336,7 +337,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$row->expects($this->once())
|
||||
->method('getSourceIdValues')
|
||||
->will($this->returnValue(array('id' => 'test')));
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
|
@ -346,12 +347,12 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
|
||||
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
|
||||
$destination->expects($this->once())
|
||||
->method('import')
|
||||
->with($row, array('test'))
|
||||
->with($row, ['test'])
|
||||
->will($this->throwException(new \Exception($exception_message)));
|
||||
|
||||
$this->migration
|
||||
|
@ -360,15 +361,15 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveIdMapping')
|
||||
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
->with($row, [], MigrateIdMapInterface::STATUS_FAILED, NULL);
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->with(array('id' => 'test'))
|
||||
->will($this->returnValue(array('test')));
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
|
||||
$this->message->expects($this->once())
|
||||
->method('display')
|
||||
|
@ -381,15 +382,15 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
* Tests the processRow method.
|
||||
*/
|
||||
public function testProcessRow() {
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'test' => 'test destination',
|
||||
'test1' => 'test1 destination'
|
||||
);
|
||||
];
|
||||
foreach ($expected as $key => $value) {
|
||||
$plugins[$key][0] = $this->getMock('Drupal\migrate\Plugin\MigrateProcessInterface');
|
||||
$plugins[$key][0]->expects($this->once())
|
||||
->method('getPluginDefinition')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
$plugins[$key][0]->expects($this->once())
|
||||
->method('transform')
|
||||
->will($this->returnValue($value));
|
||||
|
@ -413,10 +414,29 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
$this->migration->expects($this->once())
|
||||
->method('getProcessPlugins')
|
||||
->with(NULL)
|
||||
->will($this->returnValue(array('test' => array())));
|
||||
->will($this->returnValue(['test' => []]));
|
||||
$row = new Row();
|
||||
$this->executable->processRow($row);
|
||||
$this->assertSame($row->getDestination(), array());
|
||||
$this->assertSame($row->getDestination(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the processRow pipeline exception.
|
||||
*/
|
||||
public function testProcessRowPipelineException() {
|
||||
$row = new Row();
|
||||
$plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$plugin->getPluginDefinition()->willReturn(['handle_multiples' => FALSE]);
|
||||
$plugin->transform(NULL, $this->executable, $row, 'destination_id')
|
||||
->willReturn('transform_return_string');
|
||||
$plugin->multiple()->willReturn(TRUE);
|
||||
$plugin->getPluginId()->willReturn('plugin_id');
|
||||
$plugin = $plugin->reveal();
|
||||
$plugins['destination_id'] = [$plugin, $plugin];
|
||||
$this->migration->method('getProcessPlugins')->willReturn($plugins);
|
||||
|
||||
$this->setExpectedException(MigrateException::class, 'Pipeline failed at plugin_id plugin for destination destination_id: transform_return_string received instead of an array,');
|
||||
$this->executable->processRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
|
|||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
||||
|
@ -149,10 +150,10 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*/
|
||||
public function testHighwaterTrackChangesIncompatible() {
|
||||
$source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']];
|
||||
$this->setExpectedException(MigrateException::class);
|
||||
$this->getSource($source_config);
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
$container = new ContainerBuilder();
|
||||
$cache = $this->getMock(CacheBackendInterface::class);
|
||||
$cache->expects($this->any())->method('set')
|
||||
->with($this->isType('string'), $this->isType('int'), $this->isType('int'));
|
||||
->with($this->isType('string'), $this->isType('int'), $this->isType('int'));
|
||||
$container->set('cache.migrate', $cache);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
|
@ -204,7 +205,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
$container = new ContainerBuilder();
|
||||
$cache = $this->getMock(CacheBackendInterface::class);
|
||||
$cache->expects($this->any())->method('set')
|
||||
->with('test_key', $this->isType('int'), $this->isType('int'));
|
||||
->with('test_key', $this->isType('int'), $this->isType('int'));
|
||||
$container->set('cache.migrate', $cache);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
|
|
|
@ -16,63 +16,70 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'sql_idmap_test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the ensureTables method when the tables do not exist.
|
||||
*/
|
||||
public function testEnsureTablesNotExist() {
|
||||
$fields['source_ids_hash'] = Array(
|
||||
$fields['source_ids_hash'] = [
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
);
|
||||
$fields['sourceid1'] = array(
|
||||
];
|
||||
$fields['sourceid1'] = [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$fields['destid1'] = array(
|
||||
];
|
||||
$fields['sourceid2'] = [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
];
|
||||
$fields['destid1'] = [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
$fields['source_row_status'] = array(
|
||||
];
|
||||
$fields['source_row_status'] = [
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
'description' => 'Indicates current status of the source row',
|
||||
);
|
||||
$fields['rollback_action'] = array(
|
||||
];
|
||||
$fields['rollback_action'] = [
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
'description' => 'Flag indicating what to do for this item on rollback',
|
||||
);
|
||||
$fields['last_imported'] = array(
|
||||
];
|
||||
$fields['last_imported'] = [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'UNIX timestamp of the last time this row was imported',
|
||||
);
|
||||
$fields['hash'] = array(
|
||||
];
|
||||
$fields['hash'] = [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Hash of source row data, for detecting changes',
|
||||
);
|
||||
$map_table_schema = array(
|
||||
];
|
||||
$map_table_schema = [
|
||||
'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
|
||||
'fields' => $fields,
|
||||
'primary key' => array('source_ids_hash'),
|
||||
);
|
||||
'primary key' => ['source_ids_hash'],
|
||||
'indexes' => [
|
||||
'source' => ['sourceid1', 'sourceid2'],
|
||||
],
|
||||
];
|
||||
$schema = $this->getMockBuilder('Drupal\Core\Database\Schema')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -84,34 +91,34 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
->method('createTable')
|
||||
->with('migrate_map_sql_idmap_test', $map_table_schema);
|
||||
// Now do the message table.
|
||||
$fields = array();
|
||||
$fields['msgid'] = array(
|
||||
$fields = [];
|
||||
$fields['msgid'] = [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$fields['source_ids_hash'] = Array(
|
||||
];
|
||||
$fields['source_ids_hash'] = [
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
);
|
||||
$fields['level'] = array(
|
||||
];
|
||||
$fields['level'] = [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 1,
|
||||
);
|
||||
$fields['message'] = array(
|
||||
];
|
||||
$fields['message'] = [
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
$table_schema = array(
|
||||
];
|
||||
$table_schema = [
|
||||
'description' => 'Messages generated during a migration process',
|
||||
'fields' => $fields,
|
||||
'primary key' => array('msgid'),
|
||||
);
|
||||
'primary key' => ['msgid'],
|
||||
];
|
||||
|
||||
$schema->expects($this->at(2))
|
||||
->method('tableExists')
|
||||
|
@ -140,14 +147,14 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
->method('fieldExists')
|
||||
->with('migrate_map_sql_idmap_test', 'rollback_action')
|
||||
->will($this->returnValue(FALSE));
|
||||
$field_schema = array(
|
||||
$field_schema = [
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Flag indicating what to do for this item on rollback',
|
||||
);
|
||||
];
|
||||
$schema->expects($this->at(2))
|
||||
->method('addField')
|
||||
->with('migrate_map_sql_idmap_test', 'rollback_action', $field_schema);
|
||||
|
@ -155,12 +162,12 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
->method('fieldExists')
|
||||
->with('migrate_map_sql_idmap_test', 'hash')
|
||||
->will($this->returnValue(FALSE));
|
||||
$field_schema = array(
|
||||
$field_schema = [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Hash of source row data, for detecting changes',
|
||||
);
|
||||
];
|
||||
$schema->expects($this->at(4))
|
||||
->method('addField')
|
||||
->with('migrate_map_sql_idmap_test', 'hash', $field_schema);
|
||||
|
@ -168,12 +175,12 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
->method('fieldExists')
|
||||
->with('migrate_map_sql_idmap_test', 'source_ids_hash')
|
||||
->will($this->returnValue(FALSE));
|
||||
$field_schema = array(
|
||||
$field_schema = [
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
);
|
||||
];
|
||||
$schema->expects($this->at(6))
|
||||
->method('addField')
|
||||
->with('migrate_map_sql_idmap_test', 'source_ids_hash', $field_schema);
|
||||
|
@ -201,28 +208,31 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
|||
$plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface');
|
||||
$plugin->expects($this->any())
|
||||
->method('getIds')
|
||||
->willReturn(array(
|
||||
'source_id_property' => array(
|
||||
->willReturn([
|
||||
'source_id_property' => [
|
||||
'type' => 'integer',
|
||||
),
|
||||
));
|
||||
],
|
||||
'source_id_property_2' => [
|
||||
'type' => 'integer',
|
||||
],
|
||||
]);
|
||||
$migration->expects($this->any())
|
||||
->method('getSourcePlugin')
|
||||
->willReturn($plugin);
|
||||
$plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface');
|
||||
$plugin->expects($this->any())
|
||||
->method('getIds')
|
||||
->willReturn(array(
|
||||
'destination_id_property' => array(
|
||||
->willReturn([
|
||||
'destination_id_property' => [
|
||||
'type' => 'string',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
$migration->expects($this->any())
|
||||
->method('getDestinationPlugin')
|
||||
->willReturn($plugin);
|
||||
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$map = new TestSqlIdMap($database, array(), 'sql', array(), $migration, $event_dispatcher);
|
||||
$map = new TestSqlIdMap($database, [], 'sql', [], $migration, $event_dispatcher);
|
||||
$map->getDatabase();
|
||||
}
|
||||
|
||||
|
|
|
@ -130,11 +130,11 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
* - hash
|
||||
*/
|
||||
protected function idMapDefaults() {
|
||||
$defaults = array(
|
||||
$defaults = [
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
'hash' => '',
|
||||
);
|
||||
];
|
||||
// By default, the PDO SQLite driver strongly prefers to return strings
|
||||
// from SELECT queries. Even for columns that don't store strings. Even
|
||||
// if the connection's STRINGIFY_FETCHES attribute is FALSE. This can cause
|
||||
|
@ -157,9 +157,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
* - updating work.
|
||||
*/
|
||||
public function testSaveIdMapping() {
|
||||
$source = array(
|
||||
$source = [
|
||||
'source_id_property' => 'source_value',
|
||||
);
|
||||
];
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$id_map = $this->getIdMap();
|
||||
$id_map->saveIdMapping($row, ['destination_id_property' => 2]);
|
||||
|
|
|
@ -33,7 +33,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $databaseContents = array();
|
||||
protected $databaseContents = [];
|
||||
|
||||
/**
|
||||
* The plugin class under test.
|
||||
|
@ -60,7 +60,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $expectedResults = array();
|
||||
protected $expectedResults = [];
|
||||
|
||||
/**
|
||||
* Expected count of source rows.
|
||||
|
@ -106,13 +106,16 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
|||
\Drupal::setContainer($container);
|
||||
|
||||
$migration = $this->getMigration();
|
||||
$migration->expects($this->any())
|
||||
->method('getHighWater')
|
||||
->will($this->returnValue(static::ORIGINAL_HIGH_WATER));
|
||||
|
||||
// Set the high water value.
|
||||
\Drupal::keyValue('migrate:high_water')
|
||||
->expects($this->any())
|
||||
->method('get')
|
||||
->willReturn(static::ORIGINAL_HIGH_WATER);
|
||||
|
||||
// Setup the plugin.
|
||||
$plugin_class = static::PLUGIN_CLASS;
|
||||
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration, $state, $entity_manager);
|
||||
$plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], [], $migration, $state, $entity_manager);
|
||||
|
||||
// Do some reflection to set the database and moduleHandler.
|
||||
$plugin_reflection = new \ReflectionClass($plugin);
|
||||
|
@ -122,7 +125,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
|||
$module_handler_property->setAccessible(TRUE);
|
||||
|
||||
// Set the database and the module handler onto our plugin.
|
||||
$database_property->setValue($plugin, $this->getDatabase($this->databaseContents + array('test_map' => array())));
|
||||
$database_property->setValue($plugin, $this->getDatabase($this->databaseContents + ['test_map' => []]));
|
||||
$module_handler_property->setValue($plugin, $module_handler);
|
||||
|
||||
$plugin->setStringTranslation($this->getStringTranslationStub());
|
||||
|
|
|
@ -27,9 +27,6 @@ class MigrationTest extends UnitTestCase {
|
|||
* Tests checking requirements for source plugins.
|
||||
*
|
||||
* @covers ::checkRequirements
|
||||
*
|
||||
* @expectedException \Drupal\migrate\Exception\RequirementsException
|
||||
* @expectedExceptionMessage Missing source requirement
|
||||
*/
|
||||
public function testRequirementsForSourcePlugin() {
|
||||
$migration = new TestMigration();
|
||||
|
@ -43,6 +40,7 @@ class MigrationTest extends UnitTestCase {
|
|||
$migration->setSourcePlugin($source_plugin);
|
||||
$migration->setDestinationPlugin($destination_plugin);
|
||||
|
||||
$this->setExpectedException(RequirementsException::class, 'Missing source requirement');
|
||||
$migration->checkRequirements();
|
||||
}
|
||||
|
||||
|
@ -50,9 +48,6 @@ class MigrationTest extends UnitTestCase {
|
|||
* Tests checking requirements for destination plugins.
|
||||
*
|
||||
* @covers ::checkRequirements
|
||||
*
|
||||
* @expectedException \Drupal\migrate\Exception\RequirementsException
|
||||
* @expectedExceptionMessage Missing destination requirement
|
||||
*/
|
||||
public function testRequirementsForDestinationPlugin() {
|
||||
$migration = new TestMigration();
|
||||
|
@ -66,6 +61,7 @@ class MigrationTest extends UnitTestCase {
|
|||
$migration->setSourcePlugin($source_plugin);
|
||||
$migration->setDestinationPlugin($destination_plugin);
|
||||
|
||||
$this->setExpectedException(RequirementsException::class, 'Missing destination requirement');
|
||||
$migration->checkRequirements();
|
||||
}
|
||||
|
||||
|
@ -73,9 +69,6 @@ class MigrationTest extends UnitTestCase {
|
|||
* Tests checking requirements for destination plugins.
|
||||
*
|
||||
* @covers ::checkRequirements
|
||||
*
|
||||
* @expectedException \Drupal\migrate\Exception\RequirementsException
|
||||
* @expectedExceptionMessage Missing migrations test_a, test_c
|
||||
*/
|
||||
public function testRequirementsForMigrations() {
|
||||
$migration = new TestMigration();
|
||||
|
@ -112,6 +105,7 @@ class MigrationTest extends UnitTestCase {
|
|||
->with(['test_a', 'test_b', 'test_c', 'test_d'])
|
||||
->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]);
|
||||
|
||||
$this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c');
|
||||
$migration->checkRequirements();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityManagerInterface;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
|
@ -84,8 +85,6 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
* Test row skipping when we can't get an entity to save.
|
||||
*
|
||||
* @covers ::import
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage Unable to get entity
|
||||
*/
|
||||
public function testImportEntityLoadFailure() {
|
||||
$bundles = [];
|
||||
|
@ -96,14 +95,12 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
|
||||
$destination->setEntity(FALSE);
|
||||
$this->setExpectedException(MigrateException::class, 'Unable to get entity');
|
||||
$destination->import(new Row());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that translation destination fails for untranslatable entities.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage This entity type does not support translation
|
||||
*/
|
||||
public function testUntranslatable() {
|
||||
// An entity type without a language.
|
||||
|
@ -125,6 +122,7 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
|
||||
);
|
||||
$this->setExpectedException(MigrateException::class, 'This entity type does not support translation');
|
||||
$destination->getIds();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,19 +17,19 @@ class RowTest extends UnitTestCase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $testSourceIds = array(
|
||||
protected $testSourceIds = [
|
||||
'nid' => 'Node ID',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The test values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $testValues = array(
|
||||
protected $testValues = [
|
||||
'nid' => 1,
|
||||
'title' => 'node 1',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The test hash.
|
||||
|
@ -50,7 +50,7 @@ class RowTest extends UnitTestCase {
|
|||
*/
|
||||
public function testRowWithoutData() {
|
||||
$row = new Row();
|
||||
$this->assertSame(array(), $row->getSource(), 'Empty row');
|
||||
$this->assertSame([], $row->getSource(), 'Empty row');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,28 +65,25 @@ class RowTest extends UnitTestCase {
|
|||
* Tests object creation: multiple source IDs.
|
||||
*/
|
||||
public function testRowWithMultipleSourceIds() {
|
||||
$multi_source_ids = $this->testSourceIds + array('vid' => 'Node revision');
|
||||
$multi_source_ids_values = $this->testValues + array('vid' => 1);
|
||||
$multi_source_ids = $this->testSourceIds + ['vid' => 'Node revision'];
|
||||
$multi_source_ids_values = $this->testValues + ['vid' => 1];
|
||||
$row = new Row($multi_source_ids_values, $multi_source_ids);
|
||||
$this->assertSame($multi_source_ids_values, $row->getSource(), 'Row with data, multifield id.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests object creation: invalid values.
|
||||
*
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testRowWithInvalidData() {
|
||||
$invalid_values = array(
|
||||
$invalid_values = [
|
||||
'title' => 'node X',
|
||||
);
|
||||
];
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$row = new Row($invalid_values, $this->testSourceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests source immutability after freeze.
|
||||
*
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testSourceFreeze() {
|
||||
$row = new Row($this->testValues, $this->testSourceIds);
|
||||
|
@ -96,18 +93,17 @@ class RowTest extends UnitTestCase {
|
|||
$row->rehash();
|
||||
$this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.');
|
||||
$row->freezeSource();
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$row->setSourceProperty('title', 'new title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting on a frozen row.
|
||||
*
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage The source is frozen and can't be changed any more
|
||||
*/
|
||||
public function testSetFrozenRow() {
|
||||
$row = new Row($this->testValues, $this->testSourceIds);
|
||||
$row->freezeSource();
|
||||
$this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more");
|
||||
$row->setSourceProperty('title', 'new title');
|
||||
}
|
||||
|
||||
|
@ -123,11 +119,11 @@ class RowTest extends UnitTestCase {
|
|||
$this->assertSame($this->testHash, $row->getHash(), 'Correct hash even doing it twice.');
|
||||
|
||||
// Set the map to needs update.
|
||||
$test_id_map = array(
|
||||
$test_id_map = [
|
||||
'original_hash' => '',
|
||||
'hash' => '',
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
);
|
||||
];
|
||||
$row->setIdMap($test_id_map);
|
||||
$this->assertTrue($row->needsUpdate());
|
||||
|
||||
|
@ -143,30 +139,30 @@ class RowTest extends UnitTestCase {
|
|||
$this->assertSame(64, strlen($row->getHash()));
|
||||
|
||||
// Set the map to successfully imported.
|
||||
$test_id_map = array(
|
||||
$test_id_map = [
|
||||
'original_hash' => '',
|
||||
'hash' => '',
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
);
|
||||
];
|
||||
$row->setIdMap($test_id_map);
|
||||
$this->assertFalse($row->needsUpdate());
|
||||
|
||||
// Set the same hash value and ensure it was not changed.
|
||||
$random = $this->randomMachineName();
|
||||
$test_id_map = array(
|
||||
$test_id_map = [
|
||||
'original_hash' => $random,
|
||||
'hash' => $random,
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
);
|
||||
];
|
||||
$row->setIdMap($test_id_map);
|
||||
$this->assertFalse($row->changed());
|
||||
|
||||
// Set different has values to ensure it is marked as changed.
|
||||
$test_id_map = array(
|
||||
$test_id_map = [
|
||||
'original_hash' => $this->randomMachineName(),
|
||||
'hash' => $this->randomMachineName(),
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
);
|
||||
];
|
||||
$row->setIdMap($test_id_map);
|
||||
$this->assertTrue($row->changed());
|
||||
}
|
||||
|
@ -179,11 +175,11 @@ class RowTest extends UnitTestCase {
|
|||
*/
|
||||
public function testGetSetIdMap() {
|
||||
$row = new Row($this->testValues, $this->testSourceIds);
|
||||
$test_id_map = array(
|
||||
$test_id_map = [
|
||||
'original_hash' => '',
|
||||
'hash' => '',
|
||||
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
);
|
||||
];
|
||||
$row->setIdMap($test_id_map);
|
||||
$this->assertEquals($test_id_map, $row->getIdMap());
|
||||
}
|
||||
|
@ -193,7 +189,7 @@ class RowTest extends UnitTestCase {
|
|||
*/
|
||||
public function testSourceIdValues() {
|
||||
$row = new Row($this->testValues, $this->testSourceIds);
|
||||
$this->assertSame(array('nid' => $this->testValues['nid']), $row->getSourceIdValues());
|
||||
$this->assertSame(['nid' => $this->testValues['nid']], $row->getSourceIdValues());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,7 +215,7 @@ class RowTest extends UnitTestCase {
|
|||
// Set a destination.
|
||||
$row->setDestinationProperty('nid', 2);
|
||||
$this->assertTrue($row->hasDestinationProperty('nid'));
|
||||
$this->assertEquals(array('nid' => 2), $row->getDestination());
|
||||
$this->assertEquals(['nid' => 2], $row->getDestination());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,21 +55,21 @@ class TestSqlIdMap extends Sql implements \Iterator {
|
|||
*/
|
||||
protected function getFieldSchema(array $id_definition) {
|
||||
if (!isset($id_definition['type'])) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
switch ($id_definition['type']) {
|
||||
case 'integer':
|
||||
return array(
|
||||
return [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
case 'string':
|
||||
return array(
|
||||
return [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
default:
|
||||
throw new MigrateException($id_definition['type'] . ' not supported');
|
||||
|
|
|
@ -16,9 +16,9 @@ class ConfigTest extends UnitTestCase {
|
|||
* Test the import method.
|
||||
*/
|
||||
public function testImport() {
|
||||
$source = array(
|
||||
$source = [
|
||||
'test' => 'x',
|
||||
);
|
||||
];
|
||||
$migration = $this->getMockBuilder('Drupal\migrate\Plugin\Migration')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -54,7 +54,7 @@ class ConfigTest extends UnitTestCase {
|
|||
->method('getLanguageConfigOverride')
|
||||
->with('fr', 'd8_config')
|
||||
->will($this->returnValue($config));
|
||||
$destination = new Config(array('config_name' => 'd8_config'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory, $language_manager);
|
||||
$destination = new Config(['config_name' => 'd8_config'], 'd8_config', ['pluginId' => 'd8_config'], $migration, $config_factory, $language_manager);
|
||||
$destination_id = $destination->import($row);
|
||||
$this->assertEquals($destination_id, ['d8_config']);
|
||||
}
|
||||
|
@ -63,9 +63,9 @@ class ConfigTest extends UnitTestCase {
|
|||
* Test the import method.
|
||||
*/
|
||||
public function testLanguageImport() {
|
||||
$source = array(
|
||||
$source = [
|
||||
'langcode' => 'mi',
|
||||
);
|
||||
];
|
||||
$migration = $this->getMockBuilder(MigrationInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -104,7 +104,7 @@ class ConfigTest extends UnitTestCase {
|
|||
->method('getLanguageConfigOverride')
|
||||
->with('mi', 'd8_config')
|
||||
->will($this->returnValue($config));
|
||||
$destination = new Config(array('config_name' => 'd8_config', 'translations' => 'true'), 'd8_config', array('pluginId' => 'd8_config'), $migration, $config_factory, $language_manager);
|
||||
$destination = new Config(['config_name' => 'd8_config', 'translations' => 'true'], 'd8_config', ['pluginId' => 'd8_config'], $migration, $config_factory, $language_manager);
|
||||
$destination_id = $destination->import($row);
|
||||
$this->assertEquals($destination_id, ['d8_config', 'mi']);
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ class EntityRevision extends RealEntityRevision {
|
|||
/**
|
||||
* Allow public access for testing.
|
||||
*/
|
||||
public function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
|
||||
public function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
|
||||
return parent::save($entity, $old_destination_id_values);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
|||
* Tests the entity display import method.
|
||||
*/
|
||||
public function testImport() {
|
||||
$values = array(
|
||||
$values = [
|
||||
'entity_type' => 'entity_type_test',
|
||||
'bundle' => 'bundle_test',
|
||||
'view_mode' => 'view_mode_test',
|
||||
'field_name' => 'field_name_test',
|
||||
'options' => array('test setting'),
|
||||
);
|
||||
'options' => ['test setting'],
|
||||
];
|
||||
$row = new Row();
|
||||
foreach ($values as $key => $value) {
|
||||
$row->setDestinationProperty($key, $value);
|
||||
|
@ -38,14 +38,14 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
|||
->getMock();
|
||||
$entity->expects($this->once())
|
||||
->method('setComponent')
|
||||
->with('field_name_test', array('test setting'))
|
||||
->with('field_name_test', ['test setting'])
|
||||
->will($this->returnSelf());
|
||||
$entity->expects($this->once())
|
||||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), array('entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test'));
|
||||
$this->assertSame($plugin->getTestValues(), array('entity_type_test', 'bundle_test', 'view_mode_test'));
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'view_mode_test']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
|||
* Tests the entity display import method.
|
||||
*/
|
||||
public function testImport() {
|
||||
$values = array(
|
||||
$values = [
|
||||
'entity_type' => 'entity_type_test',
|
||||
'bundle' => 'bundle_test',
|
||||
'form_mode' => 'form_mode_test',
|
||||
'field_name' => 'field_name_test',
|
||||
'options' => array('test setting'),
|
||||
);
|
||||
'options' => ['test setting'],
|
||||
];
|
||||
$row = new Row();
|
||||
foreach ($values as $key => $value) {
|
||||
$row->setDestinationProperty($key, $value);
|
||||
|
@ -38,14 +38,14 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
|||
->getMock();
|
||||
$entity->expects($this->once())
|
||||
->method('setComponent')
|
||||
->with('field_name_test', array('test setting'))
|
||||
->with('field_name_test', ['test setting'])
|
||||
->will($this->returnSelf());
|
||||
$entity->expects($this->once())
|
||||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityFormDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), array('entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test'));
|
||||
$this->assertSame($plugin->getTestValues(), array('entity_type_test', 'bundle_test', 'form_mode_test'));
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'form_mode_test']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class CallbackTest extends MigrateProcessTestCase {
|
|||
* Test callback with a class method as callable.
|
||||
*/
|
||||
public function testCallbackWithClassMethod() {
|
||||
$this->plugin->setCallable(array('\Drupal\Component\Utility\Unicode', 'strtolower'));
|
||||
$this->plugin->setCallable(['\Drupal\Component\Utility\Unicode', 'strtolower']);
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Concat;
|
||||
|
||||
/**
|
||||
|
@ -28,16 +29,15 @@ class ConcatTest extends MigrateProcessTestCase {
|
|||
* Test concat works without a delimiter.
|
||||
*/
|
||||
public function testConcatWithoutDelimiter() {
|
||||
$value = $this->plugin->transform(array('foo', 'bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test concat fails properly on non-arrays.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*/
|
||||
public function testConcatWithNonArray() {
|
||||
$this->setExpectedException(MigrateException::class);
|
||||
$this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class ConcatTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testConcatWithDelimiter() {
|
||||
$this->plugin->setDelimiter('_');
|
||||
$value = $this->plugin->transform(array('foo', 'bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foo_bar');
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\DedupeEntity;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
@ -21,20 +23,20 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* The mock entity query factory.
|
||||
* The mocked entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The migration configuration, initialized to set the ID to test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -43,12 +45,16 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
$this->entityQuery = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->entityQueryFactory = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->entityQueryFactory->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($this->entityQuery));
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
|
||||
$storage = $this->getMock(EntityStorageInterface::class);
|
||||
$storage->expects($this->any())
|
||||
->method('getQuery')
|
||||
->willReturn($this->entityQuery);
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('test_entity_type')
|
||||
->willReturn($storage);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -58,16 +64,16 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* @dataProvider providerTestDedupe
|
||||
*/
|
||||
public function testDedupe($count, $postfix = '', $start = NULL, $length = NULL) {
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'entity_type' => 'test_entity_type',
|
||||
'field' => 'test_field',
|
||||
);
|
||||
];
|
||||
if ($postfix) {
|
||||
$configuration['postfix'] = $postfix;
|
||||
}
|
||||
$configuration['start'] = isset($start) ? $start : NULL;
|
||||
$configuration['length'] = isset($length) ? $length : NULL;
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
|
||||
$this->entityQueryExpects($count);
|
||||
$value = $this->randomMachineName(32);
|
||||
$actual = $plugin->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
|
||||
|
@ -80,12 +86,12 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* Tests that invalid start position throws an exception.
|
||||
*/
|
||||
public function testDedupeEntityInvalidStart() {
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'entity_type' => 'test_entity_type',
|
||||
'field' => 'test_field',
|
||||
'start' => 'foobar',
|
||||
);
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
|
||||
];
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
|
||||
$this->setExpectedException('Drupal\migrate\MigrateException', 'The start position configuration key should be an integer. Omit this key to capture from the beginning of the string.');
|
||||
$plugin->transform('test_start', $this->migrateExecutable, $this->row, 'testproperty');
|
||||
}
|
||||
|
@ -94,12 +100,12 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* Tests that invalid length option throws an exception.
|
||||
*/
|
||||
public function testDedupeEntityInvalidLength() {
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'entity_type' => 'test_entity_type',
|
||||
'field' => 'test_field',
|
||||
'length' => 'foobar',
|
||||
);
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
|
||||
];
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
|
||||
$this->setExpectedException('Drupal\migrate\MigrateException', 'The character length configuration key should be an integer. Omit this key to capture the entire string.');
|
||||
$plugin->transform('test_length', $this->migrateExecutable, $this->row, 'testproperty');
|
||||
}
|
||||
|
@ -108,40 +114,40 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* Data provider for testDedupe().
|
||||
*/
|
||||
public function providerTestDedupe() {
|
||||
return array(
|
||||
return [
|
||||
// Tests no duplication.
|
||||
array(0),
|
||||
[0],
|
||||
// Tests no duplication and start position.
|
||||
array(0, NULL, 10),
|
||||
[0, NULL, 10],
|
||||
// Tests no duplication, start position, and length.
|
||||
array(0, NULL, 5, 10),
|
||||
[0, NULL, 5, 10],
|
||||
// Tests no duplication and length.
|
||||
array(0, NULL, NULL, 10),
|
||||
[0, NULL, NULL, 10],
|
||||
// Tests duplication.
|
||||
array(3),
|
||||
[3],
|
||||
// Tests duplication and start position.
|
||||
array(3, NULL, 10),
|
||||
[3, NULL, 10],
|
||||
// Tests duplication, start position, and length.
|
||||
array(3, NULL, 5, 10),
|
||||
[3, NULL, 5, 10],
|
||||
// Tests duplication and length.
|
||||
array(3, NULL, NULL, 10),
|
||||
[3, NULL, NULL, 10],
|
||||
// Tests no duplication and postfix.
|
||||
array(0, '_'),
|
||||
[0, '_'],
|
||||
// Tests no duplication, postfix, and start position.
|
||||
array(0, '_', 5),
|
||||
[0, '_', 5],
|
||||
// Tests no duplication, postfix, start position, and length.
|
||||
array(0, '_', 5, 10),
|
||||
[0, '_', 5, 10],
|
||||
// Tests no duplication, postfix, and length.
|
||||
array(0, '_', NULL, 10),
|
||||
[0, '_', NULL, 10],
|
||||
// Tests duplication and postfix.
|
||||
array(2, '_'),
|
||||
[2, '_'],
|
||||
// Tests duplication, postfix, and start position.
|
||||
array(2, '_', 5),
|
||||
[2, '_', 5],
|
||||
// Tests duplication, postfix, start position, and length.
|
||||
array(2, '_', 5, 10),
|
||||
[2, '_', 5, 10],
|
||||
// Tests duplication, postfix, and length.
|
||||
array(2, '_', NULL, 10),
|
||||
);
|
||||
[2, '_', NULL, 10],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,12 +172,12 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* Test deduplicating only migrated entities.
|
||||
*/
|
||||
public function testDedupeMigrated() {
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'entity_type' => 'test_entity_type',
|
||||
'field' => 'test_field',
|
||||
'migrated' => TRUE,
|
||||
);
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
|
||||
];
|
||||
$plugin = new DedupeEntity($configuration, 'dedupe_entity', [], $this->getMigration(), $this->entityTypeManager);
|
||||
|
||||
// Setup the entityQuery used in DedupeEntity::exists. The map, $map, is
|
||||
// an array consisting of the four input parameters to the query condition
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Explode;
|
||||
use Drupal\migrate\Plugin\migrate\process\Concat;
|
||||
|
||||
|
@ -53,23 +54,65 @@ class ExplodeTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* Test explode fails properly on non-strings.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage is not a string
|
||||
*/
|
||||
public function testExplodeWithNonString() {
|
||||
$this->setExpectedException(MigrateException::class, 'is not a string');
|
||||
$this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that explode works on non-strings but with strict set to FALSE.
|
||||
*
|
||||
* @dataProvider providerExplodeWithNonStrictAndEmptySource
|
||||
*/
|
||||
public function testExplodeWithNonStrictAndEmptySource($value, $expected) {
|
||||
$plugin = new Explode(['delimiter' => '|', 'strict' => FALSE], 'map', []);
|
||||
|
||||
$processed = $plugin->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($expected, $processed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for ::testExplodeWithNonStrictAndEmptySource().
|
||||
*/
|
||||
public function providerExplodeWithNonStrictAndEmptySource() {
|
||||
return [
|
||||
'normal_string' => ['a|b|c', ['a', 'b', 'c']],
|
||||
'integer_cast_to_string' => [123, ['123']],
|
||||
'zero_integer_cast_to_string' => [0, ['0']],
|
||||
'true_cast_to_string' => [TRUE, ['1']],
|
||||
'null_empty_array' => [NULL, []],
|
||||
'false_empty_array' => [FALSE, []],
|
||||
'empty_string_empty_array' => ['', []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that explode raises an exception when the value cannot be casted to
|
||||
* string.
|
||||
*/
|
||||
public function testExplodeWithNonStrictAndNonCastable() {
|
||||
$plugin = new Explode(['delimiter' => '|', 'strict' => FALSE], 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'cannot be casted to a string');
|
||||
$processed = $plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame(['foo'], $processed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that explode with an empty string and strict check returns a
|
||||
* non-empty array.
|
||||
*/
|
||||
public function testExplodeWithStrictAndEmptyString() {
|
||||
$plugin = new Explode(['delimiter' => '|'], 'map', []);
|
||||
$processed = $plugin->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame([''], $processed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test explode fails with empty delimiter.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage delimiter is empty
|
||||
*/
|
||||
public function testExplodeWithEmptyDelimiter() {
|
||||
$this->setExpectedException(MigrateException::class, 'delimiter is empty');
|
||||
$plugin = new Explode(['delimiter' => ''], 'map', []);
|
||||
$plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Extract;
|
||||
|
||||
/**
|
||||
|
@ -14,8 +15,8 @@ class ExtractTest extends MigrateProcessTestCase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$configuration['index'] = array('foo');
|
||||
$this->plugin = new Extract($configuration, 'map', array());
|
||||
$configuration['index'] = ['foo'];
|
||||
$this->plugin = new Extract($configuration, 'map', []);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -23,28 +24,24 @@ class ExtractTest extends MigrateProcessTestCase {
|
|||
* Tests successful extraction.
|
||||
*/
|
||||
public function testExtract() {
|
||||
$value = $this->plugin->transform(array('foo' => 'bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$value = $this->plugin->transform(['foo' => 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests invalid input.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage Input should be an array.
|
||||
*/
|
||||
public function testExtractFromString() {
|
||||
$this->setExpectedException(MigrateException::class, 'Input should be an array.');
|
||||
$this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unsuccessful extraction.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage Array index missing, extraction failed.
|
||||
*/
|
||||
public function testExtractFail() {
|
||||
$this->plugin->transform(array('bar' => 'foo'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.');
|
||||
$this->plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,9 +15,9 @@ class FlattenTest extends MigrateProcessTestCase {
|
|||
* Test that various array flatten operations work properly.
|
||||
*/
|
||||
public function testFlatten() {
|
||||
$plugin = new Flatten(array(), 'flatten', array());
|
||||
$flattened = $plugin->transform(array(1, 2, array(3, 4, array(5)), array(), array(7, 8)), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($flattened, array(1, 2, 3, 4, 5, 7, 8));
|
||||
$plugin = new Flatten([], 'flatten', []);
|
||||
$flattened = $plugin->transform([1, 2, [3, 4, [5]], [], [7, 8]], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($flattened, [1, 2, 3, 4, 5, 7, 8]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,16 +41,16 @@ class GetTest extends MigrateProcessTestCase {
|
|||
* Tests the Get plugin when source is an array.
|
||||
*/
|
||||
public function testTransformSourceArray() {
|
||||
$map = array(
|
||||
$map = [
|
||||
'test1' => 'source_value1',
|
||||
'test2' => 'source_value2',
|
||||
);
|
||||
$this->plugin->setSource(array('test1', 'test2'));
|
||||
];
|
||||
$this->plugin->setSource(['test1', 'test2']);
|
||||
$this->row->expects($this->exactly(2))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } ));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, array('source_value1', 'source_value2'));
|
||||
$this->assertSame($value, ['source_value1', 'source_value2']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,18 +70,18 @@ class GetTest extends MigrateProcessTestCase {
|
|||
* Tests the Get plugin when source is an array pointing to destination.
|
||||
*/
|
||||
public function testTransformSourceArrayAt() {
|
||||
$map = array(
|
||||
$map = [
|
||||
'test1' => 'source_value1',
|
||||
'@test2' => 'source_value2',
|
||||
'@test3' => 'source_value3',
|
||||
'test4' => 'source_value4',
|
||||
);
|
||||
$this->plugin->setSource(array('test1', '@@test2', '@@test3', 'test4'));
|
||||
];
|
||||
$this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']);
|
||||
$this->row->expects($this->exactly(4))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) { return $map[$argument]; } ));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, array('source_value1', 'source_value2', 'source_value3', 'source_value4'));
|
||||
$this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,9 +25,9 @@ class IteratorTest extends MigrateTestCase {
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the iterator process plugin.
|
||||
|
@ -35,24 +35,24 @@ class IteratorTest extends MigrateTestCase {
|
|||
public function testIterator() {
|
||||
$migration = $this->getMigration();
|
||||
// Set up the properties for the iterator.
|
||||
$configuration = array(
|
||||
'process' => array(
|
||||
$configuration = [
|
||||
'process' => [
|
||||
'foo' => 'source_foo',
|
||||
'id' => 'source_id',
|
||||
),
|
||||
],
|
||||
'key' => '@id',
|
||||
);
|
||||
$plugin = new Iterator($configuration, 'iterator', array());
|
||||
];
|
||||
$plugin = new Iterator($configuration, 'iterator', []);
|
||||
// Manually create the plugins. Migration::getProcessPlugins does this
|
||||
// normally but the plugin system is not available.
|
||||
foreach ($configuration['process'] as $destination => $source) {
|
||||
$iterator_plugins[$destination][] = new Get(array('source' => $source), 'get', array());
|
||||
$iterator_plugins[$destination][] = new Get(['source' => $source], 'get', []);
|
||||
}
|
||||
$migration->expects($this->at(1))
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue($iterator_plugins));
|
||||
// Set up the key plugins.
|
||||
$key_plugin['key'][] = new Get(array('source' => '@id'), 'get', array());
|
||||
$key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
|
||||
$migration->expects($this->at(2))
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue($key_plugin));
|
||||
|
@ -60,12 +60,12 @@ class IteratorTest extends MigrateTestCase {
|
|||
$migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
|
||||
|
||||
// The current value of the pipeline.
|
||||
$current_value = array(
|
||||
array(
|
||||
$current_value = [
|
||||
[
|
||||
'source_foo' => 'test',
|
||||
'source_id' => 42,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// This is not used but the interface requires it, so create an empty row.
|
||||
$row = new Row();
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class MachineNameTest extends MigrateProcessTestCase {
|
|||
->with($human_name)
|
||||
->will($this->returnValue($human_name_ascii . 'aeo'));
|
||||
|
||||
$plugin = new MachineName(array(), 'machine_name', array(), $this->transliteration);
|
||||
$plugin = new MachineName([], 'machine_name', [], $this->transliteration);
|
||||
$value = $plugin->transform($human_name, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertEquals($expected_result, $value);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\migrate\MigrateSkipProcessException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\Migration;
|
||||
use Drupal\migrate\Plugin\MigrateDestinationInterface;
|
||||
|
@ -89,8 +90,6 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* Tests that processing is skipped when the input value is empty.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateSkipProcessException
|
||||
*/
|
||||
public function testSkipOnEmpty() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
|
@ -102,6 +101,7 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
];
|
||||
$migration_plugin->id()->willReturn(uniqid());
|
||||
$migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
use Drupal\migrate\MigrateSkipProcessException;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\process\SkipOnEmpty;
|
||||
|
||||
/**
|
||||
|
@ -13,10 +15,10 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::process
|
||||
* @expectedException \Drupal\migrate\MigrateSkipProcessException
|
||||
*/
|
||||
public function testProcessSkipsOnEmpty() {
|
||||
$configuration['method'] = 'process';
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
(new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
@ -33,10 +35,10 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::row
|
||||
* @expectedException \Drupal\migrate\MigrateSkipRowException
|
||||
*/
|
||||
public function testRowSkipsOnEmpty() {
|
||||
$configuration['method'] = 'row';
|
||||
$this->setExpectedException(MigrateSkipRowException::class);
|
||||
(new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\process\StaticMap;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +18,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
$configuration['map']['foo']['bar'] = 'baz';
|
||||
$this->plugin = new StaticMap($configuration, 'map', array());
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -25,33 +27,31 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testMapWithSourceString() {
|
||||
$value = $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, array('bar' => 'baz'));
|
||||
$this->assertSame($value, ['bar' => 'baz']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests map when the source is a list.
|
||||
*/
|
||||
public function testMapWithSourceList() {
|
||||
$value = $this->plugin->transform(array('foo', 'bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when the source is empty.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*/
|
||||
public function testMapwithEmptySource() {
|
||||
$this->plugin->transform(array(), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->setExpectedException(MigrateException::class);
|
||||
$this->plugin->transform([], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when the source is invalid.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateSkipRowException
|
||||
*/
|
||||
public function testMapwithInvalidSource() {
|
||||
$this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->setExpectedException(MigrateSkipRowException::class);
|
||||
$this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,8 +60,8 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
public function testMapWithInvalidSourceWithADefaultValue() {
|
||||
$configuration['map']['foo']['bar'] = 'baz';
|
||||
$configuration['default_value'] = 'test';
|
||||
$this->plugin = new StaticMap($configuration, 'map', array());
|
||||
$value = $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
$value = $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test');
|
||||
}
|
||||
|
||||
|
@ -72,22 +72,20 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
$configuration['map']['foo']['bar'] = 'baz';
|
||||
$configuration['default_value'] = NULL;
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
$value = $this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$value = $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertNull($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when the source is invalid and bypass is enabled.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage Setting both default_value and bypass is invalid.
|
||||
*/
|
||||
public function testMapWithInvalidSourceAndBypass() {
|
||||
$configuration['map']['foo']['bar'] = 'baz';
|
||||
$configuration['default_value'] = 'test';
|
||||
$configuration['bypass'] = TRUE;
|
||||
$this->plugin = new StaticMap($configuration, 'map', array());
|
||||
$this->plugin->transform(array('bar'), $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.');
|
||||
$this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Substr;
|
||||
|
||||
/**
|
||||
|
@ -55,37 +56,31 @@ class SubstrTest extends MigrateProcessTestCase {
|
|||
|
||||
/**
|
||||
* Tests invalid input type.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The input value must be a string.
|
||||
*/
|
||||
public function testSubstrFail() {
|
||||
$configuration = [];
|
||||
$this->plugin = new Substr($configuration, 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The input value must be a string.');
|
||||
$this->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the start parameter is an integer.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.
|
||||
*/
|
||||
public function testStartIsString() {
|
||||
$configuration['start'] = '2';
|
||||
$this->plugin = new Substr($configuration, 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.');
|
||||
$this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the length parameter is an integer.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
* @expectedExceptionMessage The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.
|
||||
*/
|
||||
public function testLengthIsString() {
|
||||
$configuration['length'] = '1';
|
||||
$this->plugin = new Substr($configuration, 'map', []);
|
||||
$this->setExpectedException(MigrateException::class, 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.');
|
||||
$this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
|
|
|
@ -28,14 +28,14 @@ class UrlEncodeTest extends MigrateTestCase {
|
|||
* An array of URLs to test.
|
||||
*/
|
||||
public function urlDataProvider() {
|
||||
return array(
|
||||
'A URL with no characters requiring encoding' => array('http://example.com/normal_url.html', 'http://example.com/normal_url.html'),
|
||||
'The definitive use case - encoding spaces in URLs' => array('http://example.com/url with spaces.html', 'http://example.com/url%20with%20spaces.html'),
|
||||
'Definitive use case 2 - spaces in directories' => array('http://example.com/dir with spaces/foo.html', 'http://example.com/dir%20with%20spaces/foo.html'),
|
||||
'Local filespecs without spaces should not be transformed' => array('/tmp/normal.txt', '/tmp/normal.txt'),
|
||||
'Local filespecs with spaces should not be transformed' => array('/tmp/with spaces.txt', '/tmp/with spaces.txt'),
|
||||
'Make sure URL characters (:, ?, &) are not encoded but others are.' => array('https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'),
|
||||
);
|
||||
return [
|
||||
'A URL with no characters requiring encoding' => ['http://example.com/normal_url.html', 'http://example.com/normal_url.html'],
|
||||
'The definitive use case - encoding spaces in URLs' => ['http://example.com/url with spaces.html', 'http://example.com/url%20with%20spaces.html'],
|
||||
'Definitive use case 2 - spaces in directories' => ['http://example.com/dir with spaces/foo.html', 'http://example.com/dir%20with%20spaces/foo.html'],
|
||||
'Local filespecs without spaces should not be transformed' => ['/tmp/normal.txt', '/tmp/normal.txt'],
|
||||
'Local filespecs with spaces should not be transformed' => ['/tmp/with spaces.txt', '/tmp/with spaces.txt'],
|
||||
'Make sure URL characters (:, ?, &) are not encoded but others are.' => ['https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue