Esempio n. 1
0
 public function setUp()
 {
     $maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false);
     $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
     $this->objectManager = $this->getMockForAbstractClass(
         'Magento\Framework\ObjectManagerInterface',
         [],
         '',
         false
     );
     $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
     $this->backupRollback = $this->getMock('Magento\Framework\Setup\BackupRollback', [], [], '', false);
     $this->backupRollbackFactory = $this->getMock(
         'Magento\Framework\Setup\BackupRollbackFactory',
         [],
         [],
         '',
         false
     );
     $this->backupRollbackFactory->expects($this->any())
         ->method('create')
         ->willReturn($this->backupRollback);
     $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
     $this->objectManager->expects($this->any())
         ->method('get')
         ->will($this->returnValue($this->backupRollbackFactory));
     $command = new BackupCommand(
         $objectManagerProvider,
         $maintenanceMode,
         $this->deploymentConfig
     );
     $this->tester = new CommandTester($command);
 }
 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));
 }
 public function testExecuteNoBackupOption()
 {
     $dependencies['vendor/language-ua_ua'] = [];
     $this->dependencyChecker->expects($this->once())->method('checkDependencies')->with(['vendor/language-ua_ua'])->willReturn($dependencies);
     $this->composerInfo->expects($this->once())->method('getRootRequiredPackagesAndTypes')->willReturn(['vendor/language-ua_ua' => 'magento2-language']);
     $this->backupRollbackFactory->expects($this->never())->method('create');
     $this->remove->expects($this->once())->method('remove');
     $this->cache->expects($this->once())->method('clean');
     $this->tester->execute(['package' => ['vendor/language-ua_ua']]);
     $this->assertContains('You are removing language package without a code backup.', $this->tester->getDisplay());
 }
