The command to clear the CMS cache has changed

This commit is contained in:
Samuel Georges 2015-02-11 20:39:25 +11:00
parent 0a6e14f4d2
commit ce14c0c926
5 changed files with 74 additions and 102 deletions

View File

@ -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();
});
/*

View File

@ -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

View File

@ -1,96 +0,0 @@
<?php namespace System\Console;
use App;
use Config;
use Illuminate\Cache\Console\ClearCommand;
use Symfony\Component\Console\Output\NullOutput;
use Illuminate\Cache\CacheManager;
use Illuminate\Filesystem\Filesystem;
class CacheClear extends ClearCommand
{
/**
* The file system instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* Create a new cache clear command instance.
*
* @param \Illuminate\Cache\CacheManager $cache
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(CacheManager $cache, Filesystem $files)
{
parent::__construct($cache);
$this->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
}
}
}

View File

@ -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;

View File

@ -0,0 +1,69 @@
<?php namespace System\Helpers;
use App;
use File;
use Config;
use Illuminate\Cache\Console\ClearCommand;
use Symfony\Component\Console\Output\NullOutput;
use Illuminate\Cache\CacheManager;
use Illuminate\Filesystem\Filesystem;
class Cache
{
use \October\Rain\Support\Traits\Singleton;
/**
* Execute the console command.
*/
public static function clear()
{
$instance = self::instance();
$instance->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');
}
}