public function testRemoveModulesFromDeploymentConfig()
 {
     $this->output->expects($this->atLeastOnce())->method('writeln');
     $this->deploymentConfig->expects($this->once())->method('getConfigData')->willReturn(['moduleA' => 1, 'moduleB' => 1, 'moduleC' => 1, 'moduleD' => 1]);
     $this->loader->expects($this->once())->method('load')->willReturn(['moduleC' => [], 'moduleD' => []]);
     $this->writer->expects($this->once())->method('saveConfig')->with([ConfigFilePool::APP_CONFIG => [ConfigOptionsListConstants::KEY_MODULES => ['moduleC' => 1, 'moduleD' => 1]]]);
     $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($this->output, ['moduleA', 'moduleB']);
 }
예제 #2
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 testUninstallRemoveCode()
 {
     $this->moduleRegistryUninstaller->expects($this->never())->method($this->anything());
     $this->output->expects($this->once())->method('writeln');
     $packageInfoFactory = $this->getMock('Magento\\Framework\\Module\\PackageInfoFactory', [], [], '', false);
     $packageInfo = $this->getMock('Magento\\Framework\\Module\\PackageInfo', [], [], '', false);
     $packageInfo->expects($this->atLeastOnce())->method('getPackageName');
     $packageInfoFactory->expects($this->once())->method('create')->willReturn($packageInfo);
     $this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Module\\PackageInfoFactory')->willReturn($packageInfoFactory);
     $this->remove->expects($this->once())->method('remove');
     $this->uninstaller->uninstallCode($this->output, ['moduleA', 'moduleB']);
 }
 public function testInteraction()
 {
     $input = ['module' => ['Magento_A', 'Magento_B']];
     $this->setUpExecute();
     $this->moduleUninstaller->expects($this->once())->method('uninstallCode')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']);
     $this->moduleRegistryUninstaller->expects($this->once())->method('removeModulesFromDb')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']);
     $this->moduleRegistryUninstaller->expects($this->once())->method('removeModulesFromDeploymentConfig')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $input['module']);
     $this->question->expects($this->once())->method('ask')->will($this->returnValue(false));
     $this->helperSet->expects($this->once())->method('get')->with('question')->will($this->returnValue($this->question));
     $this->command->setHelperSet($this->helperSet);
     $this->tester = new CommandTester($this->command);
     $this->tester->execute($input);
 }
 /**
  * {@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;
     }
 }