mirror of
https://github.com/getgrav/grav.git
synced 2026-07-06 14:39:25 +02:00
Added a deleteAll() method and also renamed CLI command
This commit is contained in:
2
bin/grav
2
bin/grav
@@ -39,7 +39,7 @@ $app->addCommands(array(
|
||||
new \Grav\Console\Cli\ComposerCommand(),
|
||||
new \Grav\Console\Cli\SandboxCommand(),
|
||||
new \Grav\Console\Cli\CleanCommand(),
|
||||
new \Grav\Console\Cli\ClearCacheCommand(),
|
||||
new \Grav\Console\Cli\CacheCommand(),
|
||||
new \Grav\Console\Cli\BackupCommand(),
|
||||
new \Grav\Console\Cli\NewProjectCommand(),
|
||||
new \Grav\Console\Cli\SchedulerCommand(),
|
||||
|
||||
@@ -331,6 +331,19 @@ class Cache extends Getters
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteAll()
|
||||
{
|
||||
if ($this->enabled) {
|
||||
return $this->driver->deleteAll();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean state of whether or not the item exists in the cache based on id key
|
||||
*
|
||||
@@ -400,6 +413,12 @@ class Cache extends Getters
|
||||
|
||||
}
|
||||
|
||||
// Delete entries in the doctrine cache if required
|
||||
if (in_array($remove, ['all', 'standard'])) {
|
||||
$cache = Grav::instance()['cache'];
|
||||
$cache->driver->deleteAll();
|
||||
}
|
||||
|
||||
// Clearing cache event to add paths to clear
|
||||
Grav::instance()->fireEvent('onBeforeCacheClear', new Event(['remove' => $remove, 'paths' => &$remove_paths]));
|
||||
|
||||
@@ -530,7 +549,8 @@ class Cache extends Getters
|
||||
{
|
||||
$cache = Grav::instance()['cache'];
|
||||
$deleted_folders = $cache->purgeOldCache();
|
||||
echo 'Deleted ' . $deleted_folders . ' folders...';
|
||||
$msg = 'Cleared ' . $deleted_folders . ' old cache folders...';
|
||||
return $msg;
|
||||
}
|
||||
|
||||
public function onSchedulerInitialized(Event $event)
|
||||
|
||||
@@ -13,7 +13,7 @@ use Grav\Common\Grav;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ClearCacheCommand extends ConsoleCommand
|
||||
class CacheCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
*
|
||||
@@ -21,8 +21,8 @@ class ClearCacheCommand extends ConsoleCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('clear-cache')
|
||||
->setAliases(['clearcache'])
|
||||
->setName('cache')
|
||||
->setAliases(['clearcache', 'cache-clear'])
|
||||
->setDescription('Clears Grav cache')
|
||||
->addOption('purge', null, InputOption::VALUE_NONE, 'If set purge old caches')
|
||||
->addOption('all', null, InputOption::VALUE_NONE, 'If set will remove all including compiled, twig, doctrine caches')
|
||||
@@ -55,8 +55,8 @@ class ClearCacheCommand extends ConsoleCommand
|
||||
$this->output->writeln('<magenta>Purging old cache</magenta>');
|
||||
$this->output->writeln('');
|
||||
|
||||
$cache = Grav::instance()['cache'];
|
||||
$cache->purgeOldCache();
|
||||
$msg = Cache::purgeJob();
|
||||
$this->output->writeln($msg);
|
||||
} else {
|
||||
$this->output->writeln('<magenta>Clearing cache</magenta>');
|
||||
$this->output->writeln('');
|
||||
@@ -11,7 +11,7 @@ namespace Grav\Console;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Composer;
|
||||
use Grav\Common\GravTrait;
|
||||
use Grav\Console\Cli\ClearCacheCommand;
|
||||
use Grav\Console\Cli\CacheCommand;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
@@ -107,7 +107,7 @@ trait ConsoleTrait
|
||||
$all = ['--all' => true];
|
||||
}
|
||||
|
||||
$command = new ClearCacheCommand();
|
||||
$command = new CacheCommand();
|
||||
$input = new ArrayInput($all);
|
||||
return $command->run($input, $this->output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user