First basic version of cache:clear command

Refs #837.
This commit is contained in:
Franz Liedke 2016-04-02 21:22:53 +09:00
parent 37d7f315d3
commit 8e35afe204
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Console\Command;
class CacheClearCommand extends AbstractCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cache:clear')
->setDescription('Remove all temporary and generated files');
}
/**
* {@inheritdoc}
*/
protected function fire()
{
$this->info('Clearing the cache...');
$this->removeFilesMatching('assets', '*.js');
$this->removeFilesMatching('assets', '*.css');
}
protected function removeFilesMatching($path, $pattern)
{
$this->info("Removing $pattern files in $path...");
$path = $this->getPath($path);
array_map('unlink', glob("$path/$pattern"));
}
protected function getPath($path)
{
return base_path($path);
}
}

View File

@ -11,6 +11,7 @@
namespace Flarum\Console;
use Flarum\Console\Command\CacheClearCommand;
use Flarum\Console\Command\GenerateExtensionCommand;
use Flarum\Console\Command\GenerateMigrationCommand;
use Flarum\Debug\Console\InfoCommand;
@ -42,6 +43,7 @@ class Server extends AbstractServer
InstallCommand::class,
MigrateCommand::class,
InfoCommand::class,
CacheClearCommand::class,
GenerateExtensionCommand::class,
GenerateMigrationCommand::class,
];