mirror of
https://github.com/flarum/framework.git
synced 2025-02-20 22:00:24 +08:00
feat: publish assets on admin dashboard cache clear (#3564)
Co-authored-by: Sami Mazouz <ilyasmazouz@gmail.com>
This commit is contained in:
parent
fe20e2c212
commit
2defb17cc2
@ -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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
];
|
];
|
||||||
|
20
framework/core/src/Foundation/IOException.php
Normal file
20
framework/core/src/Foundation/IOException.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user