diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index 24fe07ae4b5b83bf16416a6cfe6be510745bdd80..8784c20c1af390110b0b0adc423602122de5beaf 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -12,6 +12,7 @@ use Drupal\migrate\Event\MigrateRollbackEvent; use Drupal\migrate\Event\MigrateRowDeleteEvent; use Drupal\migrate\Exception\RequirementsException; +use Drupal\migrate\Plugin\MigrateIdFilterInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrationInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -179,6 +180,12 @@ public function import() { $this->migration->setStatus(MigrationInterface::STATUS_IMPORTING); $source = $this->getSource(); + if (!empty($this->idlist)) { + $migrate_source = $this->migration->getSourcePlugin(); + if ($migrate_source instanceof MigrateIdFilterInterface) { + $migrate_source->setIdList($this->idlist); + } + } try { $source->rewind(); diff --git a/core/modules/migrate/src/Plugin/MigrateIdFilterInterface.php b/core/modules/migrate/src/Plugin/MigrateIdFilterInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..7f1d924a16adee28e5fa7ffdcbe94e076e8fbbf4 --- /dev/null +++ b/core/modules/migrate/src/Plugin/MigrateIdFilterInterface.php @@ -0,0 +1,26 @@ +idList; + } + + /** + * {@inheritdoc} + */ + public function setIdList(array $idList) { + $this->idList = $idList; + } + /** * Wrapper for database select. */ @@ -244,6 +266,31 @@ protected function prepareQuery() { $this->query->addTag('migrate_' . $this->migration->id()); $this->query->addMetaData('migration', $this->migration); + $id_list = $this->getIdList(); + if (!empty($id_list)) { + $id_fields = []; + $connection = $this->getDatabase(); + foreach ($this->getIds() as $field_name => $field_schema) { + if (isset($field_schema['alias'])) { + $field_name = $connection->escapeAlias($field_schema['alias']) . '.' . $this->query->escapeField($field_name); + } + else { + $field_name = $this->query->escapeField($field_name); + } + $id_fields[] = $field_name; + } + + $or = $this->query->orConditionGroup(); + foreach ($id_list as $ids) { + $and = $this->query->andConditionGroup(); + foreach ($ids as $key => $id) { + $and->condition($id_fields[$key], $id); + } + $or->condition($and); + } + $this->query->condition($or); + } + return $this->query; }