1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 07:24:27 +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:
Toby Zerner
2015-10-19 15:09:54 +10:30
parent ddfedcb4dd
commit 1242fa79af
14 changed files with 290 additions and 55 deletions

View File

@@ -15,7 +15,6 @@ use Flarum\Foundation\Application;
use Flarum\Http\AbstractServer;
use Zend\Stratigility\MiddlewarePipe;
use Flarum\Http\Middleware\HandleErrors;
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
class Server extends AbstractServer
{
@@ -27,18 +26,21 @@ class Server extends AbstractServer
$pipe = new MiddlewarePipe;
if ($app->isInstalled()) {
$app->register('Flarum\Admin\AdminServiceProvider');
$adminPath = parse_url($app->url('admin'), PHP_URL_PATH);
$routes = $app->make('flarum.admin.routes');
$errorDir = __DIR__ . '/../../error';
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\AuthenticateWithCookie'));
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
$pipe->pipe($adminPath, $app->make('Flarum\Admin\Middleware\RequireAdministrateAbility'));
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\DispatchRoute', compact('routes')));
$pipe->pipe(new HandleErrors(__DIR__.'/../../error', $app->inDebugMode()));
if ($app->isUpToDate()) {
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\AuthenticateWithCookie'));
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
$pipe->pipe($adminPath, $app->make('Flarum\Admin\Middleware\RequireAdministrateAbility'));
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')]));
$pipe->pipe($adminPath, new HandleErrors($errorDir, $app->inDebugMode()));
} else {
$app->register('Flarum\Update\UpdateServiceProvider');
$pipe->pipe($adminPath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')]));
$pipe->pipe($adminPath, new HandleErrors($errorDir, true));
}
}
return $pipe;