public function testValidateIsThemeInUse()
 {
     $theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false);
     $theme->expects($this->once())->method('getId')->willReturn(6);
     $defaultEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'default', 'scope_id' => 8]);
     $websitesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'websites', 'scope_id' => 8]);
     $storesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'stores', 'scope_id' => 8]);
     $this->themeProvider->expects($this->once())->method('getThemeByFullPath')->willReturn($theme);
     $this->configData->expects($this->once())->method('getCollection')->willReturn($this->configData);
     $this->configData->expects($this->at(1))->method('addFieldToFilter')->willReturn($this->configData);
     $this->configData->expects($this->at(2))->method('addFieldToFilter')->willReturn([$defaultEntity, $websitesEntity, $storesEntity]);
     $website = $this->getMock('Magento\\Store\\Model\\Website', ['getName'], [], '', false);
     $website->expects($this->once())->method('getName')->willReturn('websiteA');
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getName'], [], '', false);
     $store->expects($this->once())->method('getName')->willReturn('storeA');
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($website);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $result = $this->themeValidator->validateIsThemeInUse(['frontend/Magento/a']);
     $this->assertEquals(['<error>frontend/Magento/a is in use in default config</error>', '<error>frontend/Magento/a is in use in website websiteA</error>', '<error>frontend/Magento/a is in use in store storeA</error>'], $result);
 }
 /**
  * {@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>');
     }
 }
示例#3
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>');
     }
 }