From 4ee5c41f37b3b7e8a0321ff6718585a042c003ec Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Sun, 11 Nov 2018 20:20:38 +0100 Subject: [PATCH] Completed install wizard --- Gruntfile.js | 1 + app/Controllers/Controller.php | 13 +++++++++++++ app/Controllers/DashboardController.php | 5 +++++ app/routes.php | 2 +- install/index.php | 16 +++++++--------- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 871450c..1cca961 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -64,6 +64,7 @@ module.exports = function (grunt) { 'app/**/*', 'bin/**/*', 'bootstrap/**/*', + 'install/**/*', 'logs/**/', 'resources/cache', 'resources/sessions', diff --git a/app/Controllers/Controller.php b/app/Controllers/Controller.php index 45e13ae..1df56e0 100644 --- a/app/Controllers/Controller.php +++ b/app/Controllers/Controller.php @@ -55,4 +55,17 @@ abstract class Controller { return new Filesystem(new Local($this->settings['storage_dir'])); } + + /** + * @param $path + */ + public function removeDirectory($path) + { + $files = glob($path . '/*'); + foreach ($files as $file) { + is_dir($file) ? $this->removeDirectory($file) : unlink($file); + } + rmdir($path); + return; + } } \ No newline at end of file diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index d76aed3..f6f7410 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -21,6 +21,11 @@ class DashboardController extends Controller */ public function redirects(Request $request, Response $response): Response { + + if ($request->getParam('afterInstall') !== null && is_dir('install')) { + $this->removeDirectory('install'); + } + return $response->withRedirect('/home'); } diff --git a/app/routes.php b/app/routes.php index 3b46829..c640c66 100644 --- a/app/routes.php +++ b/app/routes.php @@ -1,7 +1,6 @@ group('', function () { - $this->get('/', \App\Controllers\DashboardController::class . ':redirects'); $this->get('/home[/page/{page}]', \App\Controllers\DashboardController::class . ':home'); $this->get('/system', \App\Controllers\DashboardController::class . ':system')->add(\App\Middleware\AdminMiddleware::class); @@ -26,6 +25,7 @@ $app->group('', function () { })->add(\App\Middleware\AuthMiddleware::class); +$app->get('/', \App\Controllers\DashboardController::class . ':redirects'); $app->get('/login', \App\Controllers\LoginController::class . ':show'); $app->post('/login', \App\Controllers\LoginController::class . ':login'); $app->map(['GET', 'POST'], '/logout', \App\Controllers\LoginController::class . ':logout'); diff --git a/install/index.php b/install/index.php index 5b8737d..b11b397 100644 --- a/install/index.php +++ b/install/index.php @@ -14,7 +14,7 @@ $config = [ 'app_name' => 'XBackBone', 'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'], 'storage_dir' => 'storage', - 'displayErrorDetails' => false, + 'displayErrorDetails' => true, 'db' => [ 'connection' => 'sqlite', 'dsn' => 'resources/database/xbackbone.db', @@ -57,6 +57,7 @@ $app->get('/', function (Request $request, Response $response) { $app->post('/', function (Request $request, Response $response) use (&$config) { $config['base_url'] = $request->getParam('base_url'); $config['storage_dir'] = $request->getParam('storage_dir'); + $config['displayErrorDetails'] = false; $config['db']['connection'] = $request->getParam('connection'); $config['db']['dsn'] = $request->getParam('dsn'); $config['db']['username'] = null; @@ -66,11 +67,11 @@ $app->post('/', function (Request $request, Response $response) use (&$config) { file_put_contents(__DIR__ . '/../config.php', 'post('/', function (Request $request, Response $response) use (&$config) { $firstMigrate = true; } - echo 'Connected.' . PHP_EOL; - if ($firstMigrate) { - echo 'Creating migrations table...' . PHP_EOL; - DB::raw()->exec(file_get_contents(__DIR__ . '../resources/schemas/migrations.sql')); + DB::raw()->exec(file_get_contents(__DIR__ . '/../resources/schemas/migrations.sql')); } - $files = glob(__DIR__ . '../resources/schemas/' . DB::driver() . '/*.sql'); + $files = glob(__DIR__ . '/../resources/schemas/' . DB::driver() . '/*.sql'); $names = array_map(function ($path) { return basename($path);