You are here

private function ScheduledPublishCron::doUpdateFor in Scheduled Publish 8.3

Same name and namespace in other branches
  1. 8.2 src/Service/ScheduledPublishCron.php \Drupal\scheduled_publish\Service\ScheduledPublishCron::doUpdateFor()

Run field update for specific entity type

Parameters

$entityType:

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Exception

1 call to ScheduledPublishCron::doUpdateFor()
ScheduledPublishCron::doUpdate in src/Service/ScheduledPublishCron.php
Run field updates

File

src/Service/ScheduledPublishCron.php, line 111

Class

ScheduledPublishCron
Class ScheduledPublishCron

Namespace

Drupal\scheduled_publish\Service

Code

private function doUpdateFor($entityType) {
  $bundles = $this->entityBundleInfoService
    ->getBundleInfo($entityType);
  foreach ($bundles as $bundleName => $value) {
    $scheduledFields = $this
      ->getScheduledFields($entityType, $bundleName);
    if (\count($scheduledFields) > 0) {
      foreach ($scheduledFields as $scheduledField) {
        $query = $this->entityTypeManager
          ->getStorage($entityType)
          ->getQuery('AND');
        $query
          ->condition($entityType === 'media' ? 'bundle' : 'type', $bundleName);
        $query
          ->condition($scheduledField, NULL, 'IS NOT NULL');
        $query
          ->accessCheck(FALSE);
        $query
          ->latestRevision();
        $entities = $query
          ->execute();
        foreach ($entities as $entityRevision => $entityId) {
          $entity = $this->entityTypeManager
            ->getStorage($entityType)
            ->loadRevision($entityRevision);
          $this
            ->updateEntityField($entity, $scheduledField);
        }
      }
    }
  }
}