You are here

class QueueListCommand in Advanced Queue 8

Queue list command.

@package Drupal\advancedqueue

@DrupalCommand ( extension="advancedqueue", extensionType="module" )

Hierarchy

  • class \Drupal\advancedqueue\Command\QueueListCommand extends \Drupal\Console\Core\Command\Command

Expanded class hierarchy of QueueListCommand

1 string reference to 'QueueListCommand'
console.services.yml in ./console.services.yml
console.services.yml
1 service uses QueueListCommand
advancedqueue.queue_list in ./console.services.yml
Drupal\advancedqueue\Command\QueueListCommand

File

src/Command/QueueListCommand.php, line 25

Namespace

Drupal\advancedqueue\Command
View source
class QueueListCommand extends Command {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new QueueListCommand object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct();
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this
      ->setName('advancedqueue:queue:list')
      ->setDescription($this
      ->trans('commands.advancedqueue.queue.list.description'));
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $count_labels = [
      Job::STATE_QUEUED => $this
        ->trans('commands.advancedqueue.queue.list.counts.queued'),
      Job::STATE_PROCESSING => $this
        ->trans('commands.advancedqueue.queue.list.counts.processing'),
      Job::STATE_SUCCESS => $this
        ->trans('commands.advancedqueue.queue.list.counts.success'),
      Job::STATE_FAILURE => $this
        ->trans('commands.advancedqueue.queue.list.counts.failure'),
    ];
    $queue_storage = $this->entityTypeManager
      ->getStorage('advancedqueue_queue');
    $rows = [];
    foreach ($queue_storage
      ->loadMultiple() as $queue) {

      /** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
      $jobs = [];
      foreach ($queue
        ->getBackend()
        ->countJobs() as $state => $count) {
        $jobs[] = sprintf($count_labels[$state], $count);
      }
      $rows[] = [
        'id' => $queue
          ->id(),
        'label' => $queue
          ->label(),
        'jobs' => implode(' | ', $jobs),
      ];
    }
    $io = new DrupalStyle($input, $output);
    $io
      ->table([
      $this
        ->trans('commands.advancedqueue.queue.list.table-headers.id'),
      $this
        ->trans('commands.advancedqueue.queue.list.table-headers.label'),
      $this
        ->trans('commands.advancedqueue.queue.list.table-headers.jobs'),
    ], $rows, 'default');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueueListCommand::$entityTypeManager protected property The entity type manager.
QueueListCommand::configure protected function
QueueListCommand::execute protected function
QueueListCommand::__construct public function Constructs a new QueueListCommand object.