entityTypeManager ->getStorage($this->entityType->id()) ->getQuery() ->accessCheck(FALSE); if (!empty($this->configuration['bundles'])) { $query->condition($this->entityType->getKey('bundle'), $this->configuration['bundles'], 'IN'); } if (!empty($this->configuration['include_allrevisions'])) { $query->allRevisions(); } return $query; } /** * {@inheritdoc} */ public function getIds() { $id_key = $this->entityType->getKey('id'); $ids[$id_key] = $this->getDefinitionFromEntity($id_key); if ($this->entityType->isRevisionable()) { $revision_key = $this->entityType->getKey('revision'); $ids[$revision_key] = $this->getDefinitionFromEntity($revision_key); } if ($this->entityType->isTranslatable()) { $langcode_key = $this->entityType->getKey('langcode'); $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key); } return $ids; } /** * Initializes the iterator with the source data. * * @return \Generator * A data generator for this source. */ protected function initializeIterator() { $ids = $this->query()->execute(); $highWater = $this->getHighWater(); $highWaterProperty = $this->getHighWaterProperty(); $highWaterField = $this->getHighWaterField(); $shouldUseHighWater = (!empty($highWaterProperty) && !empty($highWater)); // Closure to check wheter intention is to do only-new or update all. $intendsUpdateAll = function () : bool { $shouldSkip = FALSE; $arguments = $GLOBALS['argv'] ?? []; foreach ($arguments as $argument) { $shouldSkip = (strpos($argument, '--update') !== FALSE) ? TRUE : $shouldSkip; } return $shouldSkip; }; // Array of ids is usually index by revision_id to a value of base_id. $targetVariable = (in_array($highWaterField, ['revision_id', 'vid'])) ? 'key' : 'element'; // Filter only the array of ids that is higher than highwater. $parsedIds = ($shouldUseHighWater && !$intendsUpdateAll()) ? array_filter($ids, function ($element, $key) use ($highWater, $targetVariable) { $target = ${$targetVariable}; $isHigher = ($highWater <= $target); return $isHigher; }, ARRAY_FILTER_USE_BOTH) : $ids; $outputYield = (!empty($this->configuration['include_allrevisions']) && method_exists($this, 'yieldEntityRevisions')) ? $this->yieldEntityRevisions($parsedIds) : $this->yieldEntities($parsedIds); return $outputYield; } /** * Loads and yields entities, one at a time. * * @param array $ids * The entity IDs. * * @return \Generator * An iterable of the loaded entities. */ protected function yieldEntities(array $ids) { $storage = $this->entityTypeManager ->getStorage($this->entityType->id()); foreach ($ids as $id) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $storage->load($id); yield $this->toArray($entity); if ($this->configuration['include_translations']) { foreach ($entity->getTranslationLanguages(FALSE) as $language) { yield $this->toArray($entity->getTranslation($language->getId())); } } } } /** * Loads and yields entities-revision sensitive., one at a time. * * @param array $ids * The entity vid and entity ids. * * @return \Generator * An iterable of the loaded entities. */ protected function yieldEntityRevisions(array $ids) { $storage = $this->entityTypeManager ->getStorage($this->entityType->id()); foreach ($ids as $vid => $id) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $storage->loadRevision($vid); yield $this->toArray($entity); if ($this->configuration['include_translations']) { foreach ($entity->getTranslationLanguages(FALSE) as $language) { yield $this->toArray($entity->getTranslation($language->getId())); } } } } }