Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 036c628

Browse files
committed
Keep maintenance mode on if it was previously enabled
1 parent 0c0393d commit 036c628

File tree

5 files changed

+189
-16
lines changed

5 files changed

+189
-16
lines changed

app/code/Magento/Deploy/Model/Mode.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class Mode
7878
*/
7979
private $emulatedAreaProcessor;
8080

81+
/**
82+
* @var bool
83+
*/
84+
private $skipDisableMaintenanceMode;
85+
8186
/**
8287
* @param InputInterface $input
8388
* @param OutputInterface $output
@@ -227,7 +232,14 @@ private function saveAppConfigs($mode)
227232
*/
228233
protected function enableMaintenanceMode(OutputInterface $output)
229234
{
235+
if ($this->maintenanceMode->isOn()) {
236+
$this->skipDisableMaintenanceMode = true;
237+
$output->writeln('Maintenance mode already enabled');
238+
return;
239+
}
240+
230241
$this->maintenanceMode->set(true);
242+
$this->skipDisableMaintenanceMode = false;
231243
$output->writeln('Enabled maintenance mode');
232244
}
233245

@@ -239,6 +251,11 @@ protected function enableMaintenanceMode(OutputInterface $output)
239251
*/
240252
protected function disableMaintenanceMode(OutputInterface $output)
241253
{
254+
if ($this->skipDisableMaintenanceMode) {
255+
$output->writeln('Skipped disabling maintenance mode');
256+
return;
257+
}
258+
242259
$this->maintenanceMode->set(false);
243260
$output->writeln('Disabled maintenance mode');
244261
}

app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class ThemeUninstallCommand extends Command
116116
*/
117117
private $themeDependencyChecker;
118118

119+
/**
120+
* @var bool
121+
*/
122+
private $skipDisableMaintenanceMode;
123+
119124
/**
120125
* Constructor
121126
*
@@ -215,8 +220,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
215220
}
216221

217222
try {
218-
$output->writeln('<info>Enabling maintenance mode</info>');
219-
$this->maintenanceMode->set(true);
223+
$this->enableMaintenanceMode($output);
220224
if ($input->getOption(self::INPUT_KEY_BACKUP_CODE)) {
221225
$time = time();
222226
$codeBackup = $this->backupRollbackFactory->create($output);
@@ -227,8 +231,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
227231
$this->themeUninstaller->uninstallCode($output, $themePaths);
228232

229233
$this->cleanup($input, $output);
230-
$output->writeln('<info>Disabling maintenance mode</info>');
231-
$this->maintenanceMode->set(false);
234+
$this->disableMaintenanceMode($output);
232235
} catch (\Exception $e) {
233236
$output->writeln('<error>' . $e->getMessage() . '</error>');
234237
$output->writeln('<error>Please disable maintenance mode after you resolved above issues</error>');
@@ -375,4 +378,40 @@ private function cleanup(InputInterface $input, OutputInterface $output)
375378
);
376379
}
377380
}
381+
382+
/**
383+
* Enable maintenance mode
384+
*
385+
* @param OutputInterface $output
386+
* @return void
387+
*/
388+
private function enableMaintenanceMode(OutputInterface $output)
389+
{
390+
if ($this->maintenanceMode->isOn()) {
391+
$this->skipDisableMaintenanceMode = true;
392+
$output->writeln('<info>Maintenance mode already enabled</info>');
393+
return;
394+
}
395+
396+
$this->maintenanceMode->set(true);
397+
$this->skipDisableMaintenanceMode = false;
398+
$output->writeln('<info>Enabling maintenance mode</info>');
399+
}
400+
401+
/**
402+
* Disable maintenance mode
403+
*
404+
* @param OutputInterface $output
405+
* @return void
406+
*/
407+
private function disableMaintenanceMode(OutputInterface $output)
408+
{
409+
if ($this->skipDisableMaintenanceMode) {
410+
$output->writeln('<info>Skipped disabling maintenance mode</info>');
411+
return;
412+
}
413+
414+
$this->maintenanceMode->set(false);
415+
$output->writeln('<info>Disabling maintenance mode</info>');
416+
}
378417
}

