From 8fbaded18d3dc42bff3dd68649fc929ac5b495ef Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Sun, 12 Apr 2020 18:46:25 +0200 Subject: [PATCH] Added check of cases like #191 --- composer.json | 2 +- install/index.php | 28 +++++++++++++++++----------- install/templates/install.twig | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 5ff92ba..e0399d8 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "sergix44/xbackbone", - "version": "3.1.1", + "version": "3.1.2", "description": "A lightweight ShareX PHP backend", "type": "project", "require": { diff --git a/install/index.php b/install/index.php index e1f11fa..6b324ac 100644 --- a/install/index.php +++ b/install/index.php @@ -102,11 +102,10 @@ $app->get('/', function (Response $response, View $view, Session $session) { })->setName('install'); $app->post('/', function (Request $request, Response $response, Filesystem $storage, Session $session, DB $db) use (&$config) { - // Check if there is a previous installation, if not, setup the config file - $installed = true; - // disable debug in production unset($config['debug']); + + // Check if there is a previous installation, if not, setup the config file if (!file_exists(__DIR__.'/../config.php')) { $installed = false; @@ -154,6 +153,21 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor $config['storage']['path'] = param($request, 'storage_path'); break; } + } else { + $installed = true; + if (isset($config['storage_dir'])) { // if from older installations with no support of other than local driver + $config['storage']['driver'] = 'local'; + $config['storage']['path'] = $config['storage_dir']; + unset($config['storage_dir']); + } + + if ($config['storage']['driver'] === 'local' && !is_dir($config['storage']['path'])) { // if installed with local driver, and the storage dir don't exists + $realPath = realpath(BASE_DIR.$config['storage']['path']); + if (is_dir($realPath) && is_writable($realPath)) { // and was a path relative to the upper folder + $config['storage']['path'] = $realPath; // update the config + $storage->getAdapter()->setPathPrefix($realPath); // update the prefix + } + } } // check if the storage is valid @@ -176,14 +190,6 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor return redirect($response, urlFor('/install')); } - // if from older installations with no support of other than local driver - // update the config - if ($installed && isset($config['storage_dir'])) { - $config['storage']['driver'] = 'local'; - $config['storage']['path'] = $config['storage_dir']; - unset($config['storage_dir']); - } - // Build the dns string and run the migrations try { $migrator = new Migrator($db, __DIR__.'/../resources/schemas'); diff --git a/install/templates/install.twig b/install/templates/install.twig index baf7a7f..0db4754 100644 --- a/install/templates/install.twig +++ b/install/templates/install.twig @@ -194,7 +194,7 @@