From 6c925ff51ec19d939caad784bca54e6cff387750 Mon Sep 17 00:00:00 2001 From: krisawzm Date: Sun, 26 Apr 2015 20:16:38 +0200 Subject: [PATCH] Minor changes. --- modules/system/console/ThemeInstall.php | 41 ++++++++++++++++++++----- modules/system/console/ThemeList.php | 2 +- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/system/console/ThemeInstall.php b/modules/system/console/ThemeInstall.php index 795c20d2e..0f2c6486a 100644 --- a/modules/system/console/ThemeInstall.php +++ b/modules/system/console/ThemeInstall.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputArgument; use System\Classes\UpdateManager; use Cms\Classes\ThemeManager; +use Cms\Classes\Theme; use File; class ThemeInstall extends Command @@ -35,21 +36,35 @@ class ThemeInstall extends Command */ public function fire() { + $themeName = $this->argument('name'); $argDirName = $this->argument('dirName'); - if ($argDirName && !preg_match('/^[a-z0-9\_\-]+$/i', $argDirName)) { - return $this->error('Invalid destination directory name.'); + if ($argDirName && $themeName == $argDirName) { + $argDirName = null; } - $themeName = $this->argument('name'); - $updateManager = UpdateManager::instance(); + if ($argDirName) { + if (!preg_match('/^[a-z0-9\_\-]+$/i', $argDirName)) { + return $this->error('Invalid destination directory name.'); + } + + if (Theme::exists($argDirName)) { + return $this->error('A theme named '.$argDirName.' already exists.'); + } + } try { + $themeManager = ThemeManager::instance(); + $updateManager = UpdateManager::instance(); + $themeDetails = $updateManager->requestThemeDetails($themeName); - if (ThemeManager::instance()->isInstalled($themeDetails['code'])) { - $this->error(sprintf('The theme %s is already installed.', $themeDetails['code'])); - return; + if ($themeManager->isInstalled($themeDetails['code'])) { + return $this->error(sprintf('The theme %s is already installed.', $themeDetails['code'])); + } + + if (Theme::exists($themeDetails['code'])) { + return $this->error('A theme named '.$themeDetails['code'].' already exists.'); } $this->info(sprintf( @@ -70,8 +85,20 @@ class ThemeInstall extends Command $updateManager->extractTheme($themeDetails['code'], $themeDetails['hash']); $dirName = $this->themeCodeToDir($themeDetails['code']); + if ($argDirName) { + /* + * Move downloaded theme to a new directory. + * Basically we're renaming it. + */ File::move(themes_path().'/'.$dirName, themes_path().'/'.$argDirName); + + /* + * Let's make sure to unflag the 'old' theme as + * installed so it can be re-installed later. + */ + $themeManager->setUninstalled($themeDetails['code']); + $dirName = $argDirName; } diff --git a/modules/system/console/ThemeList.php b/modules/system/console/ThemeList.php index 6c28bd7d4..97aab7613 100644 --- a/modules/system/console/ThemeList.php +++ b/modules/system/console/ThemeList.php @@ -68,7 +68,7 @@ class ThemeList extends Command protected function getOptions() { return [ - ['include-marketplace', 'm', InputOption::VALUE_NONE, 'Whether or not to include downloadable themes from the October marketplace.'] + ['include-marketplace', 'm', InputOption::VALUE_NONE, 'Include downloadable themes from the October marketplace.'] ]; } }