Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Module / InstallDependencyCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Module\InstallDependencyCommand.
6  */
7
8 namespace Drupal\Console\Command\Module;
9
10 use Drupal\Console\Core\Command\Shared\CommandTrait;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Command\Command;
16 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
17 use Drupal\Console\Command\Shared\ModuleTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Utils\Site;
20 use Drupal\Console\Utils\Validator;
21 use Drupal\Core\ProxyClass\Extension\ModuleInstaller;
22 use Drupal\Console\Core\Utils\ChainQueue;
23
24 /**
25  * Class InstallDependencyCommand
26  *
27  * @package Drupal\Console\Command\Module
28  */
29 class InstallDependencyCommand extends Command
30 {
31     use CommandTrait;
32     use ProjectDownloadTrait;
33     use ModuleTrait;
34
35     /**
36      * @var Site
37      */
38     protected $site;
39
40     /**
41  * @var Validator
42 */
43     protected $validator;
44
45     /**
46  * @var ModuleInstaller
47 */
48     protected $moduleInstaller;
49
50     /**
51      * @var ChainQueue
52      */
53     protected $chainQueue;
54
55     /**
56      * InstallCommand constructor.
57      *
58      * @param Site       $site
59      * @param Validator  $validator
60      * @param ChainQueue $chainQueue
61      */
62     public function __construct(
63         Site $site,
64         Validator $validator,
65         ModuleInstaller $moduleInstaller,
66         ChainQueue $chainQueue
67     ) {
68         $this->site = $site;
69         $this->validator = $validator;
70         $this->moduleInstaller = $moduleInstaller;
71         $this->chainQueue = $chainQueue;
72         parent::__construct();
73     }
74
75     /**
76      * {@inheritdoc}
77      */
78     protected function configure()
79     {
80         $this
81             ->setName('module:dependency:install')
82             ->setDescription($this->trans('commands.module.install.dependencies.description'))
83             ->addArgument(
84                 'module',
85                 InputArgument::IS_ARRAY,
86                 $this->trans('commands.module.install.dependencies.arguments.module')
87             );
88     }
89
90     /**
91      * {@inheritdoc}
92      */
93     protected function interact(InputInterface $input, OutputInterface $output)
94     {
95         $io = new DrupalStyle($input, $output);
96
97         $module = $input->getArgument('module');
98         if (!$module) {
99             // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
100             $module = $this->moduleQuestion($io);
101             $input->setArgument('module', $module);
102         }
103     }
104
105     /**
106      * {@inheritdoc}
107      */
108     protected function execute(InputInterface $input, OutputInterface $output)
109     {
110         $io = new DrupalStyle($input, $output);
111
112         $module = $input->getArgument('module');
113         $unInstalledDependencies = $this->calculateDependencies((array)$module);
114
115         if (!$unInstalledDependencies) {
116             $io->warning($this->trans('commands.module.install.dependencies.messages.no-depencies'));
117             return 0;
118         }
119
120         try {
121             $io->comment(
122                 sprintf(
123                     $this->trans('commands.module.install.dependencies.messages.installing'),
124                     implode(', ', $unInstalledDependencies)
125                 )
126             );
127
128             drupal_static_reset('system_rebuild_module_data');
129
130             $this->moduleInstaller->install($unInstalledDependencies, true);
131             $io->success(
132                 sprintf(
133                     $this->trans('commands.module.install.dependencies.messages.success'),
134                     implode(', ', $unInstalledDependencies)
135                 )
136             );
137         } catch (\Exception $e) {
138             $io->error($e->getMessage());
139
140             return 1;
141         }
142
143         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
144     }
145 }