diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index 451be40..332769c 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -84,13 +84,6 @@ protected $originalHighWater; /** - * List of source IDs to process. - * - * @var array - */ - protected $idList = array(); - - /** * Whether this instance should cache the source count. * * @var bool @@ -166,10 +159,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->originalHighWater = $this->migration->getHighWater(); } - if ($id_list = $this->migration->get('idlist')) { - $this->idList = $id_list; - } - // Don't allow the use of both highwater and track changes together. if ($this->highWaterProperty && $this->trackChanges) { throw new MigrateException('You should either use a highwater mark or track changes not both. They are both designed to solve the same problem'); @@ -198,6 +187,22 @@ protected function getModuleHandler() { } /** + * Get the list of IDs of the rows to be migrated. + * + * @return array + * The list of IDs of the rows to be migrated. + */ + protected function getIdList() { + if (!empty($this->configuration['id_list'])) { + if (count($this->getIds()) > 1) { + throw new \LogicException('Cannot filter on multi-value key.'); + } + return $this->configuration['id_list']; + } + return []; + } + + /** * {@inheritdoc} */ public function prepareRow(Row $row) { @@ -321,11 +326,11 @@ public function next() { // In case we have specified an ID list, but the ID given by the source is // not in there, we skip the row. - $id_in_the_list = $this->idList && in_array(reset($this->currentSourceIds), $this->idList); - if ($this->idList && !$id_in_the_list) { + $id_list = $this->getIdList(); + $id_in_the_list = $id_list && in_array(reset($this->currentSourceIds), $id_list); + if ($id_list && !$id_in_the_list) { continue; } - // Preparing the row gives source plugins the chance to skip. if ($this->prepareRow($row) === FALSE) { continue; diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php index 2ff55d5..68700dc 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php @@ -105,19 +105,16 @@ protected function prepareQuery() { // If an ID list is provided, filter on it. This only works for single-value // keys, so throw an exception if the key is multi-value. - if (isset($this->configuration['idlist'])) { - $key = $this->getIds(); - if (count($key) == 1) { - $field = key($key); + if ($id_list = $this->getIdList()) { + // \Drupal\migrate\Plugin\migrate\source\SourcePluginBase::__construct() + // ensures the idlist is single long. + foreach ($this->getIds() as $field => $definition) { // If a table alias was provided, prepend it in order to prevent // the possibility of 'ambiguous column' errors. - if (isset($key[$field]['alias'])) { - $field = $key[$field]['alias'] . '.' . $field; + if (isset($definition['alias'])) { + $field = $definition['alias'] . '.' . $field; } - $this->query->condition($field, $this->configuration['idlist'], 'IN'); - } - else { - throw new \LogicException('Cannot filter on multi-value key.'); + $this->query->condition($field, $id_list, 'IN'); } } diff --git a/core/modules/migrate_drupal/tests/src/Unit/source/d6/NodeIdListTest.php b/core/modules/migrate_drupal/tests/src/Unit/source/d6/NodeIdListTest.php index 7c4d488..4e2afcb 100644 --- a/core/modules/migrate_drupal/tests/src/Unit/source/d6/NodeIdListTest.php +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/NodeIdListTest.php @@ -20,7 +20,7 @@ class NodeIdListTest extends NodeTest { // The fake configuration for the source. 'source' => array( 'plugin' => 'd6_node', - 'idlist' => array(1), + 'id_list' => [1], ), );