diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f463a17f..eef7fe2dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ +* **Build 129** (2014-07-25) + - Fixes a bug where the active theme is not editable in the back-end. + - Added a new console command `october:util` for performing utility and maintenance tasks. + - Added new utility command for deleting thumbs in the uploads directory `october:util purge thumbs`. + - Improved console command confirmation dialogs. + * **Build 125** (2014-07-24) - - Theme support added. + - Added support for Themes. - Added new Theme picker to the backend via Settings > Front-end theme - New shorthand method for `$this->getClassExtension('Backend.Behaviors.FormController')` becomes `$this->asExtension('FormController')`. - Buttons inside a popup support new `data-popup-load-indicator` attribute. diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 05438b4b9..b74d2e4ee 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -248,6 +248,7 @@ class ServiceProvider extends ModuleServiceProvider $this->registerConsoleCommand('october.up', 'System\Console\OctoberUp'); $this->registerConsoleCommand('october.down', 'System\Console\OctoberDown'); $this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate'); + $this->registerConsoleCommand('october.util', 'System\Console\OctoberUtil'); $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove'); $this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh'); diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index ade4c4252..0c0185975 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -8,6 +8,8 @@ use Symfony\Component\Console\Input\InputArgument; class OctoberDown extends Command { + use \Illuminate\Console\ConfirmableTrait; + /** * The console command name. */ @@ -31,13 +33,13 @@ class OctoberDown extends Command */ public function fire() { - if ($this->confirm('Destroy all database tables? [yes|no]')) { + if (!$this->confirmToProceed('This will DESTROY all database tables.')) + return; - $manager = UpdateManager::instance()->resetNotes()->uninstall(); + $manager = UpdateManager::instance()->resetNotes()->uninstall(); - foreach ($manager->getNotes() as $note) - $this->output->writeln($note); - } + foreach ($manager->getNotes() as $note) + $this->output->writeln($note); } /** @@ -53,7 +55,18 @@ class OctoberDown extends Command */ protected function getOptions() { - return []; + return [ + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'], + ]; + } + + /** + * Get the default confirmation callback. + * @return \Closure + */ + protected function getDefaultConfirmCallback() + { + return function() { return true; }; } } \ No newline at end of file diff --git a/modules/system/console/OctoberUtil.php b/modules/system/console/OctoberUtil.php new file mode 100644 index 000000000..4a09bb911 --- /dev/null +++ b/modules/system/console/OctoberUtil.php @@ -0,0 +1,119 @@ +argument('name')); + $method = 'util'.studly_case($command); + + if (!method_exists($this, $method)) { + $this->error(sprintf('Utility command "%s" does not exist!', $command)); + return; + } + + $this->$method(); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::IS_ARRAY, 'A utility command to perform.'], + ]; + } + + /** + * Get the console command options. + */ + protected function getOptions() + { + return [ + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], + ]; + } + + // + // Utilties + // + + protected function utilPurgeThumbs() + { + if (!$uploadsDir = Config::get('cms.uploadsDir')) + return $this->error('No uploads directory defined in config (cms.uploadsDir)'); + + if (!$this->confirmToProceed('This will PERMANENTLY DELETE all thumbs in the uploads directory.')) + return; + + $uploadsDir = base_path() . $uploadsDir; + $totalCount = 0; + + /* + * Recursive function to scan the directory for files beginning + * with "thumb_" and repeat itself on directories. + */ + $purgeFunc = function($targetDir) use (&$purgeFunc, &$totalCount) { + if ($files = File::glob($targetDir.'/thumb_*')) { + foreach ($files as $file) { + $this->info('Purged: '. basename($file)); + $totalCount++; + @unlink($file); + } + } + + if ($dirs = File::directories($targetDir)) { + foreach ($dirs as $dir) { + $purgeFunc($dir); + } + } + }; + + $purgeFunc($uploadsDir); + + if ($totalCount > 0) + $this->comment(sprintf('Successfully deleted %s thumbs', $totalCount)); + else + $this->comment('No thumbs found to delete'); + } + +} \ No newline at end of file diff --git a/modules/system/console/PluginRemove.php b/modules/system/console/PluginRemove.php index c51e60ab1..cae780827 100644 --- a/modules/system/console/PluginRemove.php +++ b/modules/system/console/PluginRemove.php @@ -10,6 +10,8 @@ use Symfony\Component\Console\Input\InputArgument; class PluginRemove extends Command { + use \Illuminate\Console\ConfirmableTrait; + /** * The console command name. * @var string @@ -37,26 +39,31 @@ class PluginRemove extends Command */ public function fire() { - if ($this->confirm('Are you sure you want to uninstall this plugin? [yes|no]')) { - $pluginName = $this->argument('name'); - $pluginName = PluginManager::instance()->normalizeIdentifier($pluginName); + $pluginManager = PluginManager::instance(); + $pluginName = $this->argument('name'); + $pluginName = $pluginManager->normalizeIdentifier($pluginName); - /* - * Rollback plugin - */ - $manager = UpdateManager::instance()->resetNotes(); - $manager->rollbackPlugin($pluginName); + if (!$pluginManager->hasPlugin($pluginName)) + return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName)); - foreach ($manager->getNotes() as $note) - $this->output->writeln($note); + if (!$this->confirmToProceed(sprintf('This will DELETE "%s" from the filesystem and database.', $pluginName))) + return; - /* - * Delete from file system - */ - if ($pluginPath = PluginManager::instance()->getPluginPath($pluginName)) { - File::deleteDirectory($pluginPath); - $this->output->writeln(sprintf('Deleted: %s', $pluginName)); - } + /* + * Rollback plugin + */ + $manager = UpdateManager::instance()->resetNotes(); + $manager->rollbackPlugin($pluginName); + + foreach ($manager->getNotes() as $note) + $this->output->writeln($note); + + /* + * Delete from file system + */ + if ($pluginPath = $pluginManager->getPluginPath($pluginName)) { + File::deleteDirectory($pluginPath); + $this->output->writeln(sprintf('Deleted: %s', $pluginName)); } } @@ -77,7 +84,18 @@ class PluginRemove extends Command */ protected function getOptions() { - return []; + return [ + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'], + ]; + } + + /** + * Get the default confirmation callback. + * @return \Closure + */ + protected function getDefaultConfirmCallback() + { + return function() { return true; }; } } \ No newline at end of file