Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Theme / UninstallCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Theme\UninstallCommand.
6  */
7
8 namespace Drupal\Console\Command\Theme;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Core\Config\UnmetDependenciesException;
14
15 class UninstallCommand extends ThemeBaseCommand
16 {
17     protected function configure()
18     {
19         $this
20             ->setName('theme:uninstall')
21             ->setDescription($this->trans('commands.theme.uninstall.description'))
22             ->addArgument(
23                 'theme',
24                 InputArgument::IS_ARRAY,
25                 $this->trans('commands.theme.uninstall.options.theme')
26             )
27             ->setAliases(['thu']);
28     }
29
30     /**
31      * {@inheritdoc}
32      */
33     protected function interact(InputInterface $input, OutputInterface $output)
34     {
35         $titleTranslatableString = 'commands.theme.uninstall.messages.installed-themes';
36         $questionTranslatableString = 'commands.theme.uninstall.questions.theme';
37         $autocompleteAvailableThemes = $this->getAutoCompleteList(0);
38         $this->getThemeArgument($titleTranslatableString, $questionTranslatableString, $autocompleteAvailableThemes);
39     }
40
41     protected function execute(InputInterface $input, OutputInterface $output)
42     {
43         $config = $this->configFactory->getEditable('system.theme');
44         $this->themeHandler->refreshInfo();
45         $theme = $input->getArgument('theme');
46         $this->prepareThemesArrays($theme);
47
48         if (count($this->getAvailableThemes()) > 0) {
49             try {
50                 foreach ($this->getAvailableThemes() as $themeKey => $themeName) {
51                     if ($themeKey === $config->get('default')) {
52                         $this->setInfoMessage('commands.theme.uninstall.messages.error-default-theme', $this->getAvailableThemes());
53                         return 1;
54                     }
55
56                     if ($themeKey === $config->get('admin')) {
57                         $this->setErrorMessage('commands.theme.uninstall.messages.error-admin-theme', $this->getAvailableThemes());
58                         return 1;
59                     }
60                 }
61
62                 $this->themeHandler->uninstall($theme);
63
64                 if (count($this->getAvailableThemes()) > 1) {
65                     $this->setInfoMessage('commands.theme.uninstall.messages.themes-success', $this->getAvailableThemes());
66                 } else {
67                     $this->setInfoMessage('commands.theme.uninstall.messages.theme-success', array_shift($this->getAvailableThemes()));
68                 }
69             } catch (UnmetDependenciesException $e) {
70                 $this->setErrorMessage('commands.theme.uninstall.messages.dependencies', $this->getMessage());
71                 return 1;
72             }
73         } elseif (empty($this->getAvailableThemes()) && count($this->getUninstalledThemes()) > 0) {
74             if (count($this->getUninstalledThemes()) > 1) {
75                 $this->setInfoMessage('commands.theme.uninstall.messages.themes-nothing', $this->getUninstalledThemes());
76             } else {
77                 $this->setInfoMessage('commands.theme.uninstall.messages.theme-nothing', $this->getUninstalledThemes());
78             }
79         } else {
80             if (count($this->getUnavailableThemes()) > 1) {
81                 $this->setErrorMessage('commands.theme.uninstall.messages.themes-missing', $this->getUnavailableThemes());
82             } else {
83                 $this->setErrorMessage('commands.theme.uninstall.messages.theme-missing', $this->getUnavailableThemes());
84             }
85         }
86
87         // Run cache rebuild to see changes in Web UI
88         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
89
90         return 0;
91     }
92 }