You are here

public function RunUpdatesCommand::list_runners in Scheduled Updates 8

Show current state of updates.

@command sup:list_runners @aliases sup-list, sup:list

@usage drush sup:list Run updates.

@field-labels id: Update ID name: Plugin ID desc: Description count: count after: After Run Action fields: Fields entities: Entities class: Class @default-fields id,count,entities,after

@option unrun Only list entities that have not been processed. @option types Set to comma-separated list of machine name(s) of the update types to update, otherwise all types.

Parameters

array $options: (optional) The options.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields Table of runners.

File

src/Commands/RunUpdatesCommand.php, line 110

Class

RunUpdatesCommand
Class RunUpdatesCommand.

Namespace

Drupal\scheduled_updates\Commands

Code

public function list_runners($options = [
  'format' => 'table',
  'limit' => 20,
  'types' => NULL,
  'unrun' => NULL,
]) {
  $entityTypeManager = \Drupal::service('entity_type.manager');
  if ($options['types']) {
    $update_types = explode(',', $options['types']);
  }
  else {
    $update_types = [];
  }

  // $requestTime = \Drupal::time()->getRequestTime();
  $runners = $this->scheduledUpdatesRunner
    ->getUpdateTypeRunners($update_types);
  $result = [];
  foreach ($runners as $key => $runner) {
    $reffields = $runner
      ->getReferencingFieldIds();
    $entity_ids = [];
    if ($reffields) {

      /** @var \Drupal\Core\Entity\EntityStorageBase $entity_storage */
      $entityStorage = $entityTypeManager
        ->getStorage($runner
        ->updateEntityType());
      $entityType = $entityStorage
        ->getEntityType();
      foreach ($reffields as $field_id) {

        /** @var \Drupal\Core\Entity\Query\QueryInterface $query */
        $query = $entityStorage
          ->getQuery('AND');
        $query
          ->accessCheck(FALSE);

        //  $query->condition("$field_id.entity.". 'update_timestamp', $requestTime, '<=');
        $query
          ->condition("{$field_id}.entity." . 'type', $key);
        if ($options['unrun']) {
          $query
            ->condition("{$field_id}.entity." . 'status', ScheduledUpdateInterface::STATUS_UNRUN);
        }
        $entity_ids += $query
          ->execute();
      }
    }
    $row = [
      'id' => $key,
      'name' => $runner
        ->getPluginId(),
      'desc' => $runner
        ->getDescription(),
      'after' => $runner
        ->getAfterRun(),
      'fields' => implode(',', $reffields),
      'count' => $runner
        ->getQueue()
        ->numberOfItems(),
      'entities' => $entityType
        ->getBaseTable() . ':' . implode(',', $entity_ids),
    ];
    $result[] = $row;
  }
  return new RowsOfFields($result);
}