Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -14,10 +14,10 @@ class MigrateMessage implements MigrateMessageInterface {
*
* @var array
*/
protected $map = array(
protected $map = [
'status' => RfcLogLevel::INFO,
'error' => RfcLogLevel::ERROR,
);
];
/**
* {@inheritdoc}

View file

@ -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;
}

View file

@ -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;

View file

@ -73,7 +73,7 @@ class AnnotatedClassDiscoveryAutomatedProviders extends AnnotatedClassDiscovery
* {@inheritdoc}
*/
public function getDefinitions() {
$definitions = array();
$definitions = [];
$reader = $this->getAnnotationReader();

View file

@ -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.
*/

View file

@ -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.

View file

@ -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';
}

View file

@ -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.

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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.

View file

@ -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']);

View file

@ -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());
}

View file

@ -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]);
}
}
}

View file

@ -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()];
}
/**

View file

@ -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));
}
}

View file

@ -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]);
}
}

View file

@ -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()];
}
/**

View file

@ -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]);
}
}

View file

@ -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 = []) {
}
}

View file

@ -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.

View file

@ -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"

View file

@ -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)) {

View file

@ -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.

View file

@ -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"

View file

@ -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"

View file

@ -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);
}
/**

View file

@ -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",

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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');
}

View file

@ -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"

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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) {

View file

@ -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",

View file

@ -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) {

View file

@ -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"

View file

@ -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.

View file

@ -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' => '']]);
}
/**

View file

@ -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();

View file

@ -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;

View file

@ -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.