setup/src/Magento/Setup/Console/Command/BackupCommand.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class BackupCommand extends AbstractSetupCommand
5757
*/
5858
private $deploymentConfig;
5959

60+
/**
61+
* @var bool
62+
*/
63+
private $skipDisableMaintenanceMode;
64+
6065
/**
6166
* Constructor
6267
*
@@ -121,8 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
121126
$returnValue = \Magento\Framework\Console\Cli::RETURN_SUCCESS;
122127
try {
123128
$inputOptionProvided = false;
124-
$output->writeln('<info>Enabling maintenance mode</info>');
125-
$this->maintenanceMode->set(true);
129+
$this->enableMaintenanceMode($output);
126130
$time = time();
127131
$backupHandler = $this->backupRollbackFactory->create($output);
128132
if ($input->getOption(self::INPUT_KEY_CODE)) {
@@ -147,8 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
147151
$output->writeln('<error>' . $e->getMessage() . '</error>');
148152
$returnValue = \Magento\Framework\Console\Cli::RETURN_FAILURE;
149153
} finally {
150-
$output->writeln('<info>Disabling maintenance mode</info>');
151-
$this->maintenanceMode->set(false);
154+
$this->disableMaintenanceMode($output);
152155
}
153156
return $returnValue;
154157
}
@@ -168,4 +171,40 @@ private function setAreaCode()
168171
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
169172
$this->objectManager->configure($configLoader->load($areaCode));
170173
}
174+
175+
/**
176+
* Enable maintenance mode
177+
*
178+
* @param OutputInterface $output
179+
* @return void
180+
*/
181+
private function enableMaintenanceMode(OutputInterface $output)
182+
{
183+
if ($this->maintenanceMode->isOn()) {
184+
$this->skipDisableMaintenanceMode = true;
185+
$output->writeln('<info>Maintenance mode already enabled</info>');
186+
return;
187+
}
188+
189+
$this->maintenanceMode->set(true);
190+
$this->skipDisableMaintenanceMode = false;
191+
$output->writeln('<info>Enabling maintenance mode</info>');
192+
}
193+
194+
/**
195+
* Disable maintenance mode
196+
*
197+
* @param OutputInterface $output
198+
* @return void
199+
*/
200+
private function disableMaintenanceMode(OutputInterface $output)
201+
{
202+
if ($this->skipDisableMaintenanceMode) {
203+
$output->writeln('<info>Skipped disabling maintenance mode</info>');
204+
return;
205+
}
206+
207+
$this->maintenanceMode->set(false);
208+
$output->writeln('<info>Disabling maintenance mode</info>');
209+
}
171210
}

setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class ModuleUninstallCommand extends AbstractModuleCommand
108108
*/
109109
private $moduleRegistryUninstaller;
110110

