You are here

public function BaseUpdateRunner::runUpdatesInQueue in Scheduled Updates 8

Run all updates that are in the queue.

Parameters

$time_end: The time in seconds when no more updates should be run.

Overrides UpdateRunnerInterface::runUpdatesInQueue

File

src/Plugin/BaseUpdateRunner.php, line 174
Contains \Drupal\scheduled_updates\Plugin\BaseUpdateRunner.

Class

BaseUpdateRunner

Namespace

Drupal\scheduled_updates\Plugin

Code

public function runUpdatesInQueue($time_end) {
  $queue = $this
    ->getQueue();
  $invalid_updates_cnt = 0;
  $valid_updates_cnt = 0;
  while ($time_end > time()) {
    if ($update_info = $queue
      ->claimItem(10)) {

      /** @var ScheduledUpdate $update */
      if ($update = ScheduledUpdate::load($update_info->data['update_id'])) {

        // @todo Validate that $update timestamp code has been changed since
        //   adding to queue.
        // @todo If update is in queue should its edit access always be false?
        if (isset($update_info->data['entity_ids'])) {
          $entity_ids = $update_info->data['entity_ids'];
        }
        else {
          $entity_ids = $update
            ->getUpdateEntityIds();
        }
        if ($this
          ->runUpdate($update, $entity_ids, $update_info)) {
          $valid_updates_cnt++;
        }
        else {
          $invalid_updates_cnt++;
        }
      }
      else {

        // Could not load update that is in queue.
        $queue
          ->deleteItem($update_info);
      }
    }
    else {

      // No more items can be claimed.
      break;
    }
  }
  $this
    ->displayMessage($valid_updates_cnt, $invalid_updates_cnt);
  $this
    ->releaseClaimedItems();
}