c94368a5e5a3a5cc8966eb972872d68b3ac9488b
[yaffs-website] / vendor / drupal / console / src / Command / Site / MaintenanceCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Site\MaintenanceCommand.
6  */
7
8 namespace Drupal\Console\Command\Site;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Core\Command\ContainerAwareCommand;
14 use Drupal\Core\State\StateInterface;
15 use Drupal\Console\Core\Utils\ChainQueue;
16
17 class MaintenanceCommand extends ContainerAwareCommand
18 {
19     /**
20      * @var StateInterface
21      */
22     protected $state;
23
24
25     /**
26      * @var ChainQueue
27      */
28     protected $chainQueue;
29
30     /**
31      * DebugCommand constructor.
32      *
33      * @param StateInterface $state
34      * @param ChainQueue     $chainQueue
35      */
36     public function __construct(
37         StateInterface $state,
38         ChainQueue $chainQueue
39     ) {
40         $this->state = $state;
41         $this->chainQueue = $chainQueue;
42         parent::__construct();
43     }
44
45     protected function configure()
46     {
47         $this
48             ->setName('site:maintenance')
49             ->setDescription($this->trans('commands.site.maintenance.description'))
50             ->addArgument(
51                 'mode',
52                 InputArgument::REQUIRED,
53                 $this->trans('commands.site.maintenance.arguments.mode')
54             )
55             ->setAliases(['sma']);
56     }
57
58     protected function execute(InputInterface $input, OutputInterface $output)
59     {
60         $mode = $input->getArgument('mode');
61         $stateName = 'system.maintenance_mode';
62         $modeMessage = null;
63         $cacheRebuild = true;
64
65         if ('ON' === strtoupper($mode)) {
66             $this->state->set($stateName, true);
67             $modeMessage = 'commands.site.maintenance.messages.maintenance-on';
68         }
69         if ('OFF' === strtoupper($mode)) {
70             $this->state->set($stateName, false);
71             $modeMessage = 'commands.site.maintenance.messages.maintenance-off';
72         }
73
74         if ($modeMessage === null) {
75             $modeMessage = 'commands.site.maintenance.errors.invalid-mode';
76             $cacheRebuild = false;
77         }
78
79         $this->getIo()->info($this->trans($modeMessage));
80
81         if ($cacheRebuild) {
82             $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
83         }
84     }
85 }