/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('<info>Status: maintenance mode is ' . ($this->maintenanceMode->isOn() ? 'active' : 'not active') . '</info>'); $addressInfo = $this->maintenanceMode->getAddressInfo(); $addresses = implode(', ', $addressInfo); $output->writeln('<info>List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none') . '</info>'); }
/** * @return ViewModel */ public function indexAction() { $this->maintenanceMode->set(false); $view = new ViewModel(); $view->setTerminal(true); return $view; }
/** * @param array $maintenanceData * @param string $expectedMessage * @dataProvider executeDataProvider */ public function testExecute(array $maintenanceData, $expectedMessage) { $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($maintenanceData[0]); $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($maintenanceData[1]); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertEquals($expectedMessage, $tester->getDisplay()); }
/** * @param array $input * @param string $expectedMessage * @dataProvider executeDataProvider */ public function testExecute(array $input, $expectedMessage) { $return = isset($input['--ip']) ? $input['--ip'] !== ['none'] ? $input['--ip'] : [] : []; $this->maintenanceMode->expects($this->any())->method('getAddressInfo')->willReturn($return); $tester = new CommandTester($this->command); $tester->execute($input); $this->assertEquals($expectedMessage, $tester->getDisplay()); }
/** * Puts store in maintenance mode * * @return JsonModel */ public function indexAction() { try { $this->maintenanceMode->set(true); return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]); } catch (\Exception $e) { return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'error' => $e->getMessage()]); } }
public function testIndexActionWithExceptions() { $this->maintenanceMode->expects($this->once())->method('set')->will($this->throwException(new \Exception("Test error message"))); $jsonModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\\View\\Model\\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); $this->assertArrayHasKey('responseType', $variables); $this->assertEquals(ResponseTypeInterface::RESPONSE_TYPE_ERROR, $variables['responseType']); $this->assertArrayHasKey('error', $variables); $this->assertEquals("Test error message", $variables['error']); }
/** * Puts store in maintenance mode * * @return JsonModel */ public function indexAction() { try { $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $action = isset($params['disable']) && $params['disable'] ? false : true; $this->maintenanceMode->set($action); return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]); } catch (\Exception $e) { return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'error' => $e->getMessage()]); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $addresses = $input->getOption(self::INPUT_KEY_IP); $this->maintenanceMode->set($this->isEnable()); $output->writeln($this->getDisplayString()); if (!empty($addresses)) { $addresses = implode(',', $addresses); $addresses = 'none' == $addresses ? '' : $addresses; $this->maintenanceMode->setAddresses($addresses); $output->writeln('<info>Set exempt IP-addresses: ' . (implode(', ', $this->maintenanceMode->getAddressInfo()) ?: 'none') . '</info>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption(self::INPUT_KEY_NONE)) { $addresses = $input->getArgument(self::INPUT_KEY_IP); if (!empty($addresses)) { $this->maintenanceMode->setAddresses(implode(',', $addresses)); $output->writeln('<info>Set exempt IP-addresses: ' . implode(', ', $this->maintenanceMode->getAddressInfo()) . '</info>'); } } else { $this->maintenanceMode->setAddresses(''); $output->writeln('<info>Set exempt IP-addresses: none</info>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $messages = []; $themePaths = $input->getArgument(self::INPUT_KEY_THEMES); $messages = array_merge($messages, $this->validate($themePaths)); if (!empty($messages)) { $output->writeln($messages); return; } $messages = array_merge($messages, $this->themeValidator->validateIsThemeInUse($themePaths), $this->themeDependencyChecker->checkChildTheme($themePaths), $this->checkDependencies($themePaths)); if (!empty($messages)) { $output->writeln('<error>Unable to uninstall. Please resolve the following issues:</error>' . PHP_EOL . implode(PHP_EOL, $messages)); return; } try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); if ($input->getOption(self::INPUT_KEY_BACKUP_CODE)) { $time = time(); $codeBackup = $this->backupRollbackFactory->create($output); $codeBackup->codeBackup($time); } $this->themeUninstaller->uninstallRegistry($output, $themePaths); $this->themeUninstaller->uninstallCode($output, $themePaths); $this->cleanup($input, $output); $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); $output->writeln('<error>Please disable maintenance mode after you resolved above issues</error>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA) || $input->getOption(self::INPUT_KEY_DB))) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); return; } try { $inputOptionProvided = false; $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $time = time(); $backupHandler = $this->backupRollbackFactory->create($output); if ($input->getOption(self::INPUT_KEY_CODE)) { $backupHandler->codeBackup($time); $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_MEDIA)) { $backupHandler->codeBackup($time, Factory::TYPE_MEDIA); $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_DB)) { $backupHandler->dbBackup($time); $inputOptionProvided = true; } if (!$inputOptionProvided) { throw new \InvalidArgumentException('Not enough information provided to take backup.'); } } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } finally { $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } }
/** * @param array $input * @param array $validatorMessages * @param string $expectedMessage * @dataProvider executeDataProvider */ public function testExecute(array $input, array $validatorMessages, $expectedMessage) { if (isset($input['--none']) && !$input['--none'] && isset($input['ip'])) { $this->ipValidator->expects($this->once())->method('validateIps')->willReturn($validatorMessages); if (empty($validatorMessages) && !empty($input['ip'])) { $this->maintenanceMode->expects($this->once())->method('setAddresses')->with(implode(',', $input['ip'])); $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($input['ip']); } } elseif (isset($input['--none']) && $input['--none']) { $this->ipValidator->expects($this->never())->method('validateIps')->willReturn($validatorMessages); $this->maintenanceMode->expects($this->once())->method('setAddresses')->with(''); } $tester = new CommandTester($this->command); $tester->execute($input); $this->assertEquals($expectedMessage, $tester->getDisplay()); }
/** * Create Backup * * @return $this */ public function execute() { if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) { return $this; } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(true); } $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE); $this->_errors = []; try { $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir()); $this->_coreRegistry->register('backup_manager', $backupManager); if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) { $backupManager->setRootDir($this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($this->_backupData->getBackupIgnorePaths()); } $backupManager->create(); $message = $this->_backupData->getCreateSuccessMessageByType($type); $this->_logger->info($message); } catch (\Exception $e) { $this->_errors[] = $e->getMessage(); $this->_errors[] = $e->getTrace(); $this->_logger->info($e->getMessage()); $this->_logger->critical($e); } if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) { $this->maintenanceMode->set(false); } return $this; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE) || $input->getOption(self::INPUT_KEY_DB_BACKUP_FILE))) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $returnValue = \Magento\Framework\Console\Cli::RETURN_SUCCESS; try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>', false); if (!$helper->ask($input, $output, $question) && $input->isInteractive()) { return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $this->doRollback($input, $output); $output->writeln('<info>Please set file permission of bin/magento to executable</info>'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); // we must have an exit code higher than zero to indicate something was wrong $returnValue = \Magento\Framework\Console\Cli::RETURN_FAILURE; } finally { $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } return $returnValue; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $addresses = $input->getOption(self::INPUT_KEY_IP); $messages = $this->validate($addresses); if (!empty($messages)) { $output->writeln('<error>' . implode('</error>' . PHP_EOL . '<error>', $messages)); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $this->maintenanceMode->set($this->isEnable()); $output->writeln($this->getDisplayString()); if (!empty($addresses)) { $addresses = implode(',', $addresses); $addresses = 'none' == $addresses ? '' : $addresses; $this->maintenanceMode->setAddresses($addresses); $output->writeln('<info>Set exempt IP-addresses: ' . (implode(', ', $this->maintenanceMode->getAddressInfo()) ?: 'none') . '</info>'); } }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln('<error>You cannot run this command because the Magento application is not installed.</error>'); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $modules = $input->getArgument(self::INPUT_KEY_MODULES); // validate modules input $messages = $this->validate($modules); if (!empty($messages)) { $output->writeln($messages); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } // check dependencies $dependencyMessages = $this->checkDependencies($modules); if (!empty($dependencyMessages)) { $output->writeln($dependencyMessages); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('You are about to remove code and/or database tables. Are you sure?[y/N]', false); if (!$helper->ask($input, $output, $question) && $input->isInteractive()) { return \Magento\Framework\Console\Cli::RETURN_FAILURE; } try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $this->takeBackup($input, $output); $dbBackupOption = $input->getOption(self::INPUT_KEY_BACKUP_DB); if ($input->getOption(self::INPUT_KEY_REMOVE_DATA)) { $this->removeData($modules, $output, $dbBackupOption); } else { if (!empty($this->collector->collectUninstall())) { $question = new ConfirmationQuestion('You are about to remove a module(s) that might have database data. ' . 'Do you want to remove the data from database?[y/N]', false); if ($helper->ask($input, $output, $question) || !$input->isInteractive()) { $this->removeData($modules, $output, $dbBackupOption); } } else { $output->writeln('<info>You are about to remove a module(s) that might have database data. ' . 'Remove the database data manually after uninstalling, if desired.</info>'); } } $this->moduleRegistryUninstaller->removeModulesFromDb($output, $modules); $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($output, $modules); $this->moduleUninstaller->uninstallCode($output, $modules); $this->cleanup($input, $output); $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); $output->writeln('<error>Please disable maintenance mode after you resolved above issues</error>'); return \Magento\Framework\Console\Cli::RETURN_FAILURE; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption(self::INPUT_KEY_NONE)) { $addresses = $input->getArgument(self::INPUT_KEY_IP); $messages = $this->validate($addresses); if (!empty($messages)) { $output->writeln('<error>' . implode('</error>' . PHP_EOL . '<error>', $messages)); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } if (!empty($addresses)) { $this->maintenanceMode->setAddresses(implode(',', $addresses)); $output->writeln('<info>Set exempt IP-addresses: ' . implode(', ', $this->maintenanceMode->getAddressInfo()) . '</info>'); } } else { $this->maintenanceMode->setAddresses(''); $output->writeln('<info>Set exempt IP-addresses: none</info>'); } }
/** * @param array $addresses * @param int $logCount * @param int $setAddressesCount * * @dataProvider maintenanceActionWithAddressDataProvider */ public function testMaintenanceActionWithAddress($addresses, $logCount, $setAddressesCount) { $mapGetParam = [['set', null, true], ['addresses', null, $addresses]]; $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam)); $this->maintenanceMode->expects($this->exactly(1))->method('set'); $this->maintenanceMode->expects($this->exactly($setAddressesCount))->method('setAddresses'); $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn(true); $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($addresses); $this->consoleLogger->expects($this->exactly($logCount))->method('log'); $this->controller->maintenanceAction(); }
public function testOffSetMultipleAddresses() { $mapisExist = [[MaintenanceMode::FLAG_FILENAME, false], [MaintenanceMode::IP_FILENAME, true]]; $this->flagDir->expects($this->any())->method('isExist')->will($this->returnValueMap($mapisExist)); $this->flagDir->expects($this->any())->method('delete')->will($this->returnValueMap($mapisExist)); $this->flagDir->expects($this->any())->method('readFile')->with(MaintenanceMode::IP_FILENAME)->will($this->returnValue('address1,10.50.60.123')); $expectedArray = ['address1', '10.50.60.123']; $this->model->setAddresses('address1,10.50.60.123'); $this->assertEquals($expectedArray, $this->model->getAddressInfo()); $this->assertFalse($this->model->isOn('address1')); $this->assertFalse($this->model->isOn('address3')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $themePaths = $input->getArgument(self::INPUT_KEY_THEMES); $validationMessages = $this->validate($themePaths); if (!empty($validationMessages)) { $output->writeln($validationMessages); return; } $isThemeInUseMessages = $this->themeValidator->validateIsThemeInUse($themePaths); if (!empty($isThemeInUseMessages)) { $output->writeln($isThemeInUseMessages); return; } $childThemeCheckMessages = $this->checkChildTheme($themePaths); if (!empty($childThemeCheckMessages)) { $output->writeln($childThemeCheckMessages); return; } $dependencyMessages = $this->checkDependencies($themePaths); if (!empty($dependencyMessages)) { $output->writeln($dependencyMessages); return; } try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); if ($input->getOption(self::INPUT_KEY_BACKUP_CODE)) { $time = time(); $codeBackup = $this->backupRollbackFactory->create($output); $codeBackup->codeBackup($time); } $output->writeln('<info>Removing ' . implode(', ', $themePaths) . ' from database'); $this->removeFromDb($themePaths); $output->writeln('<info>Removing ' . implode(', ', $themePaths) . ' from Magento codebase'); $themePackages = []; foreach ($themePaths as $themePath) { $themePackages[] = $this->getPackageName($themePath); } $this->remove->remove($themePackages); $this->cleanup($input, $output); $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); $output->writeln('<error>Please disable maintenance mode after you resolved above issues</error>'); } }
/** * Asserts maintenance mode * * @return void * @throws \Exception */ protected function assertMaintenance() { $isExpected = $this->getIsExpected(self::PARAM_REQUIRE_MAINTENANCE, self::DEFAULT_REQUIRE_MAINTENANCE); if (null === $isExpected) { return; } $this->initObjectManager(); /** @var \Magento\Framework\App\MaintenanceMode $maintenance */ $this->maintenance = $this->objectManager->get('Magento\\Framework\\App\\MaintenanceMode'); $isOn = $this->maintenance->isOn(isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''); if ($isOn && !$isExpected) { $this->errorCode = self::ERR_MAINTENANCE; throw new \Exception('Unable to proceed: the maintenance mode is enabled. '); } if (!$isOn && $isExpected) { $this->errorCode = self::ERR_MAINTENANCE; throw new \Exception('Unable to proceed: the maintenance mode must be enabled first. '); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE) || $input->getOption(self::INPUT_KEY_DB_BACKUP_FILE))) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); return; } try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>', false); if (!$helper->ask($input, $output, $question) && $input->isInteractive()) { return; } $this->doRollback($input, $output); $output->writeln('<info>Please set file permission of bin/magento to executable</info>'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } finally { $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } }
/** * Enables or disables maintenance mode for Magento application * * @param int $value * @return void * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback. */ private function setMaintenanceMode($value) { $this->maintenanceMode->set($value); }
/** * Asserts maintenance mode * * @return void * @throws \Exception */ protected function assertMaintenance() { $isExpected = $this->getIsExpected(self::PARAM_REQUIRE_MAINTENANCE, self::DEFAULT_REQUIRE_MAINTENANCE); if (null === $isExpected) { return; } $this->init(); $isOn = $this->maintenance->isOn(isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''); if ($isOn && !$isExpected) { $this->errorCode = self::ERR_MAINTENANCE; throw new \Exception('Unable to proceed: the maintenance mode is enabled.'); } if (!$isOn && $isExpected) { $this->errorCode = self::ERR_MAINTENANCE; throw new \Exception('Unable to proceed: the maintenance mode must be enabled first.'); } }