public function OrphanPurger::processItem in Entity Reference Revisions 8
Works on a single queue item.
Parameters
mixed $data: The data that was passed to \Drupal\Core\Queue\QueueInterface::createItem() when the item was queued.
Throws
\Drupal\Core\Queue\RequeueException Processing is not yet finished. This will allow another process to claim the item immediately.
\Exception A QueueWorker plugin may throw an exception to indicate there was a problem. The cron process will log the exception, and leave the item in the queue to be processed again later.
\Drupal\Core\Queue\SuspendQueueException More specifically, a SuspendQueueException should be thrown when a QueueWorker plugin is aware that the problem will affect all subsequent workers of its queue. For example, a callback that makes HTTP requests may find that the remote server is not responding. The cron process will behave as with a normal Exception, and in addition will not attempt to process further items from the current item's queue during the current cron run.
Overrides QueueWorkerInterface::processItem
See also
\Drupal\Core\Cron::processQueues()
File
- src/
Plugin/ QueueWorker/ OrphanPurger.php, line 84
Class
- OrphanPurger
- Removes composite revisions that are no longer used.
Namespace
Drupal\entity_reference_revisions\Plugin\QueueWorkerCode
public function processItem($data) {
$entity_type_id = $data['entity_type_id'];
if (!$this->entityTypeManager
->hasDefinition($entity_type_id)) {
return;
}
// Check the usage of data item and remove if not used.
$composite_storage = $this->entityTypeManager
->getStorage($entity_type_id);
$composite_type = $this->entityTypeManager
->getDefinition($entity_type_id);
$composite_revision_key = $composite_type
->getKey('revision');
// Load all revisions of the composite type.
// @todo Replace with an entity query on all revisions with a revision ID
// condition after https://www.drupal.org/project/drupal/issues/2766135.
$entity_revision_ids = $this->database
->select($composite_type
->getRevisionTable(), 'r')
->fields('r', [
$composite_revision_key,
])
->condition($composite_type
->getKey('id'), $data['entity_id'])
->orderBy($composite_revision_key)
->execute()
->fetchCol();
/** @var \Drupal\Core\Entity\ContentEntityInterface $composite_revision */
foreach ($composite_storage
->loadMultipleRevisions($entity_revision_ids) as $composite_revision) {
if (!$this->purger
->isUsed($composite_revision)) {
$this->purger
->deleteUnusedRevision($composite_revision);
}
}
}