Completed install wizard

This commit is contained in:
Sergio Brighenti 2018-11-11 20:20:38 +01:00
parent 72523843b6
commit 4ee5c41f37
5 changed files with 27 additions and 10 deletions

View file

@ -64,6 +64,7 @@ module.exports = function (grunt) {
'app/**/*',
'bin/**/*',
'bootstrap/**/*',
'install/**/*',
'logs/**/',
'resources/cache',
'resources/sessions',

View file

@ -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;
}
}

View file

@ -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');
}

View file

@ -1,7 +1,6 @@
<?php
// Auth routes
$app->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');

View file

@ -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', '<?php' . PHP_EOL . 'return ' . var_export($config, true) . ';');
DB::setDsn($config['db']['connection'] . ':' . __DIR__ . '../' . $config['db']['dsn'], $config['db']['username'], $config['db']['password']);
DB::setDsn($config['db']['connection'] . ':' . __DIR__ . '/../' . $config['db']['dsn'], $config['db']['username'], $config['db']['password']);
$firstMigrate = false;
if (!file_exists(__DIR__ . '../' . $config['db']['dsn']) && DB::driver() === 'sqlite') {
touch(__DIR__ . '../' . $config['db']['dsn']);
if (!file_exists(__DIR__ . '/../' . $config['db']['dsn']) && DB::driver() === 'sqlite') {
touch(__DIR__ . '/../' . $config['db']['dsn']);
$firstMigrate = true;
}
@ -80,14 +81,11 @@ $app->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);