5 * Contains \Drupal\Console\Command\Module\DownloadCommand.
8 namespace Drupal\Console\Command\Module;
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\Utils\DrupalApi;
17 use GuzzleHttp\Client;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Utils\Validator;
20 use Drupal\Console\Utils\Site;
21 use Drupal\Console\Core\Utils\ConfigurationManager;
22 use Drupal\Console\Core\Utils\ShellProcess;
24 class DownloadCommand extends Command
26 use ProjectDownloadTrait;
36 protected $httpClient;
46 protected $extensionManager;
54 * @var ConfigurationManager
56 protected $configurationManager;
61 protected $shellProcess;
69 * DownloadCommand constructor.
71 * @param DrupalApi $drupalApi
72 * @param Client $httpClient
74 * @param Manager $extensionManager
75 * @param Validator $validator
77 * @param ConfigurationManager $configurationManager
78 * @param ShellProcess $shellProcess
81 public function __construct(
85 Manager $extensionManager,
88 ConfigurationManager $configurationManager,
89 ShellProcess $shellProcess,
92 $this->drupalApi = $drupalApi;
93 $this->httpClient = $httpClient;
94 $this->appRoot = $appRoot;
95 $this->extensionManager = $extensionManager;
96 $this->validator = $validator;
98 $this->configurationManager = $configurationManager;
99 $this->shellProcess = $shellProcess;
101 parent::__construct();
104 protected function configure()
107 ->setName('module:download')
108 ->setDescription($this->trans('commands.module.download.description'))
111 InputArgument::IS_ARRAY,
112 $this->trans('commands.module.download.arguments.module')
117 InputOption::VALUE_OPTIONAL,
118 $this->trans('commands.module.download.options.path')
123 InputOption::VALUE_NONE,
124 $this->trans('commands.module.download.options.latest')
129 InputOption::VALUE_NONE,
130 $this->trans('commands.module.install.options.composer')
135 InputOption::VALUE_NONE,
136 $this->trans('commands.module.download.options.unstable')
138 ->setAliases(['mod']);
144 protected function interact(InputInterface $input, OutputInterface $output)
146 $composer = $input->getOption('composer');
147 $module = $input->getArgument('module');
150 $module = $this->modulesQuestion();
151 $input->setArgument('module', $module);
155 $path = $input->getOption('path');
157 $path = $this->getIo()->ask(
158 $this->trans('commands.module.download.questions.path'),
161 $input->setOption('path', $path);
169 protected function execute(InputInterface $input, OutputInterface $output)
171 $modules = $input->getArgument('module');
172 $latest = $input->getOption('latest');
173 $path = $input->getOption('path');
174 $composer = $input->getOption('composer');
178 foreach ($modules as $module) {
180 $versions = $this->drupalApi
181 ->getPackagistModuleReleases($module, 10, $unstable);
184 $this->getIo()->error(
187 'commands.module.download.messages.no-releases'
195 $version = $this->getIo()->choice(
198 'commands.site.new.questions.composer-release'
206 $versions = $this->drupalApi
207 ->getPackagistModuleReleases($module, 10, $unstable);
210 $this->getIo()->error(
213 'commands.module.download.messages.no-releases'
222 ->getPackagistModuleReleases($module, 1, $unstable)
227 // Register composer repository
228 $command = "composer config repositories.drupal composer https://packages.drupal.org/8";
229 $this->shellProcess->exec($command, $this->root);
232 'composer require drupal/%s:%s --prefer-dist --optimize-autoloader --sort-packages --update-no-dev',
237 if ($this->shellProcess->exec($command, $this->root)) {
238 $this->getIo()->success(
240 $this->trans('commands.module.download.messages.composer'),
247 $this->downloadModules($modules, $latest, $path);