diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 45a6f6d5e..b2f1a65dc 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -308,10 +308,10 @@ class ServiceProvider extends ModuleServiceProvider }); /* - * Override clear cache command + * Add CMS based cache clearing to native command */ - App::singleton('command.cache.clear', function ($app) { - return new \System\Console\CacheClear($app['cache'], $app['files']); + Event::listen('cache:cleared', function() { + \System\Helpers\Cache::clear(); }); /* diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index 7eb9ec526..6f94d6b56 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -10,8 +10,8 @@ use Config; use Carbon\Carbon; use System\Models\Parameters; use System\Models\PluginVersion; -use System\Console\CacheClear; use ApplicationException; +use System\Helpers\Cache as CacheHelper; use October\Rain\Filesystem\Zip; use Exception; @@ -118,7 +118,7 @@ class UpdateManager } Parameters::set('system::update.count', 0); - CacheClear::fireInternal(); + CacheHelper::clear(); /* * Seed modules diff --git a/modules/system/console/CacheClear.php b/modules/system/console/CacheClear.php deleted file mode 100644 index e0c77d830..000000000 --- a/modules/system/console/CacheClear.php +++ /dev/null @@ -1,96 +0,0 @@ -files = $files; - } - - /** - * Execute the console command. - */ - public function fire() - { - $storagePath = $this->laravel->storagePath(); - - /* - * Allow this command to be executed internally - */ - if (!isset($this->output)) { - $this->output = new NullOutput; - } - - /* - * Combiner - */ - foreach ($this->files->directories($storagePath.'/cms/combiner') as $directory) { - $this->files->deleteDirectory($directory); - } - $this->info('Combiner cache cleared!'); - - /* - * Combiner - */ - foreach ($this->files->directories($storagePath.'/cms/cache') as $directory) { - $this->files->deleteDirectory($directory); - } - $this->info('CMS cache cleared!'); - - /* - * Twig - */ - if (!Config::get('cms.twigNoCache')) { - foreach ($this->files->directories($storagePath.'/cms/twig') as $directory) { - $this->files->deleteDirectory($directory); - } - $this->info('Twig cache cleared!'); - } - - /* - * Meta - */ - $this->files->delete($storagePath.'/cms/disabled.json'); - - parent::fire(); - } - - /** - * Clear the cache outside of shell environment - * @return void - */ - public static function fireInternal() - { - try { - $command = App::make('System\Console\CacheClear'); - $command->setLaravel(App::make('app')); - $command->fire(); - } - catch (\Exception $ex) { - // Do nothing - } - } -} diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index 26ee5dd4f..ccb49ba99 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -11,7 +11,6 @@ use BackendMenu; use Backend\Classes\Controller; use System\Models\Parameters; use System\Models\PluginVersion; -use System\Console\CacheClear; use System\Classes\UpdateManager; use System\Classes\PluginManager; use System\Classes\SettingsManager; diff --git a/modules/system/helpers/Cache.php b/modules/system/helpers/Cache.php new file mode 100644 index 000000000..a4692223a --- /dev/null +++ b/modules/system/helpers/Cache.php @@ -0,0 +1,69 @@ +clearCombiner(); + $instance->clearCache(); + + if (!Config::get('cms.twigNoCache')) { + $instance->clearTwig(); + } + + $instance->clearMeta(); + } + + /* + * Combiner + */ + public function clearCombiner() + { + foreach (File::directories(storage_path().'/cms/combiner') as $directory) { + File::deleteDirectory($directory); + } + + } + + /* + * Combiner + */ + public function clearCache() + { + foreach (File::directories(storage_path().'/cms/cache') as $directory) { + File::deleteDirectory($directory); + } + } + + /* + * Twig + */ + public function clearTwig() + { + foreach (File::directories(storage_path().'/cms/twig') as $directory) { + File::deleteDirectory($directory); + } + } + + /* + * Meta + */ + public function clearMeta() + { + File::delete(storage_path().'/cms/disabled.json'); + } +}