Completed install wizard
This commit is contained in:
parent
72523843b6
commit
4ee5c41f37
5 changed files with 27 additions and 10 deletions
|
@ -64,6 +64,7 @@ module.exports = function (grunt) {
|
||||||
'app/**/*',
|
'app/**/*',
|
||||||
'bin/**/*',
|
'bin/**/*',
|
||||||
'bootstrap/**/*',
|
'bootstrap/**/*',
|
||||||
|
'install/**/*',
|
||||||
'logs/**/',
|
'logs/**/',
|
||||||
'resources/cache',
|
'resources/cache',
|
||||||
'resources/sessions',
|
'resources/sessions',
|
||||||
|
|
|
@ -55,4 +55,17 @@ abstract class Controller
|
||||||
{
|
{
|
||||||
return new Filesystem(new Local($this->settings['storage_dir']));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,11 @@ class DashboardController extends Controller
|
||||||
*/
|
*/
|
||||||
public function redirects(Request $request, Response $response): Response
|
public function redirects(Request $request, Response $response): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($request->getParam('afterInstall') !== null && is_dir('install')) {
|
||||||
|
$this->removeDirectory('install');
|
||||||
|
}
|
||||||
|
|
||||||
return $response->withRedirect('/home');
|
return $response->withRedirect('/home');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
// Auth routes
|
// Auth routes
|
||||||
$app->group('', function () {
|
$app->group('', function () {
|
||||||
$this->get('/', \App\Controllers\DashboardController::class . ':redirects');
|
|
||||||
$this->get('/home[/page/{page}]', \App\Controllers\DashboardController::class . ':home');
|
$this->get('/home[/page/{page}]', \App\Controllers\DashboardController::class . ':home');
|
||||||
$this->get('/system', \App\Controllers\DashboardController::class . ':system')->add(\App\Middleware\AdminMiddleware::class);
|
$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);
|
})->add(\App\Middleware\AuthMiddleware::class);
|
||||||
|
|
||||||
|
$app->get('/', \App\Controllers\DashboardController::class . ':redirects');
|
||||||
$app->get('/login', \App\Controllers\LoginController::class . ':show');
|
$app->get('/login', \App\Controllers\LoginController::class . ':show');
|
||||||
$app->post('/login', \App\Controllers\LoginController::class . ':login');
|
$app->post('/login', \App\Controllers\LoginController::class . ':login');
|
||||||
$app->map(['GET', 'POST'], '/logout', \App\Controllers\LoginController::class . ':logout');
|
$app->map(['GET', 'POST'], '/logout', \App\Controllers\LoginController::class . ':logout');
|
||||||
|
|
|
@ -14,7 +14,7 @@ $config = [
|
||||||
'app_name' => 'XBackBone',
|
'app_name' => 'XBackBone',
|
||||||
'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'],
|
'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'],
|
||||||
'storage_dir' => 'storage',
|
'storage_dir' => 'storage',
|
||||||
'displayErrorDetails' => false,
|
'displayErrorDetails' => true,
|
||||||
'db' => [
|
'db' => [
|
||||||
'connection' => 'sqlite',
|
'connection' => 'sqlite',
|
||||||
'dsn' => 'resources/database/xbackbone.db',
|
'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) {
|
$app->post('/', function (Request $request, Response $response) use (&$config) {
|
||||||
$config['base_url'] = $request->getParam('base_url');
|
$config['base_url'] = $request->getParam('base_url');
|
||||||
$config['storage_dir'] = $request->getParam('storage_dir');
|
$config['storage_dir'] = $request->getParam('storage_dir');
|
||||||
|
$config['displayErrorDetails'] = false;
|
||||||
$config['db']['connection'] = $request->getParam('connection');
|
$config['db']['connection'] = $request->getParam('connection');
|
||||||
$config['db']['dsn'] = $request->getParam('dsn');
|
$config['db']['dsn'] = $request->getParam('dsn');
|
||||||
$config['db']['username'] = null;
|
$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) . ';');
|
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;
|
$firstMigrate = false;
|
||||||
if (!file_exists(__DIR__ . '../' . $config['db']['dsn']) && DB::driver() === 'sqlite') {
|
if (!file_exists(__DIR__ . '/../' . $config['db']['dsn']) && DB::driver() === 'sqlite') {
|
||||||
touch(__DIR__ . '../' . $config['db']['dsn']);
|
touch(__DIR__ . '/../' . $config['db']['dsn']);
|
||||||
$firstMigrate = true;
|
$firstMigrate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,14 +81,11 @@ $app->post('/', function (Request $request, Response $response) use (&$config) {
|
||||||
$firstMigrate = true;
|
$firstMigrate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo 'Connected.' . PHP_EOL;
|
|
||||||
|
|
||||||
if ($firstMigrate) {
|
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) {
|
$names = array_map(function ($path) {
|
||||||
return basename($path);
|
return basename($path);
|
||||||
|
|
Loading…
Reference in a new issue