Skip to content

Commit

Permalink
Add option install theme with release version (#4158)
Browse files Browse the repository at this point in the history
* Add option install theme with realease version

* Add validation theme:install not found theme
  • Loading branch information
gilbertomangones authored and enzolutions committed Sep 24, 2019
1 parent e9e4d3a commit 44c8d8c
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/services/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 44 additions & 1 deletion src/Command/Shared/ProjectDownloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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':
Expand Down
16 changes: 15 additions & 1 deletion src/Command/Theme/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
51 changes: 47 additions & 4 deletions src/Command/Theme/ThemeBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand All @@ -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();
}
Expand Down
16 changes: 16 additions & 0 deletions src/Utils/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44c8d8c

Please sign in to comment.