diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 3a2193c..55cdb48 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -16,10 +16,8 @@ class DashboardController extends Controller */ public function redirects(Request $request, Response $response): Response { - - if ($request->getParam('afterInstall') !== null && is_dir('install')) { + if ($request->getParam('afterInstall') !== null && !is_dir(BASE_DIR . 'install')) { $this->session->alert(lang('installed'), 'success'); - removeDirectory('install'); } return redirect($response, 'home'); diff --git a/app/Controllers/UpgradeController.php b/app/Controllers/UpgradeController.php index 5d96c0c..b678f3e 100644 --- a/app/Controllers/UpgradeController.php +++ b/app/Controllers/UpgradeController.php @@ -47,6 +47,10 @@ class UpgradeController extends Controller return redirect($response, 'system'); } + $config = $this->config; + $config['maintenance'] = true; + file_put_contents(BASE_DIR . 'config.php', 'withJson($jsonResponse, 200); } catch (\RuntimeException $e) { $jsonResponse['status'] = 'ERROR'; $jsonResponse['message'] = $e->getMessage(); - return $response->withJson($jsonResponse, 503); } + return $response->withJson($jsonResponse); } protected function getApiJson() @@ -127,7 +130,7 @@ class UpgradeController extends Controller ], ]; - $data = file_get_contents(self::GITHUB_SOURCE_API, false, stream_context_create($opts)); + $data = @file_get_contents(self::GITHUB_SOURCE_API, false, stream_context_create($opts)); if ($data === false) { throw new \RuntimeException('Cannot contact the Github API. Try again.'); diff --git a/bootstrap/app.php b/bootstrap/app.php index e2f577b..c1ab7fb 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -13,7 +13,7 @@ if (!file_exists('config.php') && is_dir('install/')) { header('Location: ./install/'); exit(); } else if (!file_exists('config.php') && !is_dir('install/')) { - die('Cannot find the config file.'); + exit('Cannot find the config file.'); } // Load the config @@ -37,6 +37,10 @@ if (!$config['displayErrorDetails']) { $container = new Container(['settings' => $config]); +$container['config'] = function ($container) use ($config) { + return $config; +}; + $container['logger'] = function ($container) { $logger = new Logger('app'); @@ -133,4 +137,4 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, }); // Load the application routes -require 'app/routes.php'; \ No newline at end of file +require BASE_DIR . 'app/routes.php'; \ No newline at end of file diff --git a/install/index.php b/install/index.php index b257503..a8f7662 100644 --- a/install/index.php +++ b/install/index.php @@ -163,6 +163,8 @@ $app->post('/', function (Request $request, Response $response) use (&$config) { $this->session->alert('The config folder is not writable (' . __DIR__ . '/../config.php' . ')', 'danger'); return redirect($response, './'); } + } else { + $config = require __DIR__ . '/../config.php'; } $dsn = $config['db']['connection'] === 'sqlite' ? __DIR__ . '/../' . $config['db']['dsn'] : $config['db']['dsn']; @@ -183,6 +185,18 @@ $app->post('/', function (Request $request, Response $response) use (&$config) { cleanDirectory(__DIR__ . '/../resources/cache'); cleanDirectory(__DIR__ . '/../resources/sessions'); + removeDirectory(__DIR__ . '/../install'); + + if ($installed) { + $config['maintenance'] = false; + + $ret = file_put_contents(__DIR__ . '/../config.php', 'session->alert('The config folder is not writable (' . __DIR__ . '/../config.php' . ')', 'danger'); + return redirect($response, './'); + } + } + return $response->withRedirect('../?afterInstall=true'); }); diff --git a/src/js/app.js b/src/js/app.js index 12f738b..600c5e3 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -95,13 +95,11 @@ var app = { $('#checkForUpdatesMessage').empty().text('...'); $('#doUpgradeButton').prop('disabled', true); $.get(window.AppConfig.base_url + '/system/checkForUpdates', function (data) { - if (data.status === 'OK') { - $('#checkForUpdatesMessage').empty().text(data.message); - if (data.upgrade) { - $('#doUpgradeButton').prop('disabled', false); - } else { - $('#doUpgradeButton').prop('disabled', true); - } + $('#checkForUpdatesMessage').empty().text(data.message); + if (data.upgrade) { + $('#doUpgradeButton').prop('disabled', false); + } else { + $('#doUpgradeButton').prop('disabled', true); } }); }