Yaffs site version 1.1
[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 Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
15 use Drupal\Console\Core\Style\DrupalStyle;
16 use Drupal\Core\State\StateInterface;
17 use Drupal\Console\Core\Utils\ChainQueue;
18
19 class MaintenanceCommand extends Command
20 {
21     use ContainerAwareCommandTrait;
22
23
24     /**
25      * @var StateInterface
26      */
27     protected $state;
28
29
30     /**
31      * @var ChainQueue
32      */
33     protected $chainQueue;
34
35     /**
36      * DebugCommand constructor.
37      *
38      * @param StateInterface $state
39      * @param ChainQueue     $chainQueue
40      */
41     public function __construct(
42         StateInterface $state,
43         ChainQueue $chainQueue
44     ) {
45         $this->state = $state;
46         $this->chainQueue = $chainQueue;
47         parent::__construct();
48     }
49
50     protected function configure()
51     {
52         $this
53             ->setName('site:maintenance')
54             ->setDescription($this->trans('commands.site.maintenance.description'))
55             ->addArgument(
56                 'mode',
57                 InputArgument::REQUIRED,
58                 $this->trans('commands.site.maintenance.arguments.mode').'[on/off]'
59             );
60     }
61
62     protected function execute(InputInterface $input, OutputInterface $output)
63     {
64         $io = new DrupalStyle($input, $output);
65
66         $mode = $input->getArgument('mode');
67         $stateName = 'system.maintenance_mode';
68         $modeMessage = null;
69         $cacheRebuild = true;
70
71         if ('ON' === strtoupper($mode)) {
72             $this->state->set($stateName, true);
73             $modeMessage = 'commands.site.maintenance.messages.maintenance-on';
74         }
75         if ('OFF' === strtoupper($mode)) {
76             $this->state->set($stateName, false);
77             $modeMessage = 'commands.site.maintenance.messages.maintenance-off';
78         }
79
80         if ($modeMessage === null) {
81             $modeMessage = 'commands.site.maintenance.errors.invalid-mode';
82             $cacheRebuild = false;
83         }
84
85         $io->info($this->trans($modeMessage));
86
87         if ($cacheRebuild) {
88             $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
89         }
90     }
91 }