Added a new console command `october:util` for performing utility and maintenance tasks.

This commit is contained in:
Sam Georges 2014-07-25 17:51:36 +10:00
parent 3ac3a7318f
commit 19a3fe2b43
5 changed files with 182 additions and 25 deletions

View File

@ -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) * **Build 125** (2014-07-24)
- Theme support added. - Added support for Themes.
- Added new Theme picker to the backend via Settings > Front-end theme - 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')`. - New shorthand method for `$this->getClassExtension('Backend.Behaviors.FormController')` becomes `$this->asExtension('FormController')`.
- Buttons inside a popup support new `data-popup-load-indicator` attribute. - Buttons inside a popup support new `data-popup-load-indicator` attribute.

View File

@ -248,6 +248,7 @@ class ServiceProvider extends ModuleServiceProvider
$this->registerConsoleCommand('october.up', 'System\Console\OctoberUp'); $this->registerConsoleCommand('october.up', 'System\Console\OctoberUp');
$this->registerConsoleCommand('october.down', 'System\Console\OctoberDown'); $this->registerConsoleCommand('october.down', 'System\Console\OctoberDown');
$this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate'); $this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate');
$this->registerConsoleCommand('october.util', 'System\Console\OctoberUtil');
$this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall'); $this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall');
$this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove'); $this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove');
$this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh'); $this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh');

View File

@ -8,6 +8,8 @@ use Symfony\Component\Console\Input\InputArgument;
class OctoberDown extends Command class OctoberDown extends Command
{ {
use \Illuminate\Console\ConfirmableTrait;
/** /**
* The console command name. * The console command name.
*/ */
@ -31,13 +33,13 @@ class OctoberDown extends Command
*/ */
public function fire() 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) foreach ($manager->getNotes() as $note)
$this->output->writeln($note); $this->output->writeln($note);
}
} }
/** /**
@ -53,7 +55,18 @@ class OctoberDown extends Command
*/ */
protected function getOptions() 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; };
} }
} }

View File

@ -0,0 +1,119 @@
<?php namespace System\Console;
use File;
use Config;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
* Utility command
*
* Supported commands:
*
* - purge thumbs: Deletes all thumbnail files in the uploads directory.
*/
class OctoberUtil extends Command
{
use \Illuminate\Console\ConfirmableTrait;
/**
* The console command name.
*/
protected $name = 'october:util';
/**
* The console command description.
*/
protected $description = 'Utility commands for October';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function fire()
{
$command = implode(' ', (array) $this->argument('name'));
$method = 'util'.studly_case($command);
if (!method_exists($this, $method)) {
$this->error(sprintf('<error>Utility command "%s" does not exist!</error>', $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');
}
}

View File

@ -10,6 +10,8 @@ use Symfony\Component\Console\Input\InputArgument;
class PluginRemove extends Command class PluginRemove extends Command
{ {
use \Illuminate\Console\ConfirmableTrait;
/** /**
* The console command name. * The console command name.
* @var string * @var string
@ -37,26 +39,31 @@ class PluginRemove extends Command
*/ */
public function fire() public function fire()
{ {
if ($this->confirm('Are you sure you want to uninstall this plugin? [yes|no]')) { $pluginManager = PluginManager::instance();
$pluginName = $this->argument('name'); $pluginName = $this->argument('name');
$pluginName = PluginManager::instance()->normalizeIdentifier($pluginName); $pluginName = $pluginManager->normalizeIdentifier($pluginName);
/* if (!$pluginManager->hasPlugin($pluginName))
* Rollback plugin return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName));
*/
$manager = UpdateManager::instance()->resetNotes();
$manager->rollbackPlugin($pluginName);
foreach ($manager->getNotes() as $note) if (!$this->confirmToProceed(sprintf('This will DELETE "%s" from the filesystem and database.', $pluginName)))
$this->output->writeln($note); return;
/* /*
* Delete from file system * Rollback plugin
*/ */
if ($pluginPath = PluginManager::instance()->getPluginPath($pluginName)) { $manager = UpdateManager::instance()->resetNotes();
File::deleteDirectory($pluginPath); $manager->rollbackPlugin($pluginName);
$this->output->writeln(sprintf('<info>Deleted: %s</info>', $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('<info>Deleted: %s</info>', $pluginName));
} }
} }
@ -77,7 +84,18 @@ class PluginRemove extends Command
*/ */
protected function getOptions() 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; };
} }
} }