From 28c7dbd2859271230bd15f2bd61f7a8a8894c182 Mon Sep 17 00:00:00 2001 From: krisawzm Date: Sat, 25 Apr 2015 03:57:40 +0200 Subject: [PATCH 1/4] - Adds artisan command october:fresh for removing the demo included with October. - Adds new artisan commands related to themes: theme:list List all available themes (in marketplace.) theme:use Switch the active theme. theme:install Install a theme from the marketplace. theme:delete Delete an existing theme. This could make the development workflow for setting up a new project alot quicker. For instance, take a look at https://github.com/krisawzm/blank-theme This is just a blank scaffolding theme that you can build on. You could install it by simply running php artisan theme:install krisawzm.blank - after running october:fresh, of course. --- modules/system/ServiceProvider.php | 7 ++ modules/system/console/OctoberFresh.php | 69 ++++++++++++++ modules/system/console/ThemeDelete.php | 76 ++++++++++++++++ modules/system/console/ThemeInstall.php | 116 ++++++++++++++++++++++++ modules/system/console/ThemeList.php | 74 +++++++++++++++ modules/system/console/ThemeUse.php | 81 +++++++++++++++++ 6 files changed, 423 insertions(+) create mode 100644 modules/system/console/OctoberFresh.php create mode 100644 modules/system/console/ThemeDelete.php create mode 100644 modules/system/console/ThemeInstall.php create mode 100644 modules/system/console/ThemeList.php create mode 100644 modules/system/console/ThemeUse.php diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 0cfda6edb..072238377 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -310,10 +310,17 @@ class ServiceProvider extends ModuleServiceProvider $this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate'); $this->registerConsoleCommand('october.util', 'System\Console\OctoberUtil'); $this->registerConsoleCommand('october.mirror', 'System\Console\OctoberMirror'); + $this->registerConsoleCommand('october.mirror', 'System\Console\OctoberFresh'); + $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove'); $this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh'); + $this->registerConsoleCommand('theme.use', 'System\Console\ThemeUse'); + $this->registerConsoleCommand('theme.list', 'System\Console\ThemeList'); + $this->registerConsoleCommand('theme.install', 'System\Console\ThemeInstall'); + $this->registerConsoleCommand('theme.delete', 'System\Console\ThemeDelete'); + /* * Register the sidebar for the System main menu */ diff --git a/modules/system/console/OctoberFresh.php b/modules/system/console/OctoberFresh.php new file mode 100644 index 000000000..f8a7e348f --- /dev/null +++ b/modules/system/console/OctoberFresh.php @@ -0,0 +1,69 @@ +confirmToProceed('Are you sure?')) { + return; + } + + $demoThemePath = themes_path().'/demo'; + + if (File::exists($demoThemePath)) { + Artisan::call('plugin:remove', ['name' => 'October.Demo', '--force' => true]); + File::deleteDirectory($demoThemePath); + + $this->info('Demo has been removed! Enjoy a fresh start.'); + } + else { + $this->error('Demo theme is already removed.'); + } + } + + /** + * Get the console command arguments. + */ + protected function getArguments() + { + return []; + } + + /** + * Get the console command options. + */ + protected function getOptions() + { + return []; + } +} diff --git a/modules/system/console/ThemeDelete.php b/modules/system/console/ThemeDelete.php new file mode 100644 index 000000000..3ca2f1737 --- /dev/null +++ b/modules/system/console/ThemeDelete.php @@ -0,0 +1,76 @@ +argument('name'); + + if (!Theme::exists($themeName)) { + return $this->error(sprintf('The theme %s does not exist.', $themeName)); + } + + if (!$this->confirm(sprintf('Do you really wish to delete the theme %s? YOU CAN NOT UNDO THIS! [y|N]', $themeName), false)) { + return; + } + + try { + ThemeManager::instance()->deleteTheme($themeName); + + $this->info(sprintf('The theme %s has been deleted.', $themeName)); + } + catch (\October\Rain\Exception\ApplicationException $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the theme. (directory name)'], + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return []; + } +} diff --git a/modules/system/console/ThemeInstall.php b/modules/system/console/ThemeInstall.php new file mode 100644 index 000000000..e0cd0c22f --- /dev/null +++ b/modules/system/console/ThemeInstall.php @@ -0,0 +1,116 @@ +argument('dirName'); + + if ($argDirName && !preg_match('/^[a-z0-9\_\-]+$/i', $argDirName)) { + return $this->error('Invalid destination directory name.'); + } + + $themeName = $this->argument('name'); + $updateManager = UpdateManager::instance(); + + try { + $themeDetails = $updateManager->requestThemeDetails($themeName); + + if (ThemeManager::instance()->isInstalled($themeDetails['code'])) { + $this->error(sprintf('The theme %s is already installed.', $themeDetails['code'])); + return; + } + + $this->info(sprintf( + "Name: %s\nDescription: %s\nAuthor: %s\nURL: %s\n", + $themeDetails['code'], + $themeDetails['description'], + $themeDetails['author'], + $themeDetails['product_url'])); + + if (!$this->confirm('Do you wish to continue? [Y|n]', true)) { + return; + } + + $this->info('Downloading theme...'); + $updateManager->downloadTheme($themeDetails['code'], $themeDetails['hash']); + + $this->info('Extracting theme...'); + $updateManager->extractTheme($themeDetails['code'], $themeDetails['hash']); + + $dirName = $this->themeCodeToDir($themeDetails['code']); + if ($argDirName) { + File::move(themes_path().'/'.$dirName, themes_path().'/'.$argDirName); + $dirName = $argDirName; + } + + $this->info(sprintf('The theme %s has been installed. (now %s)', $dirName)); + } + catch (\October\Rain\Exception\ApplicationException $e) { + $this->error($e->getMessage()); + } + } + + /** + * Theme code to dir. + * + * @param string $themeCode + * @return string + */ + protected function themeCodeToDir($themeCode) + { + return strtolower(str_replace('.', '-', $themeCode)); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the theme. Eg: AuthorName.ThemeName'], + ['dirName', InputArgument::OPTIONAL, 'Destination directory name for the theme installation.'], + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return []; + } +} diff --git a/modules/system/console/ThemeList.php b/modules/system/console/ThemeList.php new file mode 100644 index 000000000..6c28bd7d4 --- /dev/null +++ b/modules/system/console/ThemeList.php @@ -0,0 +1,74 @@ +isActiveTheme() ? '[*] ' : '[-] '; + $this->info($ln.$loadedThemes[$i]->getId()); + } + + if ($this->option('include-marketplace')) { + + // @todo List everything in the marketplace - not just popular. + + $popularThemes = UpdateManager::instance()->requestPopularProducts('theme'); + $themeManager = ThemeManager::instance(); + + for ($i = 0, $c = count($popularThemes); $i < $c; $i++) { + if (!$themeManager->isInstalled($popularThemes[$i]['code'])) { + $this->info('[ ] '.$popularThemes[$i]['code']); + } + } + } + + $this->info("\n[*] Active [-] Installed [ ] Not installed"); + } + + /** + * Get the console command arguments. + */ + protected function getArguments() + { + return []; + } + + /** + * Get the console command options. + */ + protected function getOptions() + { + return [ + ['include-marketplace', 'm', InputOption::VALUE_NONE, 'Whether or not to include downloadable themes from the October marketplace.'] + ]; + } +} diff --git a/modules/system/console/ThemeUse.php b/modules/system/console/ThemeUse.php new file mode 100644 index 000000000..e7016de3b --- /dev/null +++ b/modules/system/console/ThemeUse.php @@ -0,0 +1,81 @@ +confirmToProceed('Do you really want to change the active theme?')) { + return; + } + + $newThemeName = $this->argument('name'); + $newTheme = Theme::load($newThemeName); + + if (!$newTheme->exists($newThemeName)) { + return $this->error(sprintf('The theme %s does not exist.', $newThemeName)); + } + + if ($newTheme->isActiveTheme()) { + return $this->error(sprintf('%s is already the active theme.', $newTheme->getId())); + } + + $activeTheme = Theme::getActiveTheme(); + $from = $activeTheme ? $activeTheme->getId() : 'nothing'; + + $this->info(sprintf('Switching theme from %s to %s', $from, $newTheme->getId())); + + Theme::setActiveTheme($newThemeName); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the theme. (directory name)'], + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return []; + } +} From 0947a60969684dfbc3dc904f0837dda2491a271a Mon Sep 17 00:00:00 2001 From: krisawzm Date: Sat, 25 Apr 2015 04:10:51 +0200 Subject: [PATCH 2/4] Fixes missing argument for sprintf --- modules/system/console/ThemeInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/console/ThemeInstall.php b/modules/system/console/ThemeInstall.php index e0cd0c22f..795c20d2e 100644 --- a/modules/system/console/ThemeInstall.php +++ b/modules/system/console/ThemeInstall.php @@ -75,7 +75,7 @@ class ThemeInstall extends Command $dirName = $argDirName; } - $this->info(sprintf('The theme %s has been installed. (now %s)', $dirName)); + $this->info(sprintf('The theme %s has been installed. (now %s)', $themeDetails['code'], $dirName)); } catch (\October\Rain\Exception\ApplicationException $e) { $this->error($e->getMessage()); From a670f61c922da5d50239296229d76be4d94e6f4b Mon Sep 17 00:00:00 2001 From: krisawzm Date: Sat, 25 Apr 2015 19:52:23 +0200 Subject: [PATCH 3/4] Fixes typo for october.fresh artisan command --- modules/system/ServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 072238377..d2adf8fa3 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -310,7 +310,7 @@ class ServiceProvider extends ModuleServiceProvider $this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate'); $this->registerConsoleCommand('october.util', 'System\Console\OctoberUtil'); $this->registerConsoleCommand('october.mirror', 'System\Console\OctoberMirror'); - $this->registerConsoleCommand('october.mirror', 'System\Console\OctoberFresh'); + $this->registerConsoleCommand('october.fresh', 'System\Console\OctoberFresh'); $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove'); From 6c925ff51ec19d939caad784bca54e6cff387750 Mon Sep 17 00:00:00 2001 From: krisawzm Date: Sun, 26 Apr 2015 20:16:38 +0200 Subject: [PATCH 4/4] 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.'] ]; } }