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 []; + } +}