mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
DB/Errors
* improve db error handling * web view should always result in an user friendly error if the db connection is missing or erronous * cli use should never fatal if the db connection is erronous. How are you going to fix it, d'uh. * if some CLISetup script requires a db connection check it individually
This commit is contained in:
@@ -58,10 +58,7 @@ switch ($cmd) // we accept only on
|
||||
|
||||
$dbc = new DBC(trim($n), ['temporary' => false]);
|
||||
if ($dbc->error)
|
||||
{
|
||||
CLI::write('CLISetup::loadDBC() - required DBC '.$n.'.dbc not found!', CLI::LOG_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$dbc->readFile())
|
||||
{
|
||||
|
||||
@@ -130,7 +130,7 @@ class CLISetup
|
||||
self::$localeIds[] = $idx;
|
||||
|
||||
// get site status
|
||||
if (DB::isConnectable(DB_AOWOW))
|
||||
if (DB::isConnected(DB_AOWOW))
|
||||
self::$lock = (int)DB::Aowow()->selectCell('SELECT `value` FROM ?_config WHERE `key` = "maintenance"');
|
||||
else
|
||||
self::$lock = self::LOCK_ON;
|
||||
@@ -199,7 +199,7 @@ class CLISetup
|
||||
|
||||
public static function siteLock(int $mode = self::LOCK_RESTORE) : void
|
||||
{
|
||||
if (DB::isConnectable(DB_AOWOW))
|
||||
if (DB::isConnected(DB_AOWOW))
|
||||
DB::Aowow()->query('UPDATE ?_config SET `value` = ?d WHERE `key` = "maintenance"', (int)!!($mode == self::LOCK_RESTORE ? self::$lock : $mode));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,14 @@ function account() : void
|
||||
'pass2' => ['Confirm Password', true ]
|
||||
);
|
||||
|
||||
if (!DB::isConnected(DB_AOWOW))
|
||||
{
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
User::useLocale(LOCALE_EN);
|
||||
Lang::load(LOCALE_EN);
|
||||
|
||||
|
||||
@@ -13,6 +13,14 @@ if (!CLI)
|
||||
|
||||
function build($syncMe = null) : array
|
||||
{
|
||||
if (!DB::isConnected(DB_AOWOW) || !DB::isConnected(DB_WORLD))
|
||||
{
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return [];
|
||||
}
|
||||
|
||||
require_once 'setup/tools/fileGen.class.php';
|
||||
|
||||
if(!FileGen::init($syncMe !== null ? FileGen::MODE_UPDATE : FileGen::MODE_NORMAL, $syncMe ?: []))
|
||||
|
||||
@@ -24,18 +24,19 @@ function dbconfig() : void
|
||||
);
|
||||
$testDB = function($idx, $name, $dbInfo)
|
||||
{
|
||||
$buff = '['.CLI::bold($idx).'] '.str_pad($name, 17);
|
||||
$buff = ['['.CLI::bold($idx).']', $name];
|
||||
|
||||
if ($dbInfo['host'])
|
||||
{
|
||||
DB::test($dbInfo, $errStr);
|
||||
|
||||
$buff .= $errStr ? CLI::red('ERR ') : CLI::green('OK ');
|
||||
$buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', mb_strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].'/'.$dbInfo['db'];
|
||||
$buff .= ($dbInfo['prefix'] ? ' table prefix: '.$dbInfo['prefix'] : null).' '.$errStr;
|
||||
$buff[] = $errStr ? CLI::red('ERR') : CLI::green('OK');
|
||||
$buff[] = 'mysqli://'.$dbInfo['user'].':'.($dbInfo['pass'] ? '**********' : '').'@'.$dbInfo['host'].'/'.$dbInfo['db'];
|
||||
$buff[] = $dbInfo['prefix'] ? 'table prefix: '.$dbInfo['prefix'] : '';
|
||||
$buff[] = $errStr;
|
||||
}
|
||||
else
|
||||
$buff .= ' '.CLI::bold('<empty>');
|
||||
$buff[] = CLI::bold('<empty>');
|
||||
|
||||
return $buff;
|
||||
};
|
||||
@@ -52,17 +53,18 @@ function dbconfig() : void
|
||||
CLI::write("select a numerical index to use the corresponding entry");
|
||||
|
||||
$nCharDBs = 0;
|
||||
$tblRows = [];
|
||||
foreach ($databases as $idx => $name)
|
||||
{
|
||||
if ($idx != 3)
|
||||
CLI::write($testDB($idx, $name, $AoWoWconf[$name]));
|
||||
$tblRows[] = $testDB($idx, $name, $AoWoWconf[$name]);
|
||||
else if (!empty($AoWoWconf[$name]))
|
||||
foreach ($AoWoWconf[$name] as $charIdx => $dbInfo)
|
||||
CLI::write($testDB($idx + $nCharDBs++, $name.' ['.$charIdx.']', $AoWoWconf[$name][$charIdx]));
|
||||
$tblRows[] = $testDB($idx + $nCharDBs++, $name.' ['.$charIdx.']', $AoWoWconf[$name][$charIdx]);
|
||||
}
|
||||
|
||||
CLI::write("[".CLI::bold(3 + $nCharDBs)."] add an additional Character DB");
|
||||
CLI::write();
|
||||
$tblRows[] = ['['.CLI::bold(3 + $nCharDBs).']', 'add new character DB'];
|
||||
CLI::writeTable($tblRows, true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -168,6 +168,12 @@ function setup() : void
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!DB::isConnected(DB_AOWOW))
|
||||
{
|
||||
$error[] = ' * not connected to DB';
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = DB::Aowow()->selectCol('SELECT `key` AS ARRAY_KEY, value FROM ?_config WHERE `key` IN ("site_host", "static_host", "force_ssl")');
|
||||
$prot = $res['force_ssl'] ? 'https://' : 'http://';
|
||||
$cases = array(
|
||||
|
||||
@@ -16,9 +16,10 @@ function siteconfig() : void
|
||||
$reqKeys = ['site_host', 'static_host'];
|
||||
$updScripts = [];
|
||||
|
||||
if (!DB::isConnectable(DB_AOWOW))
|
||||
if (!DB::isConnected(DB_AOWOW))
|
||||
{
|
||||
CLI::write("database not yet set up!\n Please use --dbconfig for setup", CLI::LOG_WARN);
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,14 @@ if (!CLI)
|
||||
|
||||
function sql($syncMe = null) : array
|
||||
{
|
||||
if (!DB::isConnected(DB_AOWOW) || !DB::isConnected(DB_WORLD))
|
||||
{
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return [];
|
||||
}
|
||||
|
||||
require_once 'setup/tools/sqlGen.class.php';
|
||||
|
||||
if (!SqlGen::init($syncMe !== null ? SqlGen::MODE_UPDATE : SqlGen::MODE_NORMAL, $syncMe ?: []))
|
||||
|
||||
@@ -30,6 +30,14 @@ function sync(array $s = [], array $b = []) : void
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DB::isConnected(DB_AOWOW) || !DB::isConnected(DB_WORLD))
|
||||
{
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
$_s = sql($s);
|
||||
if ($s)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,14 @@ if (!CLI)
|
||||
|
||||
function update(?array &$sql = [], ?array &$build = []) : void
|
||||
{
|
||||
if (!DB::isConnected(DB_AOWOW))
|
||||
{
|
||||
CLI::write('Database not yet set up!', CLI::LOG_WARN);
|
||||
CLI::write('Please use '.CLI::bold('"php aowow --dbconfig"').' for setup', CLI::LOG_BLANK);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
[$date, $part] = array_values(DB::Aowow()->selectRow('SELECT `date`, `part` FROM ?_dbversion'));
|
||||
|
||||
if (CLISetup::getOpt('help'))
|
||||
|
||||
@@ -280,6 +280,14 @@ class DBC
|
||||
if (empty($this->_fields[$file]) || empty($this->_formats[$file]))
|
||||
{
|
||||
CLI::write('no structure known for '.$file.'.dbc, aborting.', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DB::isConnected(DB_AOWOW))
|
||||
{
|
||||
CLI::write('not connected to db, aborting.', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,6 +299,7 @@ class DBC
|
||||
if (count($this->fields) != strlen(str_ireplace('x', '', $this->format)))
|
||||
{
|
||||
CLI::write('known field types ['.count($this->fields).'] and names ['.strlen(str_ireplace('x', '', $this->format)).'] do not match for '.$file.'.dbc, aborting.', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,6 +336,7 @@ class DBC
|
||||
if (!$this->fileRefs)
|
||||
{
|
||||
CLI::write('no suitable files found for '.$file.'.dbc, aborting.', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -336,18 +346,21 @@ class DBC
|
||||
if (count($x) != 1)
|
||||
{
|
||||
CLI::write('some DBCs have differenct record counts ('.implode(', ', $x).' respectively). cannot merge!', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
$x = array_unique(array_column($headers, 'fieldCount'));
|
||||
if (count($x) != 1)
|
||||
{
|
||||
CLI::write('some DBCs have differenct field counts ('.implode(', ', $x).' respectively). cannot merge!', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
$x = array_unique(array_column($headers, 'recordSize'));
|
||||
if (count($x) != 1)
|
||||
{
|
||||
CLI::write('some DBCs have differenct record sizes ('.implode(', ', $x).' respectively). cannot merge!', CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ if (!CLI)
|
||||
if (!$set)
|
||||
CLI::write(' - realmMenu: Auth-DB not set up .. realm menu will be empty', CLI::LOG_WARN);
|
||||
|
||||
Lang::load(LOCALE_EN); // why is this file not localized!?
|
||||
|
||||
foreach (Util::$regions as $idx => $n)
|
||||
if ($set & (1 << $idx))
|
||||
$menu[] = [$n, Lang::profiler('regions', $n), null, &$subs[$idx]];
|
||||
|
||||
@@ -1161,6 +1161,7 @@ SqlGen::register(new class extends SetupScript
|
||||
{
|
||||
CLI::write(' * #13 cuStrings', CLI::LOG_BLANK, true, true);
|
||||
|
||||
Lang::load(LOCALE_EN);
|
||||
foreach (Lang::game('pvpSources') as $src => $__)
|
||||
$this->pushBuffer(Type::TITLE, $src, SRC_CUSTOM_STRING, $src);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user