diff --git a/bin/grav b/bin/grav index 4b2483c6a..12269a781 100755 --- a/bin/grav +++ b/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(), diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index f458c9ca6..6ee599e5f 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -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) diff --git a/system/src/Grav/Console/Cli/ClearCacheCommand.php b/system/src/Grav/Console/Cli/CacheCommand.php similarity index 92% rename from system/src/Grav/Console/Cli/ClearCacheCommand.php rename to system/src/Grav/Console/Cli/CacheCommand.php index 294142d32..8f80f51c0 100644 --- a/system/src/Grav/Console/Cli/ClearCacheCommand.php +++ b/system/src/Grav/Console/Cli/CacheCommand.php @@ -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('Purging old cache'); $this->output->writeln(''); - $cache = Grav::instance()['cache']; - $cache->purgeOldCache(); + $msg = Cache::purgeJob(); + $this->output->writeln($msg); } else { $this->output->writeln('Clearing cache'); $this->output->writeln(''); diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 6c3a3c997..294ed9302 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -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); }