diff --git a/config/services/module.yml b/config/services/module.yml index e970203dc..6d081eb13 100644 --- a/config/services/module.yml +++ b/config/services/module.yml @@ -6,7 +6,7 @@ services: - { name: drupal.command } console.module_download: class: Drupal\Console\Command\Module\DownloadCommand - arguments: ['@console.drupal_api', '@http_client', '@app.root', '@console.extension_manager', '@console.validator', '@console.site', '@console.configuration_manager', '@console.shell_process', '@console.root'] + arguments: ['@console.drupal_api', '@http_client', '@app.root', '@console.extension_manager', '@console.validator', '@console.site'] tags: - { name: drupal.command } console.module_install: diff --git a/src/Command/Module/DownloadCommand.php b/src/Command/Module/DownloadCommand.php index 84cd9dd3c..27beb0b31 100644 --- a/src/Command/Module/DownloadCommand.php +++ b/src/Command/Module/DownloadCommand.php @@ -7,6 +7,7 @@ namespace Drupal\Console\Command\Module; +use GuzzleHttp\Client; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -14,25 +15,22 @@ use Drupal\Console\Core\Command\Command; use Drupal\Console\Command\Shared\ProjectDownloadTrait; use Drupal\Console\Utils\DrupalApi; -use GuzzleHttp\Client; use Drupal\Console\Extension\Manager; use Drupal\Console\Utils\Validator; use Drupal\Console\Utils\Site; -use Drupal\Console\Core\Utils\ConfigurationManager; -use Drupal\Console\Core\Utils\ShellProcess; class DownloadCommand extends Command { use ProjectDownloadTrait; /** - * @var DrupalApi -*/ + * @var DrupalApi + */ protected $drupalApi; /** - * @var Client -*/ + * @var Client + */ protected $httpClient; /** @@ -41,29 +39,19 @@ class DownloadCommand extends Command protected $appRoot; /** - * @var Manager -*/ + * @var Manager + */ protected $extensionManager; /** - * @var Validator -*/ + * @var Validator + */ protected $validator; /** - * @var ConfigurationManager -*/ - protected $configurationManager; - - /** - * @var ShellProcess -*/ - protected $shellProcess; - - /** - * @var string + * @var Site */ - protected $root; + protected $site; /** * DownloadCommand constructor. @@ -74,9 +62,6 @@ class DownloadCommand extends Command * @param Manager $extensionManager * @param Validator $validator * @param Site $site - * @param ConfigurationManager $configurationManager - * @param ShellProcess $shellProcess - * @param $root */ public function __construct( DrupalApi $drupalApi, @@ -84,10 +69,7 @@ public function __construct( $appRoot, Manager $extensionManager, Validator $validator, - Site $site, - ConfigurationManager $configurationManager, - ShellProcess $shellProcess, - $root + Site $site ) { $this->drupalApi = $drupalApi; $this->httpClient = $httpClient; @@ -95,9 +77,6 @@ public function __construct( $this->extensionManager = $extensionManager; $this->validator = $validator; $this->site = $site; - $this->configurationManager = $configurationManager; - $this->shellProcess = $shellProcess; - $this->root = $root; parent::__construct(); } @@ -123,18 +102,6 @@ protected function configure() InputOption::VALUE_NONE, $this->trans('commands.module.download.options.latest') ) - ->addOption( - 'composer', - null, - InputOption::VALUE_NONE, - $this->trans('commands.module.install.options.composer') - ) - ->addOption( - 'unstable', - null, - InputOption::VALUE_NONE, - $this->trans('commands.module.download.options.unstable') - ) ->setAliases(['mod']); } @@ -143,7 +110,6 @@ protected function configure() */ protected function interact(InputInterface $input, OutputInterface $output) { - $composer = $input->getOption('composer'); $module = $input->getArgument('module'); if (!$module) { @@ -151,15 +117,13 @@ protected function interact(InputInterface $input, OutputInterface $output) $input->setArgument('module', $module); } - if (!$composer) { - $path = $input->getOption('path'); - if (!$path) { - $path = $this->getIo()->ask( - $this->trans('commands.module.download.questions.path'), - 'modules/contrib' - ); - $input->setOption('path', $path); - } + $path = $input->getOption('path'); + if (!$path) { + $path = $this->getIo()->ask( + $this->trans('commands.module.download.questions.path'), + 'modules/contrib' + ); + $input->setOption('path', $path); } } @@ -171,82 +135,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $modules = $input->getArgument('module'); $latest = $input->getOption('latest'); $path = $input->getOption('path'); - $composer = $input->getOption('composer'); - $unstable = true; - - if ($composer) { - foreach ($modules as $module) { - if (!$latest) { - $versions = $this->drupalApi - ->getPackagistModuleReleases($module, 10, $unstable); - - if (!$versions) { - $this->getIo()->error( - sprintf( - $this->trans( - 'commands.module.download.messages.no-releases' - ), - $module - ) - ); - - return 1; - } else { - $version = $this->getIo()->choice( - sprintf( - $this->trans( - 'commands.site.new.questions.composer-release' - ), - $module - ), - $versions - ); - } - } else { - $versions = $this->drupalApi - ->getPackagistModuleReleases($module, 10, $unstable); - - if (!$versions) { - $this->getIo()->error( - sprintf( - $this->trans( - 'commands.module.download.messages.no-releases' - ), - $module - ) - ); - return 1; - } else { - $version = current( - $this->drupalApi - ->getPackagistModuleReleases($module, 1, $unstable) - ); - } - } - - // Register composer repository - $command = 'composer config repositories.drupal composer https://packages.drupal.org/8'; - $this->shellProcess->exec($command, $this->root); - - $command = sprintf( - 'composer require drupal/%s:%s --prefer-dist --optimize-autoloader --sort-packages --update-no-dev', - $module, - $version - ); - - if ($this->shellProcess->exec($command, $this->root)) { - $this->getIo()->success( - sprintf( - $this->trans('commands.module.download.messages.composer'), - $module - ) - ); - } - } - } else { - $this->downloadModules($modules, $latest, $path); - } - return true; + $this->downloadModules($modules, $latest, $path); + + return 1; } } diff --git a/src/Command/Theme/DownloadCommand.php b/src/Command/Theme/DownloadCommand.php index d9180bd29..ddb5c4882 100644 --- a/src/Command/Theme/DownloadCommand.php +++ b/src/Command/Theme/DownloadCommand.php @@ -73,12 +73,7 @@ protected function configure() InputArgument::OPTIONAL, $this->trans('commands.theme.download.arguments.version') ) - ->addOption( - 'composer', - null, - InputOption::VALUE_NONE, - $this->trans('commands.theme.download.options.composer') - )->setAliases(['thd']); + ->setAliases(['thd']); } /** @@ -88,24 +83,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $theme = $input->getArgument('theme'); $version = $input->getArgument('version'); - $composer = $input->getOption('composer'); - - if ($composer) { - if (!is_array($theme)) { - $theme = [$theme]; - } - $this->get('chain_queue')->addCommand( - 'module:download', - [ - 'module' => $theme, - '--composer' => true - ], - true, - true - ); - } else { - $this->downloadProject($theme, $version, 'theme'); + + if(!$version) { + return 1; } + + $this->downloadProject($theme, $version, 'theme'); + + return 1; } /** @@ -115,9 +100,8 @@ protected function interact(InputInterface $input, OutputInterface $output) { $theme = $input->getArgument('theme'); $version = $input->getArgument('version'); - $composer = $input->getOption('composer'); - if (!$version && !$composer) { + if (!$version) { $version = $this->releasesQuestion($theme); $input->setArgument('version', $version); } diff --git a/src/Utils/DrupalApi.php b/src/Utils/DrupalApi.php index d104221d5..57a97d1a5 100644 --- a/src/Utils/DrupalApi.php +++ b/src/Utils/DrupalApi.php @@ -232,86 +232,6 @@ public function downloadFile($url, $destination) return file_exists($destination); } - /** - * Gets Drupal modules releases from Packagist API. - * - * @param string $module - * @param int $limit - * @param bool $unstable - * - * @return array - */ - public function getPackagistModuleReleases($module, $limit = 10, $unstable = true) - { - if (!trim($module)) { - return []; - } - - return $this->getComposerReleases( - sprintf( - 'http://packagist.drupal-composer.org/packages/drupal/%s.json', - trim($module) - ), - $limit, - $unstable - ); - } - - /** - * Gets Drupal releases from Packagist API. - * - * @param string $url - * @param int $limit - * @param bool $unstable - * - * @return array - */ - private function getComposerReleases($url, $limit = 10, $unstable = false) - { - if (!$url) { - return []; - } - - $packagistResponse = $this->httpClient->getUrlAsString($url); - - if ($packagistResponse->getStatusCode() != 200) { - throw new \Exception('Invalid path.'); - } - - try { - $packagistJson = json_decode( - $packagistResponse->getBody()->getContents() - ); - } catch (\Exception $e) { - return []; - } - - $versions = array_keys((array)$packagistJson->package->versions); - - // Remove Drupal 7 versions - $i = 0; - foreach ($versions as $version) { - if (0 === strpos($version, "7.") || 0 === strpos($version, "dev-7.")) { - unset($versions[$i]); - } - $i++; - } - - if (!$unstable) { - foreach ($versions as $key => $version) { - if (strpos($version, "-")) { - unset($versions[$key]); - } - } - } - - if (is_array($versions)) { - return array_slice($versions, 0, $limit); - } - - return []; - } - /** * @Todo: Remove when issue https://www.drupal.org/node/2556025 get resolved *