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