From 44c8d8ca612f871e713dad4a351ed42911cbfabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilberto=20Mangones=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2019 18:28:41 -0500 Subject: [PATCH] Add option install theme with release version (#4158) * Add option install theme with realease version * Add validation theme:install not found theme --- config/services/theme.yml | 2 +- src/Command/Shared/ProjectDownloadTrait.php | 45 +++++++++++++++++- src/Command/Theme/InstallCommand.php | 16 ++++++- src/Command/Theme/ThemeBaseCommand.php | 51 +++++++++++++++++++-- src/Utils/Validator.php | 16 +++++++ 5 files changed, 123 insertions(+), 7 deletions(-) diff --git a/config/services/theme.yml b/config/services/theme.yml index 74a2ff152..caa51fe6a 100644 --- a/config/services/theme.yml +++ b/config/services/theme.yml @@ -6,7 +6,7 @@ services: - { name: drupal.command } console.theme_install: class: Drupal\Console\Command\Theme\InstallCommand - arguments: ['@config.factory', '@theme_handler', '@console.chain_queue'] + arguments: ['@config.factory', '@theme_handler', '@console.chain_queue', '@console.site', '@console.validator','@module_installer','@console.drupal_api','@console.extension_manager','@app.root'] tags: - { name: drupal.command } console.theme_path: diff --git a/src/Command/Shared/ProjectDownloadTrait.php b/src/Command/Shared/ProjectDownloadTrait.php index cfe750fab..c0eb841af 100644 --- a/src/Command/Shared/ProjectDownloadTrait.php +++ b/src/Command/Shared/ProjectDownloadTrait.php @@ -128,6 +128,49 @@ private function downloadModules($modules, $latest, $path = null, $resultList = return $this->downloadModules($dependencies, $latest, $path, $resultList); } + + private function downloadThemes($themes, $latest, $path = null, $resultList = []) + { + if (!$resultList) { + $resultList = [ + 'invalid' => [], + 'uninstalled' => [], + 'dependencies' => [] + ]; + } + drupal_static_reset('system_rebuild_module_data'); + + $missingThemes = $this->validator->getMissingThemes($themes); + + $invalidModules = []; + if ($missingThemes) { + $this->getIo()->info( + sprintf( + $this->trans('commands.theme.install.messages.theme-missing'), + implode(', ', $missingThemes) + ) + ); + foreach ($missingThemes as $missingTheme) { + $version = $this->releasesQuestion($missingTheme, $latest); + if ($version) { + $this->downloadProject($missingTheme, $version, 'theme', $path); + } else { + $invalidModules[] = $missingTheme; + unset($themes[array_search($missingTheme, $themes)]); + } + $this->extensionManager->discoverModules(); + } + } + $this->themeHandler->install($themes); + + $unInstalledThemes = $this->validator->getUninstalledThemes($themes); + + if (!$unInstalledThemes) { + return 0; + }else{ + return $this->setInfoMessage('commands.theme.install.messages.theme-success', $missingThemes); + } + } protected function calculateDependencies($modules) { @@ -303,7 +346,7 @@ private function getExtractPath($type) case 'module': return 'modules/contrib'; case 'theme': - return 'themes'; + return 'themes/contrib'; case 'profile': return 'profiles'; case 'core': diff --git a/src/Command/Theme/InstallCommand.php b/src/Command/Theme/InstallCommand.php index a63acc79f..aa6888a7a 100644 --- a/src/Command/Theme/InstallCommand.php +++ b/src/Command/Theme/InstallCommand.php @@ -12,9 +12,23 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Drupal\Core\Config\UnmetDependenciesException; +use Drupal\Console\Command\Shared\ProjectDownloadTrait; +use Drupal\Console\Core\Command\Command; +use Drupal\Console\Command\Shared\ModuleTrait; +use Drupal\Console\Utils\Site; +use Drupal\Console\Utils\Validator; +use Drupal\Core\Extension\ModuleInstallerInterface; +use Drupal\Console\Utils\DrupalApi; +use Drupal\Console\Extension\Manager; +use Drupal\Console\Core\Utils\ChainQueue; class InstallCommand extends ThemeBaseCommand { + use ProjectDownloadTrait; + use ModuleTrait; + /** + * {@inheritdoc} + */ protected function configure() { $this @@ -88,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (count($this->getUnavailableThemes()) > 1) { $this->setErrorMessage('commands.theme.install.messages.themes-missing', $this->getUnavailableThemes()); } else { - $this->setErrorMessage('commands.theme.install.messages.themes-missing', $this->getUnavailableThemes()); + $resultList = $this->downloadThemes($theme, $default); } } diff --git a/src/Command/Theme/ThemeBaseCommand.php b/src/Command/Theme/ThemeBaseCommand.php index eb3c1e976..d83f19150 100644 --- a/src/Command/Theme/ThemeBaseCommand.php +++ b/src/Command/Theme/ThemeBaseCommand.php @@ -12,7 +12,11 @@ use Drupal\Core\Config\UnmetDependenciesException; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Console\Core\Utils\ChainQueue; - +use Drupal\Console\Utils\Site; +use Drupal\Console\Utils\Validator; +use Drupal\Core\Extension\ModuleInstallerInterface; +use Drupal\Console\Utils\DrupalApi; +use Drupal\Console\Extension\Manager; /** * Class ThemeBaseCommand * @@ -34,12 +38,34 @@ class ThemeBaseCommand extends Command * @var ChainQueue */ protected $chainQueue; - + /** + * @var Site + */ + protected $site; + /** + * @var Validator + */ + protected $validator; + /** + * @var ModuleInstaller + */ + protected $moduleInstaller; + /** + * @var DrupalApi + */ + protected $drupalApi; + /** + * @var Manager + */ + protected $extensionManager; + /** + * @var string + */ + protected $appRoot; /** * @var array */ protected $themes; - /** * @var array */ @@ -61,15 +87,32 @@ class ThemeBaseCommand extends Command * @param ConfigFactory $configFactory * @param ThemeHandler $themeHandler * @param ChainQueue $chainQueue + * @param Site $site + * @param Validator $validator + * @param ModuleInstaller $moduleInstaller + * @param DrupalApi $drupalApi + * @param Manager $extensionManager + * @param $appRoot */ public function __construct( ConfigFactoryInterface $configFactory, ThemeHandlerInterface $themeHandler, - ChainQueue $chainQueue + ChainQueue $chainQueue, + Site $site, + Validator $validator, + ModuleInstallerInterface $moduleInstaller, + DrupalApi $drupalApi, + Manager $extensionManager, $appRoot ) { $this->configFactory = $configFactory; $this->themeHandler = $themeHandler; $this->chainQueue = $chainQueue; + $this->site = $site; + $this->validator = $validator; + $this->moduleInstaller = $moduleInstaller; + $this->drupalApi = $drupalApi; + $this->extensionManager = $extensionManager; + $this->appRoot = $appRoot; $this->themes = $this->themeHandler->rebuildThemeData(); parent::__construct(); } diff --git a/src/Utils/Validator.php b/src/Utils/Validator.php index c41531684..cf9efd766 100644 --- a/src/Utils/Validator.php +++ b/src/Utils/Validator.php @@ -314,7 +314,23 @@ public function getMissingModules($moduleList) return array_diff($moduleList, $modules); } + + /** + * @param $moduleList + * @return array + */ + public function getMissingThemes($moduleList) + { + + $modules = $this->extensionManager->discoverThemes() + ->showInstalled() + ->showUninstalled() + ->showNoCore() + ->showCore() + ->getList(true); + return array_diff($moduleList, $modules); + } /** * @param $moduleList * @return array