Esempio n. 4
0
 /**
  * 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);
     }
 }
 /**
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function setUp()
 {
     $this->deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false);
     $this->fullModuleList = $this->getMock('Magento\\Framework\\Module\\FullModuleList', [], [], '', false);
     $this->maintenanceMode = $this->getMock('Magento\\Framework\\App\\MaintenanceMode', [], [], '', false);
     $objectManagerProvider = $this->getMock('Magento\\Setup\\Model\\ObjectManagerProvider', [], [], '', false);
     $objectManager = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManagerInterface', [], '', false);
     $this->uninstallCollector = $this->getMock('Magento\\Setup\\Model\\UninstallCollector', [], [], '', false);
     $this->packageInfo = $this->getMock('Magento\\Framework\\Module\\PackageInfo', [], [], '', false);
     $packageInfoFactory = $this->getMock('Magento\\Framework\\Module\\PackageInfoFactory', [], [], '', false);
     $packageInfoFactory->expects($this->once())->method('create')->willReturn($this->packageInfo);
     $this->dependencyChecker = $this->getMock('Magento\\Framework\\Module\\DependencyChecker', [], [], '', false);
     $this->backupRollback = $this->getMock('Magento\\Framework\\Setup\\BackupRollback', [], [], '', false);
     $this->backupRollbackFactory = $this->getMock('Magento\\Framework\\Setup\\BackupRollbackFactory', [], [], '', false);
     $this->backupRollbackFactory->expects($this->any())->method('create')->willReturn($this->backupRollback);
     $this->cache = $this->getMock('Magento\\Framework\\App\\Cache', [], [], '', false);
     $this->cleanupFiles = $this->getMock('Magento\\Framework\\App\\State\\CleanupFiles', [], [], '', false);
     $objectManagerProvider->expects($this->any())->method('get')->willReturn($objectManager);
     $configLoader = $this->getMockForAbstractClass('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface', [], '', false);
     $configLoader->expects($this->any())->method('load')->willReturn([]);
     $objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\Module\\PackageInfoFactory', $packageInfoFactory], ['Magento\\Framework\\Module\\DependencyChecker', $this->dependencyChecker], ['Magento\\Framework\\App\\Cache', $this->cache], ['Magento\\Framework\\App\\State\\CleanupFiles', $this->cleanupFiles], ['Magento\\Framework\\App\\State', $this->getMock('Magento\\Framework\\App\\State', [], [], '', false)], ['Magento\\Framework\\Setup\\BackupRollbackFactory', $this->backupRollbackFactory], ['Magento\\Framework\\ObjectManager\\ConfigLoaderInterface', $configLoader]]));
     $composer = $this->getMock('Magento\\Framework\\Composer\\ComposerInformation', [], [], '', false);
     $composer->expects($this->any())->method('getRootRequiredPackages')->willReturn(['magento/package-a', 'magento/package-b']);
     $this->moduleUninstaller = $this->getMock('Magento\\Setup\\Model\\ModuleUninstaller', [], [], '', false);
     $this->moduleRegistryUninstaller = $this->getMock('Magento\\Setup\\Model\\ModuleRegistryUninstaller', [], [], '', false);
     $this->command = new ModuleUninstallCommand($composer, $this->deploymentConfig, $this->fullModuleList, $this->maintenanceMode, $objectManagerProvider, $this->uninstallCollector, $this->moduleUninstaller, $this->moduleRegistryUninstaller);
     $this->question = $this->getMock('Symfony\\Component\\Console\\Helper\\QuestionHelper', [], [], '', false);
     $this->question->expects($this->any())->method('ask')->will($this->returnValue(true));
     $this->helperSet = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet', [], [], '', false);
     $this->helperSet->expects($this->any())->method('get')->with('question')->will($this->returnValue($this->question));
     $this->command->setHelperSet($this->helperSet);
     $this->tester = new CommandTester($this->command);
 }
 /**
  * {@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>');
     }
 }
Esempio n. 8
0
 /**
  * {@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);
     }
 }
Esempio n. 9
0
 public function setUp()
 {
     $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
     $maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false);
     $this->objectManager = $this->getMockForAbstractClass(
         'Magento\Framework\ObjectManagerInterface',
         [],
         '',
         false
     );
     $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
     $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
     $this->backupRollback = $this->getMock('Magento\Framework\Setup\BackupRollback', [], [], '', false);
     $this->backupRollbackFactory = $this->getMock(
         'Magento\Framework\Setup\BackupRollbackFactory',
         [],
         [],
         '',
         false
     );
     $this->backupRollbackFactory->expects($this->any())
         ->method('create')
         ->willReturn($this->backupRollback);
     $this->objectManager->expects($this->any())
         ->method('get')
         ->will($this->returnValueMap([
             ['Magento\Framework\Setup\BackupRollbackFactory', $this->backupRollbackFactory],
         ]));
     $this->helperSet = $this->getMock('Symfony\Component\Console\Helper\HelperSet', [], [], '', false);
     $this->question = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper', [], [], '', false);
     $this->question
         ->expects($this->any())
         ->method('ask')
         ->will($this->returnValue(true));
     $this->helperSet
         ->expects($this->any())
         ->method('get')
         ->with('question')
         ->will($this->returnValue($this->question));
     $this->command = new RollbackCommand(
         $objectManagerProvider,
         $maintenanceMode,
         $this->deploymentConfig
     );
     $this->command->setHelperSet($this->helperSet);
     $this->tester = new CommandTester($this->command);
 }
Esempio n. 10
0
 public function testExecuteWithBackupCode()
 {
     $this->setUpExecute();
     $backupRollback = $this->getMock('Magento\\Framework\\Setup\\BackupRollback', [], [], '', false);
     $this->backupRollbackFactory->expects($this->once())->method('create')->willReturn($backupRollback);
     $this->tester->execute(['theme' => ['test'], '--backup-code' => true]);
     $this->tester->getDisplay();
 }
Esempio n. 11
0
 /**
  * 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);
     }
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Could not complete
  */
 public function testExceptionOnExecute()
 {
     $this->backupRollbackFactory->expects($this->once())->method('create')->willThrowException(new \Exception());
     $this->jobDbRollback->execute();
 }
Esempio n. 14
0
 /**
  * {@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>');
     }
 }