1
0
mirror of https://github.com/flarum/core.git synced 2025-10-19 02:36:08 +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

@@ -13,6 +13,7 @@ namespace Flarum\Forum;
use Flarum\Foundation\Application;
use Flarum\Http\AbstractServer;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Stratigility\MiddlewarePipe;
use Flarum\Http\Middleware\HandleErrors;
@@ -25,26 +26,25 @@ class Server extends AbstractServer
{
$pipe = new MiddlewarePipe;
$installed = $app->isInstalled();
$basePath = parse_url($app->url(), PHP_URL_PATH);
$errorDir = __DIR__.'/../../error';
if ($installed) {
$app->register('Flarum\Forum\ForumServiceProvider');
$routes = $app->make('flarum.forum.routes');
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\AuthenticateWithCookie'));
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
} else {
if (! $app->isInstalled()) {
$app->register('Flarum\Install\InstallServiceProvider');
$routes = $app->make('flarum.install.routes');
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
$pipe->pipe($basePath, new HandleErrors($errorDir, true));
} elseif ($app->isUpToDate()) {
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\AuthenticateWithCookie'));
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
$pipe->pipe($basePath, new HandleErrors($errorDir, $app->inDebugMode()));
} else {
$pipe->pipe($basePath, function () use ($errorDir) {
return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503));
});
}
$pipe->pipe($basePath, $app->make('Flarum\Http\Middleware\DispatchRoute', compact('routes')));
$pipe->pipe(new HandleErrors(__DIR__.'/../../error', $app->inDebugMode() || ! $installed));
return $pipe;
}
}