/**
  * Execute job
  *
  * @throws \RuntimeException
  * @return void
  */
 public function execute()
 {
     try {
         $rollbackHandler = $this->backupRollbackFactory->create($this->output);
         $dbBackupFile = $this->params['backup_file_name'];
         if (!empty($dbBackupFile)) {
             $rollbackHandler->dbRollback(basename($dbBackupFile));
         } else {
             $this->status->add('No available DB backup file found. Please refer to documentation specified ' . 'in <a href=""> doc link </a> to rollback database to a previous version to ');
         }
     } catch (\Exception $e) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()), $e->getCode(), $e);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $languages = $input->getArgument(self::PACKAGE_ARGUMENT);
     $packagesToRemove = [];
     $dependencies = $this->dependencyChecker->checkDependencies($languages, true);
     foreach ($languages as $package) {
         if (!$this->validate($package)) {
             $output->writeln("<info>Package {$package} is not a Magento language and will be skipped.</info>");
         } else {
             if (sizeof($dependencies[$package]) > 0) {
                 $output->writeln("<info>Package {$package} has dependencies and will be skipped.</info>");
             } else {
                 $packagesToRemove[] = $package;
             }
         }
     }
     if ($packagesToRemove !== []) {
         if ($input->getOption(self::BACKUP_CODE_OPTION)) {
             $backupRestore = $this->backupRollbackFactory->create($output);
             $backupRestore->codeBackup(time());
         } else {
             $output->writeln('<info>You are removing language package without a code backup.</info>');
         }
         $output->writeln($this->remove->remove($packagesToRemove));
         $this->cache->clean();
     } else {
         $output->writeln('<info>Nothing is removed.</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);
     }
 }
 public function testCreate()
 {
     $objectManager = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface', [], '', false);
     $consoleLogger = $this->getMock('Magento\\Framework\\Setup\\ConsoleLogger', [], [], '', false);
     $factory = $this->getMock('Magento\\Framework\\Setup\\BackupRollback', [], [], '', false);
     $output = $this->getMockForAbstractClass('Symfony\\Component\\Console\\Output\\OutputInterface', [], '', false);
     $objectManager->expects($this->exactly(2))->method('create')->will($this->returnValueMap([['Magento\\Framework\\Setup\\ConsoleLogger', ['output' => $output], $consoleLogger], ['Magento\\Framework\\Setup\\BackupRollback', ['log' => $consoleLogger], $factory]]));
     $model = new BackupRollbackFactory($objectManager);
     $this->assertInstanceOf('Magento\\Framework\\Setup\\BackupRollback', $model->create($output));
 }
 /**
  * Check rollback options and rolls back appropriately
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  * @throws \InvalidArgumentException
  */
 private function doRollback(InputInterface $input, OutputInterface $output)
 {
     $inputOptionProvided = false;
     $rollbackHandler = $this->backupRollbackFactory->create($output);
     if ($input->getOption(self::INPUT_KEY_CODE_BACKUP_FILE)) {
         $rollbackHandler->codeRollback($input->getOption(self::INPUT_KEY_CODE_BACKUP_FILE));
         $inputOptionProvided = true;
     }
     if ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE)) {
         $rollbackHandler->codeRollback($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE), Factory::TYPE_MEDIA);
         $inputOptionProvided = true;
     }
     if ($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE)) {
         $rollbackHandler->dbRollback($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE));
         $inputOptionProvided = true;
     }
     if (!$inputOptionProvided) {
         throw new \InvalidArgumentException('Not enough information provided to roll back.');
     }
 }
 /**
  * Check backup options and take backup appropriately
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 private function takeBackup(InputInterface $input, OutputInterface $output)
 {
     $time = time();
     if ($input->getOption(self::INPUT_KEY_BACKUP_CODE)) {
         $codeBackup = $this->backupRollbackFactory->create($output);
         $codeBackup->codeBackup($time);
     }
     if ($input->getOption(self::INPUT_KEY_BACKUP_MEDIA)) {
         $mediaBackup = $this->backupRollbackFactory->create($output);
         $mediaBackup->codeBackup($time, Factory::TYPE_MEDIA);
     }
     if ($input->getOption(self::INPUT_KEY_BACKUP_DB)) {
         $dbBackup = $this->backupRollbackFactory->create($output);
         $this->setAreaCode();
         $dbBackup->dbBackup($time);
     }
 }
 /**
  * {@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>');
     }
 }