diff --git a/framework/core/src/Console/Command/CacheClearCommand.php b/framework/core/src/Console/Command/CacheClearCommand.php new file mode 100644 index 000000000..7ce3feb71 --- /dev/null +++ b/framework/core/src/Console/Command/CacheClearCommand.php @@ -0,0 +1,48 @@ + + * + * 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); + } +} diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index 5cff344b2..9892a8122 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -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, ];