/** * {@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); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); return; } /** @var DbVersionInfo $dbVersionInfo */ $dbVersionInfo = $this->objectManagerProvider->get()->get('Magento\\Framework\\Module\\DbVersionInfo'); $outdated = $dbVersionInfo->getDbVersionErrors(); if (!empty($outdated)) { $output->writeln("<info>The module code base doesn't match the DB schema and data.</info>"); $versionParser = new VersionParser(); $codebaseUpdateNeeded = false; foreach ($outdated as $row) { if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') { // check if module code base update is needed $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]); $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]); if ($requiredVersion->matches($currentVersion)) { $codebaseUpdateNeeded = true; } } $output->writeln(sprintf("<info>%20s %10s: %11s -> %-11s</info>", $row[DbVersionInfo::KEY_MODULE], $row[DbVersionInfo::KEY_TYPE], $row[DbVersionInfo::KEY_CURRENT], $row[DbVersionInfo::KEY_REQUIRED])); } if ($codebaseUpdateNeeded) { $output->writeln('<info>Some modules use code versions newer or older than the database. ' . "First update the module code, then run 'setup:upgrade'.</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } else { $output->writeln("<info>Run 'setup:upgrade' to update your DB schema and data.</info>"); } } else { $output->writeln('<info>All modules are up to date.</info>'); } }
/** * {@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) { $notification = 'setup-cron: Please check var/log/update.log for execution summary.'; if (!$this->deploymentConfig->isAvailable()) { $output->writeln($notification); $this->status->add('Magento is not installed.', \Psr\Log\LogLevel::INFO); return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } if (!$this->checkRun()) { $output->writeln($notification); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } try { $this->status->toggleUpdateInProgress(); } catch (\RuntimeException $e) { $this->status->add($e->getMessage(), \Psr\Log\LogLevel::ERROR); $output->writeln($notification); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $returnCode = $this->executeJobsFromQueue(); if ($returnCode != \Magento\Framework\Console\Cli::RETURN_SUCCESS) { $output->writeln($notification); } return $returnCode; }
public function testNotAvailableThenAvailable() { $this->reader->expects($this->at(0))->method('load')->willReturn([]); $this->reader->expects($this->at(1))->method('load')->willReturn([ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE => 1]); $object = new DeploymentConfig($this->reader); $this->assertFalse($object->isAvailable()); $this->assertTrue($object->isAvailable()); }
public function testNotAvailableThenAvailable() { $this->reader->expects($this->at(0))->method('load')->willReturn([]); $this->reader->expects($this->at(1))->method('load')->willReturn(['a' => 1]); $object = new DeploymentConfig($this->reader); $this->assertFalse($object->isAvailable()); $this->assertTrue($object->isAvailable()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>Store settings can't be saved because the Magento application is not installed.</info>"); return; } $installer = $this->installerFactory->create(new ConsoleLogger($output)); $installer->installUserConfig($input->getOptions()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>No information is available: the application is not installed.</info>"); return; } $installer = $this->installFactory->create(new ConsoleLogger($output)); $installer->installSchema(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $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; } $installer = $this->installFactory->create(new ConsoleLogger($output)); $installer->installDataFixtures(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>Store settings can't be saved because 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; } $errors = $this->validate($input); if ($errors) { $output->writeln($errors); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $installer = $this->installerFactory->create(new ConsoleLogger($output)); $installer->installUserConfig($input->getOptions()); }
/** * Checks that application is installed and DI resources are cleared * * @return string[] */ private function checkEnvironment() { $messages = []; if (!$this->deploymentConfig->isAvailable()) { $messages[] = 'You cannot run this command because the Magento application is not installed.'; } return $messages; }
/** * {@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; } }
/** * Checks that application is installed and DI resources are cleared * * @return string[] */ private function checkEnvironment() { $messages = []; if (!$this->deploymentConfig->isAvailable()) { $messages[] = 'You cannot run this command because the Magento application is not installed.'; } /** * By the time the command is able to execute, the Object Management configuration is already contaminated * by old config info, and it's too late to just clear the files in code. * * TODO: reconfigure OM in runtime so DI resources can be cleared after command launches * */ $path = $this->directoryList->getPath(DirectoryList::DI); if ($this->fileDriver->isExists($path)) { $messages[] = "DI configuration must be cleared before running compiler. Please delete '{$path}'."; } return $messages; }
/** * @param ServiceLocatorInterface $serviceLocator * @param DeploymentConfig $deploymentConfig */ public function __construct(ServiceLocatorInterface $serviceLocator, DeploymentConfig $deploymentConfig) { if ($deploymentConfig->isAvailable()) { $this->navStates = $serviceLocator->get('config')[self::NAV_UPDATER]; $this->navType = self::NAV_UPDATER; $this->titles = $serviceLocator->get('config')[self::NAV_UPDATER . 'Titles']; } else { $this->navStates = $serviceLocator->get('config')[self::NAV_INSTALLER]; $this->navType = self::NAV_INSTALLER; $this->titles = $serviceLocator->get('config')[self::NAV_INSTALLER . 'Titles']; } }
/** * {@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); } }
/** * @return ViewModel|\Zend\Http\Response */ public function indexAction() { if ($this->deploymentConfig->isAvailable()) { $objectManager = $this->objectManagerProvider->get(); /** @var \Magento\Framework\App\State $adminAppState */ $adminAppState = $objectManager->get('Magento\Framework\App\State'); $adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN); $objectManager->create( 'Magento\Backend\Model\Auth\Session', [ 'sessionConfig' => $objectManager->get('Magento\Backend\Model\Session\AdminConfig'), 'appState' => $adminAppState ] ); if (!$objectManager->get('Magento\Backend\Model\Auth')->isLoggedIn()) { $view = new ViewModel(); $view->setTemplate('/error/401.phtml'); $this->getResponse()->setStatusCode(\Zend\Http\Response::STATUS_CODE_401); return $view; } } return new ViewModel(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>You need to install the Magento application before running this utility.</info>"); return; } $options = $input->getOptions(); $languages = $input->getArgument(self::LANGUAGE_OPTION); foreach ($languages as $lang) { if (!$this->validator->isValid($lang)) { throw new \InvalidArgumentException( $lang . ' argument has invalid value, please run info:language:list for list of available locales' ); } } try { $objectManager = $this->objectManagerProvider->get(); // run the deployment logic $filesUtil = $objectManager->create( '\Magento\Framework\App\Utility\Files', ['pathToSource' => BP] ); $objectManagerFactory = $this->objectManagerProvider->getObjectManagerFactory(); /** @var \Magento\Setup\Model\Deployer $deployer */ $deployer = $objectManager->create( 'Magento\Setup\Model\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]] ); $deployer->deploy($objectManagerFactory, $languages); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>>'); if ($output->isVerbose()) { $output->writeln($e->getTraceAsString()); } return; } }
/** * Checks for prior install * * @return void * @throws \Magento\Setup\Exception */ private function checkForPriorInstall() { if ($this->deploymentConfig->isAvailable()) { throw new \Magento\Setup\Exception('Magento application is already installed.'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES); $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL); $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION); if (!$this->deploymentConfig->isAvailable()) { $output->writeln('You cannot run this command because the Magento application is not installed.'); return; } $this->objectManager->get('Magento\Framework\App\Cache')->clean(); $compiledPathsList = [ 'application' => $appCodePath, 'library' => $libraryPath . '/Magento/Framework', 'generated_helpers' => $generationPath ]; $this->excludedPathsList = [ 'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#', 'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#' ]; $dataAttributesIncludePattern = [ 'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/' ]; $this->configureObjectManager($output); $operations = $this->getOperationsConfiguration( $compiledPathsList, $dataAttributesIncludePattern ); try { $this->cleanupFilesystem( [ DirectoryList::CACHE, DirectoryList::GENERATION, DirectoryList::DI, ] ); foreach ($operations as $operationCode => $arguments) { $this->taskManager->addOperation( $operationCode, $arguments ); } /** @var ProgressBar $progressBar */ $progressBar = $this->objectManager->create( 'Symfony\Component\Console\Helper\ProgressBar', [ 'output' => $output, 'max' => count($operations) ] ); $progressBar->setFormat( '<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%' ); $output->writeln('<info>Compilation was started.</info>'); $progressBar->start(); $progressBar->display(); $this->taskManager->process( function (OperationInterface $operation) use ($progressBar) { $progressBar->setMessage($operation->getName() . '...'); $progressBar->display(); }, function (OperationInterface $operation) use ($progressBar) { $progressBar->advance(); } ); $progressBar->finish(); $output->writeln(''); $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>'); } catch (OperationException $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }
/** * Check if Cron job can be run * * @return bool */ private function checkRun() { return $this->deploymentConfig->isAvailable() && $this->readinessCheck->runReadinessCheck() && !$this->status->isUpdateInProgress() && !$this->status->isUpdateError(); }
/** * Loads configuration data only * * @return void */ private function loadConfigData() { if (null === $this->configData && $this->config->isAvailable()) { $this->configData = $this->config->getConfigData(ConfigOptionsList::KEY_MODULES); } }
/** * Validates that deployment configuration exists * * @throws \Magento\Setup\Exception * @return void */ private function assertDeploymentConfigExists() { if (!$this->deploymentConfig->isAvailable()) { throw new \Magento\Setup\Exception( "Can't run this operation: deployment configuration is absent." . " Run 'magento setup:config:set --help' for options." ); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES); $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL); $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION); if (!$this->deploymentConfig->isAvailable()) { $output->writeln('You cannot run this command because the Magento application is not installed.'); return; } $this->objectManager->get('Magento\Framework\App\Cache')->clean(); $compiledPathsList = [ 'application' => $appCodePath, 'library' => $libraryPath . '/Magento/Framework', 'generated_helpers' => $generationPath ]; $this->excludedPathsList = [ 'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#', 'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#' ]; $dataAttributesIncludePattern = [ 'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/' ]; $this->configureObjectManager($output); $operations = [ OperationFactory::REPOSITORY_GENERATOR => [ 'path' => $compiledPathsList['application'], 'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'] ], OperationFactory::DATA_ATTRIBUTES_GENERATOR => [ 'path' => $compiledPathsList['application'], 'filePatterns' => $dataAttributesIncludePattern ], OperationFactory::APPLICATION_CODE_GENERATOR => [ $compiledPathsList['application'], $compiledPathsList['library'], $compiledPathsList['generated_helpers'], ], OperationFactory::INTERCEPTION => [ 'intercepted_paths' => [ $compiledPathsList['application'], $compiledPathsList['library'], $compiledPathsList['generated_helpers'], ], 'path_to_store' => $compiledPathsList['generated_helpers'], ], OperationFactory::AREA_CONFIG_GENERATOR => [ $compiledPathsList['application'], $compiledPathsList['library'], $compiledPathsList['generated_helpers'], ], OperationFactory::INTERCEPTION_CACHE => [ $compiledPathsList['application'], $compiledPathsList['library'], $compiledPathsList['generated_helpers'], ] ]; try { $this->cleanupFilesystem( [ DirectoryList::CACHE, DirectoryList::GENERATION, DirectoryList::DI, ] ); foreach ($operations as $operationCode => $arguments) { $this->taskManager->addOperation( $operationCode, $arguments ); } $this->taskManager->process(); $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>'); } catch (OperationException $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }