1
0
mirror of https://github.com/flarum/core.git synced 2025-07-16 22:31:18 +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

@@ -0,0 +1,68 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Update\Controller;
use Exception;
use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Update\Console\MigrateCommand;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\StreamOutput;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\HtmlResponse;
class UpdateController implements ControllerInterface
{
protected $command;
/**
* @var Application
*/
protected $app;
/**
* @param MigrateCommand $command
* @param Application $app
*/
public function __construct(MigrateCommand $command, Application $app)
{
$this->command = $command;
$this->app = $app;
}
/**
* @param Request $request
* @param array $routeParams
* @return \Psr\Http\Message\ResponseInterface
*/
public function handle(Request $request, array $routeParams = [])
{
$input = $request->getParsedBody();
if (array_get($input, 'databasePassword') !== $this->app->config('database.password')) {
return new HtmlResponse('Incorrect database password.', 500);
}
$body = fopen('php://temp', 'wb+');
$input = new StringInput('');
$output = new StreamOutput($body);
try {
$this->command->run($input, $output);
} catch (Exception $e) {
return new HtmlResponse($e->getMessage(), 500);
}
return new Response($body, 200);
}
}