summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/SetupController.php16
-rw-r--r--app/Http/Middleware/UseTree.php5
-rw-r--r--index.php29
-rw-r--r--resources/views/setup/config.ini.phtml8
4 files changed, 20 insertions, 38 deletions
diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php
index 63403a7b13..adf3d507e8 100644
--- a/app/Http/Controllers/SetupController.php
+++ b/app/Http/Controllers/SetupController.php
@@ -20,11 +20,13 @@ namespace Fisharebest\Webtrees\Http\Controllers;
use Exception;
use Fisharebest\Localization\Locale;
use Fisharebest\Localization\Locale\LocaleEnUs;
+use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\MigrationService;
use Fisharebest\Webtrees\Services\ServerCheckService;
use Fisharebest\Webtrees\Services\UserService;
+use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Webtrees;
use Illuminate\Database\Capsule\Manager;
use SQLite3;
@@ -339,17 +341,13 @@ class SetupController extends AbstractBaseController
->setPreference('verified_by_admin', '1');
// Write the config file. We already checked that this would work.
- $config_ini_php =
- '; <' . '?php exit; ?' . '> DO NOT DELETE THIS LINE' . PHP_EOL .
- 'dbtype="' . addcslashes($data['dbtype'], '"') . '"' . PHP_EOL .
- 'dbhost="' . addcslashes($data['dbhost'], '"') . '"' . PHP_EOL .
- 'dbport="' . addcslashes($data['dbport'], '"') . '"' . PHP_EOL .
- 'dbuser="' . addcslashes($data['dbuser'], '"') . '"' . PHP_EOL .
- 'dbpass="' . addcslashes($data['dbpass'], '"') . '"' . PHP_EOL .
- 'dbname="' . addcslashes($data['dbname'], '"') . '"' . PHP_EOL .
- 'tblpfx="' . addcslashes($data['tblpfx'], '"') . '"' . PHP_EOL;
+ $config_ini_php = view('setup/config.ini', $data);
file_put_contents(Webtrees::CONFIG_FILE, $config_ini_php);
+
+ // Login as the new user
+ Session::start();
+ Auth::login($admin);
}
/**
diff --git a/app/Http/Middleware/UseTree.php b/app/Http/Middleware/UseTree.php
index 81672d3762..439d7646a7 100644
--- a/app/Http/Middleware/UseTree.php
+++ b/app/Http/Middleware/UseTree.php
@@ -54,7 +54,10 @@ class UseTree implements MiddlewareInterface
// Most layouts will require a tree for the page header/footer
View::share('tree', $tree);
- app()->instance(Tree::class, $tree);
+ // Need a closure, as the container does not allow you to bind null.
+ app()->bind(Tree::class, function() use ($tree): ?Tree {
+ return $tree;
+ });
return $next($request);
}
diff --git a/index.php b/index.php
index 0fccfca463..a8f62bc0cf 100644
--- a/index.php
+++ b/index.php
@@ -31,7 +31,6 @@ use Fisharebest\Webtrees\Http\Middleware\UseSession;
use Fisharebest\Webtrees\Http\Middleware\UseTheme;
use Fisharebest\Webtrees\Http\Middleware\UseTransaction;
use Fisharebest\Webtrees\Http\Middleware\UseTree;
-use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\MigrationService;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Services\TimeoutService;
@@ -72,11 +71,11 @@ $request_uri = $request->getSchemeAndHttpHost() . $request->getRequestUri();
$base_uri = preg_replace('/[^\/]+\.php(\?.*)?$/', '', $request_uri);
define('WT_BASE_URL', $base_uri);
-// Connect to the database
try {
// No config file? Run the setup wizard
if (!file_exists(Webtrees::CONFIG_FILE)) {
define('WT_DATA_DIR', 'data/');
+
/** @var SetupController $controller */
$controller = app()->make(SetupController::class);
$response = $controller->setup($request);
@@ -84,33 +83,7 @@ try {
return;
}
-} catch (PDOException $exception) {
- defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/');
- I18N::init();
- if ($exception->getCode() === 1045) {
- // Error during connection?
- $content = view('errors/database-connection', ['error' => $exception->getMessage()]);
- } else {
- // Error in a migration script?
- $content = view('errors/database-error', ['error' => $exception->getMessage()]);
- }
- $html = view('layouts/error', ['content' => $content]);
- $response = new Response($html, Response::HTTP_SERVICE_UNAVAILABLE);
- $response->prepare($request)->send();
-
- return;
-} catch (Throwable $exception) {
- defined('WT_DATA_DIR') || define('WT_DATA_DIR', 'data/');
- I18N::init();
- $content = view('errors/database-connection', ['error' => $exception->getMessage()]);
- $html = view('layouts/error', ['content' => $content]);
- $response = new Response($html, Response::HTTP_SERVICE_UNAVAILABLE);
- $response->prepare($request)->send();
- return;
-}
-
-try {
$database_config = parse_ini_file(Webtrees::CONFIG_FILE);
if ($database_config === false) {
diff --git a/resources/views/setup/config.ini.phtml b/resources/views/setup/config.ini.phtml
new file mode 100644
index 0000000000..b351ca22ee
--- /dev/null
+++ b/resources/views/setup/config.ini.phtml
@@ -0,0 +1,8 @@
+; <<?= '?php' ?> return; ?> DO NOT DELETE THIS LINE
+dbtype="<?= addcslashes($dbtype, '"') ?>"
+dbhost="<?= addcslashes($dbhost, '"') ?>"
+dbport="<?= addcslashes($dbport, '"') ?>"
+dbuser="<?= addcslashes($dbuser, '"') ?>"
+dbpass="<?= addcslashes($dbpass, '"') ?>"
+dbname="<?= addcslashes($dbname, '"') ?>"
+tblpfx="<?= addcslashes($tblpfx, '"') ?>"