111+
/**
112+
* @var bool
113+
*/
114+
private $skipDisableMaintenanceMode;
115+
111116
/**
112117
* Constructor
113118
*
@@ -228,8 +233,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
228233
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
229234
}
230235
try {
231-
$output->writeln('<info>Enabling maintenance mode</info>');
232-
$this->maintenanceMode->set(true);
236+
$this->enableMaintenanceMode($output);
233237
$this->takeBackup($input, $output);
234238
$dbBackupOption = $input->getOption(self::INPUT_KEY_BACKUP_DB);
235239
if ($input->getOption(self::INPUT_KEY_REMOVE_DATA)) {
@@ -255,8 +259,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
255259
$this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($output, $modules);
256260
$this->moduleUninstaller->uninstallCode($output, $modules);
257261
$this->cleanup($input, $output);
258-
$output->writeln('<info>Disabling maintenance mode</info>');
259-
$this->maintenanceMode->set(false);
262+
$this->disableMaintenanceMode($output);
260263
} catch (\Exception $e) {
261264
$output->writeln('<error>' . $e->getMessage() . '</error>');
262265
$output->writeln('<error>Please disable maintenance mode after you resolved above issues</error>');
@@ -378,4 +381,40 @@ private function setAreaCode()
378381
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
379382
$this->objectManager->configure($configLoader->load($areaCode));
380383
}
384+
385+
/**
386+
* Enable maintenance mode
387+
*
388+
* @param OutputInterface $output
389+
* @return void
390+
*/
391+
private function enableMaintenanceMode(OutputInterface $output)
392+
{
393+
if ($this->maintenanceMode->isOn()) {
394+
$this->skipDisableMaintenanceMode = true;
395+
$output->writeln('<info>Maintenance mode already enabled</info>');
396+
return;
397+
}
398+
399+
$this->maintenanceMode->set(true);
400+
$this->skipDisableMaintenanceMode = false;
401+
$output->writeln('<info>Enabling maintenance mode</info>');
402+
}
403+
404+
/**
405+
* Disable maintenance mode
406+
*
407+
* @param OutputInterface $output
408+
* @return void
409+
*/
410+
private function disableMaintenanceMode(OutputInterface $output)
411+
{
412+
if ($this->skipDisableMaintenanceMode) {
413+
$output->writeln('<info>Skipped disabling maintenance mode</info>');
414+
return;
415+
}
416+
417+
$this->maintenanceMode->set(false);
418+
$output->writeln('<info>Disabling maintenance mode</info>');
419+
}
381420
}

setup/src/Magento/Setup/Console/Command/RollbackCommand.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class RollbackCommand extends AbstractSetupCommand
5454
*/
5555
private $deploymentConfig;
5656

57+
/**
58+
* @var bool
59+
*/
60+
private $skipDisableMaintenanceMode;
61+
5762
/**
5863
* Constructor
5964
*
@@ -117,8 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
117122
}
118123
$returnValue = \Magento\Framework\Console\Cli::RETURN_SUCCESS;
119124
try {
120-
$output->writeln('<info>Enabling maintenance mode</info>');
121-
$this->maintenanceMode->set(true);
125+
$this->enableMaintenanceMode($output);
122126
$helper = $this->getHelper('question');
123127
$question = new ConfirmationQuestion(
124128
'<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>',
@@ -134,8 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
134138
// we must have an exit code higher than zero to indicate something was wrong
135139
$returnValue = \Magento\Framework\Console\Cli::RETURN_FAILURE;
136140
} finally {
137-
$output->writeln('<info>Disabling maintenance mode</info>');
138-
$this->maintenanceMode->set(false);
141+
$this->disableMaintenanceMode($output);
139142
}
140143
return $returnValue;
141144
}
@@ -187,4 +190,40 @@ private function setAreaCode()
187190
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
188191
$this->objectManager->configure($configLoader->load($areaCode));
189192
}
193+
194+
/**
195+
* Enable maintenance mode
196+
*
197+
* @param OutputInterface $output
198+
* @return void
199+
*/
200+
private function enableMaintenanceMode(OutputInterface $output)
201+
{
202+
if ($this->maintenanceMode->isOn()) {
203+
$this->skipDisableMaintenanceMode = true;
204+
$output->writeln('<info>Maintenance mode already enabled</info>');
205+
return;
206+
}
207+
208+
$this->maintenanceMode->set(true);
209+
$this->skipDisableMaintenanceMode = false;
210+
$output->writeln('<info>Enabling maintenance mode</info>');
211+
}
212+
213+
/**
214+
* Disable maintenance mode
215+
*
216+
* @param OutputInterface $output
217+
* @return void
218+
*/
219+
private function disableMaintenanceMode(OutputInterface $output)
220+
{
221+
if ($this->skipDisableMaintenanceMode) {
222+
$output->writeln('<info>Skipped disabling maintenance mode</info>');
223+
return;
224+
}
225+
226+
$this->maintenanceMode->set(false);
227+
$output->writeln('<info>Disabling maintenance mode</info>');
228+
}
190229
}

0 commit comments

Comments
 (0)