protected function EmbeddedUpdateRunner::getPreviousRevisionsWithUpdates in Scheduled Updates 8
Get all previous revisions that have updates of the attached type.
This function would be easier and more performant if this core issue with Entity Query was fixed: https://www.drupal.org/node/2649268 Without this fix can't filter query on type of update and whether they are active. So therefore all previous revisions have to be loaded.
@todo Help get that core issue fixed or rewrite this function query table fields directly.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity:
Return value
\Drupal\Core\Entity\ContentEntityInterface[]
1 call to EmbeddedUpdateRunner::getPreviousRevisionsWithUpdates()
- EmbeddedUpdateRunner::deactivateUpdates in src/
Plugin/ UpdateRunner/ EmbeddedUpdateRunner.php - Deactivate any Scheduled Updates that are previous revision but not on current.
File
- src/
Plugin/ UpdateRunner/ EmbeddedUpdateRunner.php, line 192 - Contains \Drupal\scheduled_updates\Plugin\UpdateRunner\EmbeddedUpdateRunner.
Class
- EmbeddedUpdateRunner
- The default Embedded Update Runner.
Namespace
Drupal\scheduled_updates\Plugin\UpdateRunnerCode
protected function getPreviousRevisionsWithUpdates(ContentEntityInterface $entity) {
/** @var ContentEntityInterface[] $revisions */
$revisions = [];
$type = $entity
->getEntityType();
$query = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->getQuery();
$query
->allRevisions()
->condition($type
->getKey('id'), $entity
->id())
->condition($type
->getKey('revision'), $entity
->getRevisionId(), '<')
->sort($type
->getKey('revision'), 'DESC');
if ($revision_ids = $query
->execute()) {
$revision_ids = array_keys($revision_ids);
$storage = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId());
foreach ($revision_ids as $revision_id) {
/** @var ContentEntityInterface $revision */
$revision = $storage
->loadRevision($revision_id);
if ($update_ids = $this
->getUpdateIdsOnEntity($revision)) {
$revisions[$revision_id] = $revision;
}
}
}
return $revisions;
}