예제 #1
0
 /**
  * Perform setup side uninstall
  *
  * @param OutputInterface $output
  * @param string $componentName
  * @param bool $dataOption
  * @return void
  */
 public function uninstall(OutputInterface $output, $componentName, $dataOption)
 {
     $packageInfo = $this->packageInfoFactory->create();
     // convert to module name
     $moduleName = $packageInfo->getModuleName($componentName);
     if ($dataOption) {
         $this->moduleUninstaller->uninstallData($output, [$moduleName]);
     }
     $this->moduleRegistryUninstaller->removeModulesFromDb($output, [$moduleName]);
     $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($output, [$moduleName]);
 }
 public function testRemoveModulesFromDb()
 {
     $this->output->expects($this->atLeastOnce())->method('writeln');
     $this->dataSetup->expects($this->atLeastOnce())->method('deleteTableRow');
     $this->moduleRegistryUninstaller->removeModulesFromDb($this->output, ['moduleA', 'moduleB']);
 }
 /**
  * {@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;
     }
 }