15 use Symfony\Component\Console\Input\InputInterface;
16 use Symfony\Component\Console\Input\InputOption;
17 use Symfony\Component\Console\Output\OutputInterface;
18 use Symfony\Component\Console\Question\ConfirmationQuestion;
39 private $objectManager;
44 private $backupRollbackFactory;
51 private $deploymentConfig;
56 private $maintenanceModeEnabler;
74 $this->objectManager = $objectManagerProvider->
get();
75 $this->backupRollbackFactory = $this->objectManager->get(\
Magento\Framework\Setup\BackupRollbackFactory::class);
77 $this->maintenanceModeEnabler =
78 $maintenanceModeEnabler ?: $this->objectManager->get(MaintenanceModeEnabler::class);
79 parent::__construct();
89 self::INPUT_KEY_CODE_BACKUP_FILE,
91 InputOption::VALUE_REQUIRED,
92 'Basename of the code backup file in var/backups' 95 self::INPUT_KEY_MEDIA_BACKUP_FILE,
97 InputOption::VALUE_REQUIRED,
98 'Basename of the media backup file in var/backups' 101 self::INPUT_KEY_DB_BACKUP_FILE,
103 InputOption::VALUE_REQUIRED,
104 'Basename of the db backup file in var/backups' 107 $this->setName(
'setup:rollback')
108 ->setDescription(
'Rolls back Magento Application codebase, media and database')
118 if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE)
119 || $input->getOption(self::INPUT_KEY_DB_BACKUP_FILE))
121 $output->writeln(
"<info>No information is available: the Magento application is not installed.</info>");
123 return \Magento\Framework\Console\Cli::RETURN_FAILURE;
125 $returnValue = $this->maintenanceModeEnabler->executeInMaintenanceMode(
126 function () use ($input,
$output, &$returnValue) {
128 $helper = $this->getHelper(
'question');
129 $question =
new ConfirmationQuestion(
130 '<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>',
133 if (!
$helper->ask($input,
$output, $question) && $input->isInteractive()) {
134 return \Magento\Framework\Console\Cli::RETURN_FAILURE;
136 $questionKeep =
new ConfirmationQuestion(
137 '<info>Do you want to keep the backups?[y/N]<info>',
142 $this->doRollback($input,
$output, $keepSourceFile);
143 $output->writeln(
'<info>Please set file permission of bin/magento to executable</info>');
145 return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
147 $output->writeln(
'<error>' . $e->getMessage() .
'</error>');
149 return \Magento\Framework\Console\Cli::RETURN_FAILURE;
167 private function doRollback(InputInterface $input, OutputInterface
$output, $keepSourceFile)
169 $inputOptionProvided =
false;
170 $rollbackHandler = $this->backupRollbackFactory->create(
$output);
171 if ($input->getOption(self::INPUT_KEY_CODE_BACKUP_FILE)) {
172 $rollbackHandler->codeRollback(
173 $input->getOption(self::INPUT_KEY_CODE_BACKUP_FILE),
177 $inputOptionProvided =
true;
179 if ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE)) {
180 $rollbackHandler->codeRollback(
181 $input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE),
185 $inputOptionProvided =
true;
187 if ($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE)) {
188 $this->setAreaCode();
189 $rollbackHandler->dbRollback($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE), $keepSourceFile);
190 $inputOptionProvided =
true;
192 if (!$inputOptionProvided) {
193 throw new \InvalidArgumentException(
194 'Not enough information provided to roll back.' 204 private function setAreaCode()
206 $areaCode =
'adminhtml';
208 $appState = $this->objectManager->get(\
Magento\Framework\
App\State::class);
209 $appState->setAreaCode($areaCode);
211 $configLoader = $this->objectManager->get(\
Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
212 $this->objectManager->configure($configLoader->load($areaCode));
const INPUT_KEY_MEDIA_BACKUP_FILE
const INPUT_KEY_DB_BACKUP_FILE
const INPUT_KEY_CODE_BACKUP_FILE
execute(InputInterface $input, OutputInterface $output)
__construct(ObjectManagerProvider $objectManagerProvider, MaintenanceMode $maintenanceMode, DeploymentConfig $deploymentConfig, MaintenanceModeEnabler $maintenanceModeEnabler=null)