mirror of
https://github.com/flarum/core.git
synced 2025-10-18 10:16:09 +02:00
Implement proper update process
If the version in the settings table mismatches the code version, then we return a 503 error for all requests coming through index.php and api.php, while admin.php serves up a form prompting for the database password which will run outstanding migrations.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Flarum\Api;
|
||||
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Http\AbstractServer;
|
||||
use Tobscure\JsonApi\Document;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
|
||||
class Server extends AbstractServer
|
||||
@@ -24,19 +25,27 @@ class Server extends AbstractServer
|
||||
{
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
if ($app->isInstalled()) {
|
||||
$app->register('Flarum\Api\ApiServiceProvider');
|
||||
|
||||
$routes = $app->make('flarum.api.routes');
|
||||
$apiPath = parse_url($app->url('api'), PHP_URL_PATH);
|
||||
$apiPath = parse_url($app->url('api'), PHP_URL_PATH);
|
||||
|
||||
if ($app->isInstalled() && $app->isUpToDate()) {
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\AuthenticateWithCookie'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Api\Middleware\AuthenticateWithHeader'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Api\Middleware\FakeHttpMethods'));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\DispatchRoute', compact('routes')));
|
||||
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
|
||||
$pipe->pipe($apiPath, $app->make('Flarum\Api\Middleware\HandleErrors'));
|
||||
} else {
|
||||
$pipe->pipe($apiPath, function () {
|
||||
$document = new Document;
|
||||
$document->setErrors([
|
||||
[
|
||||
'code' => 503,
|
||||
'title' => 'Service Unavailable'
|
||||
]
|
||||
]);
|
||||
|
||||
return new JsonApiResponse($document, 503);
|
||||
});
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
|
Reference in New Issue
Block a user