5 * Contains \Drupal\Console\Command\Module\DownloadCommand.
8 namespace Drupal\Console\Command\Module;
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\Core\Style\DrupalStyle;
18 use Drupal\Console\Utils\DrupalApi;
19 use GuzzleHttp\Client;
20 use Drupal\Console\Extension\Manager;
21 use Drupal\Console\Utils\Validator;
22 use Drupal\Console\Utils\Site;
23 use Drupal\Console\Core\Utils\ConfigurationManager;
24 use Drupal\Console\Core\Utils\ShellProcess;
26 class DownloadCommand extends Command
29 use ProjectDownloadTrait;
39 protected $httpClient;
49 protected $extensionManager;
57 * @var ConfigurationManager
59 protected $configurationManager;
64 protected $shellProcess;
72 * DownloadCommand constructor.
74 * @param DrupalApi $drupalApi
75 * @param Client $httpClient
77 * @param Manager $extensionManager
78 * @param Validator $validator
80 * @param ConfigurationManager $configurationManager
81 * @param ShellProcess $shellProcess
84 public function __construct(
88 Manager $extensionManager,
91 ConfigurationManager $configurationManager,
92 ShellProcess $shellProcess,
95 $this->drupalApi = $drupalApi;
96 $this->httpClient = $httpClient;
97 $this->appRoot = $appRoot;
98 $this->extensionManager = $extensionManager;
99 $this->validator = $validator;
101 $this->configurationManager = $configurationManager;
102 $this->shellProcess = $shellProcess;
104 parent::__construct();
107 protected function configure()
110 ->setName('module:download')
111 ->setDescription($this->trans('commands.module.download.description'))
114 InputArgument::IS_ARRAY,
115 $this->trans('commands.module.download.arguments.module')
120 InputOption::VALUE_OPTIONAL,
121 $this->trans('commands.module.download.options.path')
126 InputOption::VALUE_NONE,
127 $this->trans('commands.module.download.options.latest')
132 InputOption::VALUE_NONE,
133 $this->trans('commands.module.install.options.composer')
138 InputOption::VALUE_NONE,
139 $this->trans('commands.module.install.options.unstable')
146 protected function interact(InputInterface $input, OutputInterface $output)
148 $io = new DrupalStyle($input, $output);
149 $composer = $input->getOption('composer');
150 $module = $input->getArgument('module');
153 $module = $this->modulesQuestion($io);
154 $input->setArgument('module', $module);
158 $path = $input->getOption('path');
161 $this->trans('commands.module.download.questions.path'),
164 $input->setOption('path', $path);
172 protected function execute(InputInterface $input, OutputInterface $output)
174 $io = new DrupalStyle($input, $output);
176 $modules = $input->getArgument('module');
177 $latest = $input->getOption('latest');
178 $path = $input->getOption('path');
179 $composer = $input->getOption('composer');
183 foreach ($modules as $module) {
185 $versions = $this->drupalApi
186 ->getPackagistModuleReleases($module, 10, $unstable);
192 'commands.module.download.messages.no-releases'
200 $version = $io->choice(
203 'commands.site.new.questions.composer-release'
211 $versions = $this->drupalApi
212 ->getPackagistModuleReleases($module, 10, $unstable);
218 'commands.module.download.messages.no-releases'
227 ->getPackagistModuleReleases($module, 1, $unstable)
232 // Register composer repository
233 $command = "composer config repositories.drupal composer https://packagist.drupal-composer.org";
234 $this->shellProcess->exec($command, $this->root);
237 'composer require drupal/%s:%s --prefer-dist --optimize-autoloader --sort-packages --update-no-dev',
242 if ($this->shellProcess->exec($command, $this->root)) {
245 $this->trans('commands.module.download.messages.composer'),
252 $this->downloadModules($io, $modules, $latest, $path);