ORIENT/modules/system/console/CacheClear.php

97 lines
2.3 KiB
PHP
Raw Normal View History

2014-05-14 13:24:20 +00:00
<?php namespace System\Console;
use App;
use Config;
use Illuminate\Cache\Console\ClearCommand;
use Symfony\Component\Console\Output\NullOutput;
2015-02-07 03:50:03 +00:00
use Illuminate\Cache\CacheManager;
use Illuminate\Filesystem\Filesystem;
2014-05-14 13:24:20 +00:00
class CacheClear extends ClearCommand
{
2015-02-07 03:50:03 +00:00
/**
* 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;
}
2014-05-14 13:24:20 +00:00
/**
* Execute the console command.
*/
public function fire()
{
2015-02-07 03:50:03 +00:00
$storagePath = $this->laravel->storagePath();
2014-05-14 13:24:20 +00:00
/*
* Allow this command to be executed internally
*/
if (!isset($this->output)) {
$this->output = new NullOutput;
}
/*
* Combiner
*/
2015-02-07 03:50:03 +00:00
foreach ($this->files->directories($storagePath.'/cms/combiner') as $directory) {
2014-05-14 13:24:20 +00:00
$this->files->deleteDirectory($directory);
}
$this->info('Combiner cache cleared!');
2015-02-07 03:50:03 +00:00
/*
* Combiner
*/
foreach ($this->files->directories($storagePath.'/cms/cache') as $directory) {
$this->files->deleteDirectory($directory);
}
$this->info('CMS cache cleared!');
2014-05-14 13:24:20 +00:00
/*
* Twig
*/
if (!Config::get('cms.twigNoCache')) {
2015-02-07 03:50:03 +00:00
foreach ($this->files->directories($storagePath.'/cms/twig') as $directory) {
2014-05-14 13:24:20 +00:00
$this->files->deleteDirectory($directory);
}
$this->info('Twig cache cleared!');
}
/*
* Meta
*/
2015-02-07 03:50:03 +00:00
$this->files->delete($storagePath.'/cms/disabled.json');
2014-05-14 13:24:20 +00:00
parent::fire();
}
/**
* Clear the cache outside of shell environment
* @return void
*/
public static function fireInternal()
{
try {
$command = App::make('System\Console\CacheClear');
2014-06-12 09:02:30 +00:00
$command->setLaravel(App::make('app'));
$command->fire();
}
catch (\Exception $ex) {
// Do nothing
}
2014-05-14 13:24:20 +00:00
}
2014-10-18 09:58:50 +00:00
}