ソースを参照

Completed maintenance impl.
Small fixes

Sergio Brighenti 6 年 前
コミット
3ba38eff2c

+ 1 - 3
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');

+ 6 - 3
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', '<?php' . PHP_EOL . 'return ' . var_export($config, true) . ';');
+
 		$currentFiles = array_merge(
 			glob_recursive(BASE_DIR . 'app/*'),
 			glob_recursive(BASE_DIR . 'bin/*'),
@@ -107,12 +111,11 @@ class UpgradeController extends Controller
 				$jsonResponse['message'] = lang('already_latest_version');
 				$jsonResponse['upgrade'] = false;
 			}
-			return $response->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.');

+ 6 - 2
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';
+require BASE_DIR . 'app/routes.php';

+ 14 - 0
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', '<?php' . PHP_EOL . 'return ' . var_export($config, true) . ';');
+		if ($ret === false) {
+			$this->session->alert('The config folder is not writable (' . __DIR__ . '/../config.php' . ')', 'danger');
+			return redirect($response, './');
+		}
+	}
+
 	return $response->withRedirect('../?afterInstall=true');
 });
 

+ 5 - 7
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);
             }
         });
     }