Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobSetMaintenanceMode.php
Go to the documentation of this file.
1 <?php
7 
11 use Symfony\Component\Console\Input\ArrayInput;
12 use Symfony\Component\Console\Output\OutputInterface;
13 
18 {
29  public function __construct(
31  ObjectManagerProvider $objectManagerProvider,
32  OutputInterface $output,
34  $name,
35  $params = []
36  ) {
37  $this->command = $command;
38  parent::__construct($output, $status, $objectManagerProvider, $name, $params);
39  }
40 
47  public function execute()
48  {
49  if ($this->command instanceof MaintenanceDisableCommand && $this->command->isSetAddressInfo()) {
50  // Maintenance mode should not be unset from updater application if it was set manually by the admin
51  throw new \RuntimeException(
52  $this->getExceptionMessage(
53  'Magento maintenance mode was not disabled. It can be disabled from the Magento Backend.'
54  )
55  );
56  }
57 
58  try {
59  // Prepare the arguments to invoke Symfony run()
60  $arguments['command'] = $this->getCommand();
61  $this->command->run(new ArrayInput($arguments), $this->output);
62  } catch (\Exception $e) {
63  $this->status->toggleUpdateError(true);
64  throw new \RuntimeException(
65  $this->getExceptionMessage($e->getMessage())
66  );
67  }
68  }
69 
76  private function getExceptionMessage($msg)
77  {
78  return sprintf('Could not complete %s successfully: %s', $this, $msg);
79  }
80 
86  private function getCommand()
87  {
88  return $this->getName() === 'setup:maintenance:enable' ? 'maintenance:enable' : 'maintenance:disable';
89  }
90 }
output($string, $level=INFO, $label='')
__construct(AbstractSetupCommand $command, ObjectManagerProvider $objectManagerProvider, OutputInterface $output, Status $status, $name, $params=[])
$arguments