Update to Drupal 8.0.5. For more information, see https://www.drupal.org/node/2679347

This commit is contained in:
Pantheon Automation 2016-03-02 12:40:24 -08:00 committed by Greg Anderson
parent 2a9f1f148d
commit fd3b12cf27
251 changed files with 5439 additions and 957 deletions

View file

@ -112,7 +112,7 @@ abstract class Entity extends DestinationBase implements ContainerFactoryPluginI
* The entity we are importing into.
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
$entity_id = $old_destination_id_values ? reset($old_destination_id_values) : $this->getEntityId($row);
$entity_id = reset($old_destination_id_values) ?: $this->getEntityId($row);
if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) {
$this->updateEntity($entity, $row);
}

View file

@ -33,6 +33,11 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryPluginInterface {
/**
* Column name of hashed source id values.
*/
const SOURCE_IDS_HASH = 'source_ids_hash';
/**
* An event dispatcher instance to use for map events.
*
@ -171,6 +176,34 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
);
}
/**
* Retrieves the hash of the source identifier values.
*
* It is public only for testing purposes.
*
* @param array $source_id_values
* The source identifiers
*
* @return string
* An hash containing the hashed values of the source identifiers.
*/
public function getSourceIDsHash(array $source_id_values) {
// When looking up the destination ID we require an array with both the
// source key and value, e.g. ['nid' => 41]. In this case, $source_id_values
// need to be ordered the same order as $this->sourceIdFields().
// However, the Migration process plugin doesn't currently have a way to get
// the source key so we presume the values have been passed through in the
// correct order.
if (!isset($source_id_values[0])) {
$source_id_values_keyed = [];
foreach ($this->sourceIdFields() as $field_name => $source_id) {
$source_id_values_keyed[] = $source_id_values[$field_name];
}
$source_id_values = $source_id_values_keyed;
}
return hash('sha256', serialize(array_map('strval', $source_id_values)));
}
/**
* The source ID fields.
*
@ -285,28 +318,25 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
// and map from the source field names to the map/msg field names.
$count = 1;
$source_id_schema = array();
$pks = array();
foreach ($this->migration->getSourcePlugin()->getIds() as $id_definition) {
$mapkey = 'sourceid' . $count++;
$source_id_schema[$mapkey] = $this->getFieldSchema($id_definition);
$source_id_schema[$mapkey]['not null'] = TRUE;
// With InnoDB, utf8mb4-based primary keys can't be over 191 characters.
// Use ASCII-based primary keys instead.
if (isset($source_id_schema[$mapkey]['type']) && $source_id_schema[$mapkey]['type'] == 'varchar') {
$source_id_schema[$mapkey]['type'] = 'varchar_ascii';
}
$pks[] = $mapkey;
}
$fields = $source_id_schema;
$source_ids_hash[static::SOURCE_IDS_HASH] = array(
'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.
// @todo How do we discover the destination schema?
$count = 1;
foreach ($this->migration->getDestinationPlugin()->getIds() as $id_definition) {
// Allow dest identifier fields to be NULL (for IGNORED/FAILED
// cases).
// Allow dest identifier fields to be NULL (for IGNORED/FAILED cases).
$mapkey = 'destid' . $count++;
$fields[$mapkey] = $this->getFieldSchema($id_definition);
$fields[$mapkey]['not null'] = FALSE;
@ -343,10 +373,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
$schema = array(
'description' => 'Mappings from source identifier value(s) to destination identifier value(s).',
'fields' => $fields,
'primary key' => array(static::SOURCE_IDS_HASH),
);
if ($pks) {
$schema['primary key'] = $pks;
}
$this->getDatabase()->schema()->createTable($this->mapTableName, $schema);
// Now do the message table.
@ -357,7 +385,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
'unsigned' => TRUE,
'not null' => TRUE,
);
$fields += $source_id_schema;
$fields += $source_ids_hash;
$fields['level'] = array(
'type' => 'int',
@ -375,9 +403,6 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
'fields' => $fields,
'primary key' => array('msgid'),
);
if ($pks) {
$schema['indexes']['sourcekey'] = $pks;
}
$this->getDatabase()->schema()->createTable($this->messageTableName(), $schema);
}
}
@ -406,6 +431,14 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
)
);
}
if (!$this->getDatabase()->schema()->fieldExists($this->mapTableName, static::SOURCE_IDS_HASH)) {
$this->getDatabase()->schema()->addField($this->mapTableName, static::SOURCE_IDS_HASH, array(
'type' => 'varchar',
'length' => '64',
'not null' => TRUE,
'description' => 'Hash of source ids. Used as primary key',
));
}
}
}
@ -435,9 +468,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
public function getRowBySource(array $source_id_values) {
$query = $this->getDatabase()->select($this->mapTableName(), 'map')
->fields('map');
foreach ($this->sourceIdFields() as $field_name => $source_id) {
$query->condition("map.$source_id", $source_id_values[$field_name], '=');
}
$query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
$result = $query->execute();
return $result->fetchAssoc();
}
@ -497,14 +528,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
$query = $this->getDatabase()->select($this->mapTableName(), 'map')
->fields('map', $this->destinationIdFields());
// When looking up the destination ID we require an array with both the
// source key and value, e.g. ['nid' => 41]. However, the Migration process
// plugin doesn't currently have a way to get the source key so we presume
// the values have been passed through in the correct order.
$have_keys = !isset($source_id_values[0]);
foreach ($this->sourceIdFields() as $field_name => $source_id) {
$query->condition("map.$source_id", $have_keys ? $source_id_values[$field_name] : array_shift($source_id_values), '=');
}
$query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
$result = $query->execute();
$destination_id = $result->fetchAssoc();
return array_values($destination_id ?: array());
@ -517,19 +541,23 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
// Construct the source key.
$source_id_values = $row->getSourceIdValues();
// Construct the source key and initialize to empty variable keys.
$keys = array();
$fields = [];
foreach ($this->sourceIdFields() as $field_name => $key_name) {
// A NULL key value will fail.
// A NULL key value is usually an indication of a problem.
if (!isset($source_id_values[$field_name])) {
$this->message->display(t(
'Could not save to map table due to NULL value for key field @field',
$this->message->display($this->t(
'Did not save to map table due to NULL value for key field @field',
array('@field' => $field_name)), 'error');
return;
}
$keys[$key_name] = $source_id_values[$field_name];
$fields[$key_name] = $source_id_values[$field_name];
}
$fields = array(
if (!$fields) {
return;
}
$fields += array(
'source_row_status' => (int) $source_row_status,
'rollback_action' => (int) $rollback_action,
'hash' => $row->getHash(),
@ -545,14 +573,13 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
if ($this->migration->get('trackLastImported')) {
$fields['last_imported'] = time();
}
if ($keys) {
// Notify anyone listening of the map row we're about to save.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $keys + $fields));
$this->getDatabase()->merge($this->mapTableName())
->key($keys)
->fields($fields)
->execute();
}
$keys = [static::SOURCE_IDS_HASH => $this->getSourceIDsHash($source_id_values)];
// Notify anyone listening of the map row we're about to save.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $fields));
$this->getDatabase()->merge($this->mapTableName())
->key($keys)
->fields($fields)
->execute();
}
/**
@ -564,8 +591,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
if (!isset($source_id_values[$field_name])) {
return;
}
$fields[$source_id] = $source_id_values[$field_name];
}
$fields[static::SOURCE_IDS_HASH] = $this->getSourceIDsHash($source_id_values);
$fields['level'] = $level;
$fields['message'] = $message;
$this->getDatabase()->insert($this->messageTableName())
@ -583,10 +610,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
public function getMessageIterator(array $source_id_values = [], $level = NULL) {
$query = $this->getDatabase()->select($this->messageTableName(), 'msg')
->fields('msg');
foreach ($this->sourceIdFields() as $field_name => $source_id) {
if (isset($source_id_values[$field_name])) {
$query->condition($source_id, $source_id_values[$field_name]);
}
if ($source_id_values) {
$query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
}
if ($level) {
@ -672,22 +697,16 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
if (empty($source_id_values)) {
throw new MigrateException('Without source identifier values it is impossible to find the row to delete.');
}
if (!$messages_only) {
$map_query = $this->getDatabase()->delete($this->mapTableName());
}
$message_query = $this->getDatabase()->delete($this->messageTableName());
foreach ($this->sourceIdFields() as $field_name => $source_id) {
if (!$messages_only) {
$map_query->condition($source_id, $source_id_values[$field_name]);
}
$message_query->condition($source_id, $source_id_values[$field_name]);
}
if (!$messages_only) {
$map_query = $this->getDatabase()->delete($this->mapTableName());
$map_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
// Notify anyone listening of the map row we're about to delete.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
$map_query->execute();
}
$message_query = $this->getDatabase()->delete($this->messageTableName());
$message_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
$message_query->execute();
}
@ -705,11 +724,8 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
// Notify anyone listening of the map row we're about to delete.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
$map_query->execute();
$count = 1;
foreach ($this->sourceIdFields() as $field_name => $source_id) {
$message_query->condition($source_id, $source_id_values[$field_name]);
$count++;
}
$message_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
$message_query->execute();
}
}
@ -762,6 +778,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
}
$this->result = $this->getDatabase()->select($this->mapTableName(), 'map')
->fields('map', $fields)
->orderBy('destid1')
->execute();
$this->next();
}

View file

@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\migrate\Plugin\migrate\process\Explode.
*/
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* This plugin explodes a delimited string into an array of values.
*
* @MigrateProcessPlugin(
* id = "explode"
* )
*/
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');
}
}
else {
throw new MigrateException(sprintf('%s is not a string', var_export($value, TRUE)));
}
}
/**
* {@inheritdoc}
*/
public function multiple() {
return TRUE;
}
}

View file

@ -102,6 +102,10 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter
}
}
if (!$destination_ids && !empty($this->configuration['no_stub'])) {
return NULL;
}
if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) {
// If the lookup didn't succeed, figure out which migration will do the
// stubbing.

View file

@ -75,7 +75,7 @@ abstract class SqlBase extends SourcePluginBase implements ContainerFactoryPlugi
* The query string.
*/
public function __toString() {
return (string) $this->query;
return (string) $this->query();
}
/**