Commit 2e73586b authored by Lisa Harrison's avatar Lisa Harrison Committed by Bojan Živanović
Browse files

Issue #3264133 by lhridley, johnwebdev: Remove Drupal Console commands

parent 4de1b503
Loading
Loading
Loading
Loading

console.services.yml

deleted100644 → 0
+0 −18
Original line number Diff line number Diff line
services:
  advancedqueue.queue_clear:
    class: Drupal\advancedqueue\Command\QueueClearCommand
    arguments: ['@entity_type.manager', '@database']
    tags:
      - { name: drupal.command }

  advancedqueue.queue_list:
    class: Drupal\advancedqueue\Command\QueueListCommand
    arguments: ['@entity_type.manager']
    tags:
      - { name: drupal.command }

  advancedqueue.queue_process:
    class: Drupal\advancedqueue\Command\QueueProcessCommand
    arguments: ['@entity_type.manager', '@advancedqueue.processor']
    tags:
      - { name: drupal.command }
+0 −10
Original line number Diff line number Diff line
description: 'Clear a queue'
options:
  queue-id: 'The queue ID'
arguments:
  job-state: 'Allowed job states'
messages:
  not-found: 'Could not find queue "%s".'
  unknown-state: 'Unknown job state "%s".'
  nothing-to-do: 'Finished. No jobs found in the %s queue.'
  finished: 'Finished. Removed %s jobs from the %s queue.'
+0 −12
Original line number Diff line number Diff line
description: 'List queues.'
options: {}
arguments: {}
table-headers:
  id: 'ID'
  label: 'Label'
  jobs: 'Jobs'
counts:
  queued: 'Queued: %d'
  processing: 'Processing: %d'
  success: 'Success: %d'
  failure: 'Failure: %d'
+0 −6
Original line number Diff line number Diff line
description: 'Process a queue.'
options: {}
arguments: {}
messages:
  not-found: 'Could not find queue "%s".'
  finished: 'Processed %s jobs from the %s queue in %.2f seconds.'

src/Command/QueueClearCommand.php

deleted100644 → 0
+0 −138
Original line number Diff line number Diff line
<?php

namespace Drupal\advancedqueue\Command;

// @codingStandardsIgnoreStart
use Drupal\advancedqueue\Job;
use Drupal\Console\Annotations\DrupalCommand;
use Drupal\Console\Core\Command\Command;
use Drupal\Core\Database\Connection;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\Entity\EntityTypeManagerInterface;
// @codingStandardsIgnoreEnd

/**
 * Class ClearQueueCommand.
 *
 * @DrupalCommand (
 *   extension="advancedqueue",
 *   extensionType="module"
 * )
 */
class QueueClearCommand extends Command {

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

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * Allowed job states.
   *
   * @var array
   */
  protected $jobStates = [
    Job::STATE_QUEUED,
    Job::STATE_PROCESSING,
    Job::STATE_SUCCESS,
    Job::STATE_FAILURE,
  ];

  /**
   * Constructs a new QueueClearCommand object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Database\Connection $database
   *   The database connection.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database) {
    parent::__construct();

    $this->entityTypeManager = $entity_type_manager;
    $this->database = $database;
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this->setName('advancedqueue:queue:clear')
      ->setDescription($this->trans('commands.advancedqueue.queue.clear.description'))
      ->addArgument(
        'queue_id',
        InputArgument::REQUIRED,
        $this->trans('commands.advancedqueue.queue.clear.options.queue-id')
      )
      ->addOption(
        'state',
        's',
        InputOption::VALUE_OPTIONAL,
        $this->trans('commands.advancedqueue.queue.clear.arguments.job-state')
      );
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $queue_id = $input->getArgument('queue_id');
    $state = strtolower($input->getOption('state'));

    $queue_storage = $this->entityTypeManager->getStorage('advancedqueue_queue');
    /** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
    $queue = $queue_storage->load($queue_id);
    if (!$queue) {
      $message = $this->trans('commands.advancedqueue.queue.clear.messages.not-found');
      throw new \RuntimeException(sprintf($message, $queue_id));
    }
    if ($state && !in_array($state, $this->jobStates)) {
      $message = $this->trans('commands.advancedqueue.queue.clear.messages.unknown-state');
      throw new \RuntimeException(sprintf($message, $state));
    }

    $query = $this->database->delete('advancedqueue');
    $query->condition('queue_id', $queue_id);
    if ($state) {
      $query->condition('state', $state, '=');
    }
    else {
      // All job states.
      $query->condition('state', $this->jobStates, 'IN');
    }
    $num_rows = $query->execute();

    $io = new DrupalStyle($input, $output);
    if ($num_rows) {
      $io->success(
        sprintf(
          $this->trans('commands.advancedqueue.queue.clear.messages.finished'),
          $num_rows,
          $queue->get('label')
        )
      );
    }
    else {
      $io->success(
        sprintf(
          $this->trans('commands.advancedqueue.queue.clear.messages.nothing-to-do'),
          $queue->get('label')
        )
      );
    }
  }

}
Loading