From 43778b01e7e480cf514e5ad333437d025258c431 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 18 Feb 2021 21:11:08 +0100 Subject: [PATCH] Setup/DB * connect to db after successful setup so siteconfig doesn't fail --- includes/database.class.php | 2 +- setup/setup.php | 3 ++- setup/tools/clisetup/firstrun.func.php | 7 ++++++- setup/tools/clisetup/siteconfig.func.php | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/database.class.php b/includes/database.class.php index 8656cfa4..d1cad02d 100644 --- a/includes/database.class.php +++ b/includes/database.class.php @@ -31,7 +31,7 @@ class DB $interface = DbSimple_Generic::connect(self::createConnectSyntax($options)); if (!$interface || $interface->error) - die('Failed to connect to database.'); + die('Failed to connect to database on index #'.$idx.".\n"); $interface->setErrorHandler(['DB', 'errorHandler']); $interface->query('SET NAMES ?', 'utf8mb4'); diff --git a/setup/setup.php b/setup/setup.php index 677f0538..b07b722e 100644 --- a/setup/setup.php +++ b/setup/setup.php @@ -26,7 +26,8 @@ function finish(bool $unlock = true) : void function lockSite(bool $enable = true) : void { - DB::Aowow()->query('UPDATE ?_config SET `value` = ?d WHERE `key` = "maintenance"', $enable ? 1 : 0); + if (DB::isConnectable(DB_AOWOW)) + DB::Aowow()->query('UPDATE ?_config SET `value` = ?d WHERE `key` = "maintenance"', $enable ? 1 : 0); } CLISetup::init(); diff --git a/setup/tools/clisetup/firstrun.func.php b/setup/tools/clisetup/firstrun.func.php index 175072da..07959d02 100644 --- a/setup/tools/clisetup/firstrun.func.php +++ b/setup/tools/clisetup/firstrun.func.php @@ -120,7 +120,7 @@ function firstrun() : bool $error = []; $defPort = ini_get('mysqli.default_port'); - foreach (['world', 'aowow', 'auth'] as $what) + foreach (['aowow', 'world', 'auth'] as $idx => $what) { if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host']))) continue; @@ -130,7 +130,12 @@ function firstrun() : bool [$AoWoWconf[$what]['host'], $port] = explode(':', $AoWoWconf[$what]['host']); if ($link = @mysqli_connect($AoWoWconf[$what]['host'], $AoWoWconf[$what]['user'], $AoWoWconf[$what]['pass'], $AoWoWconf[$what]['db'], $port ?: $defPort)) + { mysqli_close($link); + + // init proper access for further setup + DB::load($idx, $AoWoWconf[$what]); + } else $error[] = ' * '.$what.': '.'['.mysqli_connect_errno().'] '.mysqli_connect_error(); } diff --git a/setup/tools/clisetup/siteconfig.func.php b/setup/tools/clisetup/siteconfig.func.php index 3e863941..575729d7 100644 --- a/setup/tools/clisetup/siteconfig.func.php +++ b/setup/tools/clisetup/siteconfig.func.php @@ -16,7 +16,7 @@ function siteconfig() $reqKeys = ['site_host', 'static_host']; $updScripts = []; - if (!DB::isConnected(DB_AOWOW)) + if (!DB::isConnectable(DB_AOWOW)) { CLI::write(); CLI::write("database not yet set up!\n Please use --dbconfig for setup", CLI::LOG_WARN);