feat: publish assets on admin dashboard cache clear (#3564)

Co-authored-by: Sami Mazouz <ilyasmazouz@gmail.com>
This commit is contained in:
David Wheatley 2022-07-26 13:48:04 +01:00 committed by GitHub
parent fe20e2c212
commit 2defb17cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 3 deletions

View File

@ -56,6 +56,14 @@ export default class StatusWidget extends DashboardWidget {
method: 'DELETE', method: 'DELETE',
url: app.forum.attribute('apiUrl') + '/cache', url: app.forum.attribute('apiUrl') + '/cache',
}) })
.then(() => window.location.reload()); .then(() => window.location.reload())
.catch((e) => {
if (e.status === 409) {
app.alerts.clear();
app.alerts.show({ type: 'error' }, app.translator.trans('core.admin.dashboard.io_error_message'));
}
app.modal.close();
});
} }
} }

View File

@ -53,6 +53,7 @@ core:
dashboard: dashboard:
clear_cache_button: Clear Cache clear_cache_button: Clear Cache
description: Your forum at a glance. description: Your forum at a glance.
io_error_message: "Could not write to filesystem. Check your filesystem permissions an try again. Or try running from the command line."
title: Dashboard title: Dashboard
tools_button: Tools tools_button: Tools

View File

@ -9,7 +9,9 @@
namespace Flarum\Api\Controller; namespace Flarum\Api\Controller;
use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\Foundation\Console\CacheClearCommand; use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\IOException;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Laminas\Diactoros\Response\EmptyResponse; use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -23,26 +25,46 @@ class ClearCacheController extends AbstractDeleteController
*/ */
protected $command; protected $command;
/**
* @var AssetsPublishCommand
*/
protected $assetsPublishCommand;
/** /**
* @param CacheClearCommand $command * @param CacheClearCommand $command
*/ */
public function __construct(CacheClearCommand $command) public function __construct(CacheClearCommand $command, AssetsPublishCommand $assetsPublishCommand)
{ {
$this->command = $command; $this->command = $command;
$this->assetsPublishCommand = $assetsPublishCommand;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
* @throws IOException|\Flarum\User\Exception\PermissionDeniedException
*/ */
protected function delete(ServerRequestInterface $request) protected function delete(ServerRequestInterface $request)
{ {
RequestUtil::getActor($request)->assertAdmin(); RequestUtil::getActor($request)->assertAdmin();
$this->command->run( $exitCode = $this->command->run(
new ArrayInput([]), new ArrayInput([]),
new NullOutput() new NullOutput()
); );
if ($exitCode !== 0) {
throw new IOException();
}
$exitCode = $this->assetsPublishCommand->run(
new ArrayInput([]),
new NullOutput()
);
if ($exitCode !== 0) {
throw new IOException();
}
return new EmptyResponse(204); return new EmptyResponse(204);
} }
} }

View File

@ -39,6 +39,9 @@ class ErrorServiceProvider extends AbstractServiceProvider
// 405 Method Not Allowed // 405 Method Not Allowed
'method_not_allowed' => 405, 'method_not_allowed' => 405,
// 409 Conflict
'io_error' => 409,
// 429 Too Many Requests // 429 Too Many Requests
'too_many_requests' => 429, 'too_many_requests' => 429,
]; ];

View File

@ -0,0 +1,20 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation;
use Exception;
class IOException extends Exception implements KnownError
{
public function getType(): string
{
return 'io_error';
}
}