Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Queue / RunCommand.php
index e2df4760cb5fc02b711ce6ffda73395d0c184806..53c9ab7ae432edb604944ebdc49e8b8b47e2d1cd 100644 (file)
@@ -7,14 +7,12 @@
 
 namespace Drupal\Console\Command\Queue;
 
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Drupal\Core\Queue\QueueWorkerManagerInterface;
 use Drupal\Core\Queue\QueueFactory;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
 
 /**
  * Class RunCommand
@@ -23,8 +21,6 @@ use Drupal\Console\Core\Style\DrupalStyle;
  */
 class RunCommand extends Command
 {
-    use CommandTrait;
-
     /**
      * @var QueueWorkerManagerInterface
      */
@@ -34,7 +30,7 @@ class RunCommand extends Command
     /**
      * @var QueueFactory
      */
-    protected $queue;
+    protected $queueFactory;
 
     /**
      * DebugCommand constructor.
@@ -44,10 +40,10 @@ class RunCommand extends Command
      */
     public function __construct(
         QueueWorkerManagerInterface $queueWorker,
-        QueueFactory $queue
+        QueueFactory $queueFactory
     ) {
         $this->queueWorker = $queueWorker;
-        $this->queue = $queue;
+        $this->queueFactory = $queueFactory;
         parent::__construct();
     }
 
@@ -63,7 +59,7 @@ class RunCommand extends Command
                 'name',
                 InputArgument::OPTIONAL,
                 $this->trans('commands.queue.run.arguments.name')
-            );
+            )->setAliases(['qr']);
     }
 
     /**
@@ -71,11 +67,10 @@ class RunCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
         $name = $input->getArgument('name');
 
         if (!$name) {
-            $io->error(
+            $this->getIo()->error(
                 $this->trans('commands.queue.run.messages.missing-name')
             );
 
@@ -84,8 +79,9 @@ class RunCommand extends Command
 
         try {
             $worker = $this->queueWorker->createInstance($name);
+            $queue = $this->queueFactory->get($name);
         } catch (\Exception $e) {
-            $io->error(
+            $this->getIo()->error(
                 sprintf(
                     $this->trans('commands.queue.run.messages.invalid-name'),
                     $name
@@ -96,11 +92,11 @@ class RunCommand extends Command
         }
 
         $start = microtime(true);
-        $result = $this->runQueue($worker);
+        $result = $this->runQueue($queue, $worker);
         $time = microtime(true) - $start;
 
         if (!empty($result['error'])) {
-            $io->error(
+            $this->getIo()->error(
                 sprintf(
                     $this->trans('commands.queue.run.messages.failed'),
                     $name,
@@ -111,7 +107,7 @@ class RunCommand extends Command
             return 1;
         }
 
-        $io->success(
+        $this->getIo()->success(
             sprintf(
                 $this->trans('commands.queue.run.success'),
                 $name,
@@ -125,21 +121,22 @@ class RunCommand extends Command
     }
 
     /**
-     * @param $worker
+     * @param \Drupal\Core\Queue\QueueInterface       $queue
+     * @param \Drupal\Core\Queue\QueueWorkerInterface $worker
      *
      * @return array
      */
-    private function runQueue($worker)
+    private function runQueue($queue, $worker)
     {
         $result['count'] = 0;
-        $result['total'] = $this->queue->numberOfItems();
-        while ($item = $this->queue->claimItem()) {
+        $result['total'] = $queue->numberOfItems();
+        while ($item = $queue->claimItem()) {
             try {
                 $worker->processItem($item->data);
-                $this->queue->deleteItem($item);
+                $queue->deleteItem($item);
                 $result['count']++;
             } catch (SuspendQueueException $e) {
-                $this->queue->releaseItem($item);
+                $queue->releaseItem($item);
                 $result['error'] = $e;
             }
         }