5 * Contains \Drupal\Console\Command\Site\MaintenanceCommand.
8 namespace Drupal\Console\Command\Site;
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;
19 class MaintenanceCommand extends Command
21 use ContainerAwareCommandTrait;
33 protected $chainQueue;
36 * DebugCommand constructor.
38 * @param StateInterface $state
39 * @param ChainQueue $chainQueue
41 public function __construct(
42 StateInterface $state,
43 ChainQueue $chainQueue
45 $this->state = $state;
46 $this->chainQueue = $chainQueue;
47 parent::__construct();
50 protected function configure()
53 ->setName('site:maintenance')
54 ->setDescription($this->trans('commands.site.maintenance.description'))
57 InputArgument::REQUIRED,
58 $this->trans('commands.site.maintenance.arguments.mode').'[on/off]'
62 protected function execute(InputInterface $input, OutputInterface $output)
64 $io = new DrupalStyle($input, $output);
66 $mode = $input->getArgument('mode');
67 $stateName = 'system.maintenance_mode';
71 if ('ON' === strtoupper($mode)) {
72 $this->state->set($stateName, true);
73 $modeMessage = 'commands.site.maintenance.messages.maintenance-on';
75 if ('OFF' === strtoupper($mode)) {
76 $this->state->set($stateName, false);
77 $modeMessage = 'commands.site.maintenance.messages.maintenance-off';
80 if ($modeMessage === null) {
81 $modeMessage = 'commands.site.maintenance.errors.invalid-mode';
82 $cacheRebuild = false;
85 $io->info($this->trans($modeMessage));
88 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);