-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Keep maintenance mode on if it was previously enabled #11052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep maintenance mode on if it was previously enabled #11052
Conversation
* @param OutputInterface $output | ||
* @return void | ||
*/ | ||
private function enableMaintenanceMode(OutputInterface $output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication can be avoided by extracting this behavior to a separate object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you do this? Create something like a MaintenanceModeManagement
? Or would you add this feature to Magento\Framework\App\MaintenanceMode
? I considered that last one but I don't think MaintenanceMode
should be responsible for knowing or it should disable maintenance mode.
Do you already have something in mind?
@antonkril, I've updated the pull request. All logic was moved to |
0c0393d
to
e442de5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jokeputs Changing of constructor arguments is a backward incompatible change and should be avoided. See inline comment how it may be resolved.
Also, some little code duplication is still present as for each command we need to enable and disable mode.
In general, Magento does not allow introduce new public methods in patch releases. But in this case, I suppose this is ok so I propose to add new method to
Magento\Framework\App\MaintenanceMode
:
public function executeInMaintainanceMode(callable $task)
{
// check current maintenance mode
// switch on maintenance mode if not yet enabled
call_user_func($task);
// restore initial mode if needed
}
Such approach will reduce code duplication to minimum an will not lead to a lot of code changes and constructor arguments (only wrapping some part of logic in anonymous function is required)
@@ -83,7 +83,7 @@ class Mode | |||
* @param OutputInterface $output | |||
* @param Writer $writer | |||
* @param Reader $reader | |||
* @param MaintenanceMode $maintenanceMode | |||
* @param MaintenanceModeEnabler $maintenanceMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such change is backward incompatible and not allowed for a patch releases. You should deprecate old constructor parameter and add new one.
* @param OutputInterface $output | ||
* @return void | ||
*/ | ||
private function enableMaintenanceMode(OutputInterface $output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this function private as it changes internal state. So class interfaces with enable/disable methods creates temporal coupling in a code.
Class MaintenanceModeEnabler
is preserved in a code as it would be wrong to introduce dependency on OutputInterface
in MaintenanceMode
(initial recommendation).
6b05533
to
f3f36c5
Compare
f3f36c5
to
fa5c45d
Compare
fa5c45d
to
f71efe0
Compare
…agento#11052 - revert backward incompatible changes - fix temporal coupling in \Magento\Framework\App\Console\MaintenanceModeEnabler - cover maintenance mode with unit test - revert changes in unit test to ensure code have same behavior after refactoring
f71efe0
to
b1b604e
Compare
Description
When enabling maintenance mode it will get disabled after using one of the following commands:
bin\magento module:uninstall
bin\magento setup:backup
bin\magento setup:rollback
bin\magento theme:uninstall
bin\magento deploy:mode:set production
The changes in this PR will first check or maintenance mode was already enabled. If so, it will skip disabling maintenance mode after executing the command.
Fixed Issues
Manual testing scenarios
bin\magento maintenance:enable
bin/magento setup:backup --media
bin\magento maintenance:status
The output will be for example: