2fa9541ad813332b3176858861f51b0cafc64154
[yaffs-website] / vendor / drupal / console / src / Command / Cron / ReleaseCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Cron\ReleaseCommand.
6  */
7
8 namespace Drupal\Console\Command\Cron;
9
10 use Symfony\Component\Config\Definition\Exception\Exception;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Lock\LockBackendInterface;
15 use Drupal\Console\Core\Utils\ChainQueue;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
18
19 class ReleaseCommand extends Command
20 {
21     use CommandTrait;
22
23     /**
24      * @var LockBackendInterface
25      */
26     protected $lock;
27
28     /**
29      * @var ChainQueue
30      */
31     protected $chainQueue;
32
33     /**
34      * ReleaseCommand constructor.
35      *
36      * @param LockBackendInterface $lock
37      * @param ChainQueue           $chainQueue
38      */
39     public function __construct(
40         LockBackendInterface $lock,
41         ChainQueue $chainQueue
42     ) {
43         $this->lock = $lock;
44         $this->chainQueue = $chainQueue;
45         parent::__construct();
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     protected function configure()
52     {
53         $this
54             ->setName('cron:release')
55             ->setDescription($this->trans('commands.cron.release.description'));
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     protected function execute(InputInterface $input, OutputInterface $output)
62     {
63         $io = new DrupalStyle($input, $output);
64
65         try {
66             $this->lock->release('cron');
67
68             $io->info($this->trans('commands.cron.release.messages.released'));
69         } catch (Exception $e) {
70             $io->error($e->getMessage());
71
72             return 1;
73         }
74
75         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
76
77         return 0;
78     }
79 }