Setup/Misc

* fix some outdated array indizes during setup
 * fix indexing when connecting to DB for first time
 * add initial loading of config strings during setup
This commit is contained in:
Sarjuuk
2021-10-24 17:12:05 +02:00
parent 56e70e22bb
commit 6b49aa6069
7 changed files with 71 additions and 56 deletions

View File

@@ -93,10 +93,14 @@ if (!empty($AoWoWconf['characters']))
// load config to constants // load config to constants
$sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : []; function loadConfig(bool $noPHP = false) : void
foreach ($sets as $k => $v)
{ {
$sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : [];
foreach ($sets as $k => $v)
{
$php = $v['flags'] & CON_FLAG_PHP; $php = $v['flags'] & CON_FLAG_PHP;
if ($php && $noPHP)
continue;
// this should not have been possible // this should not have been possible
if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php) if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php)
@@ -128,8 +132,9 @@ foreach ($sets as $k => $v)
ini_set(strtolower($k), $val); ini_set(strtolower($k), $val);
else else
define('CFG_'.strtoupper($k), $val); define('CFG_'.strtoupper($k), $val);
}
} }
loadConfig();
// handle non-fatal errors and notices // handle non-fatal errors and notices
error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? E_AOWOW : 0); error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? E_AOWOW : 0);

View File

@@ -104,15 +104,15 @@ class CLISetup
self::$opts[$alias[$o] ?? $o] = (self::$optDefs[$alias[$o] ?? $o][2] & self::ARGV_ARRAY) ? ($v ? explode(',', $v) : []) : ($v ?: true); self::$opts[$alias[$o] ?? $o] = (self::$optDefs[$alias[$o] ?? $o][2] & self::ARGV_ARRAY) ? ($v ? explode(',', $v) : []) : ($v ?: true);
// optional logging // optional logging
if (self::$opts['log']) if (isset(self::$opts['log']))
CLI::initLogFile(trim(self::$opts['log'])); CLI::initLogFile(trim(self::$opts['log']));
// alternative data source (no quotes, use forward slash) // alternative data source (no quotes, use forward slash)
if (self::$opts['mpqDataDir']) if (isset(self::$opts['mpqDataDir']))
self::$srcDir = CLI::nicePath($self::$opts['mpqDataDir']); self::$srcDir = CLI::nicePath($self::$opts['mpqDataDir']);
// optional limit handled locales // optional limit handled locales
if (self::$opts['locales']) if (isset(self::$opts['locales']))
{ {
// engb and enus are identical for all intents and purposes // engb and enus are identical for all intents and purposes
$from = ['engb', 'esmx', 'encn']; $from = ['engb', 'esmx', 'encn'];

View File

@@ -118,7 +118,7 @@ function setup() : void
require 'config/config.php'; require 'config/config.php';
$error = []; $error = [];
foreach (['world', 'aowow', 'auth'] as $idx => $what) foreach (['aowow', 'world', 'auth'] as $idx => $what)
{ {
if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host']))) if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host'])))
continue; continue;

View File

@@ -431,6 +431,9 @@ function siteconfig() : void
$updScripts = []; $updScripts = [];
} }
} }
// actually load set constants
loadConfig(true);
} }
?> ?>

View File

@@ -349,7 +349,10 @@ class DBC
$this->createTable(); $this->createTable();
CLI::write(' - reading '.($this->localized ? 'and merging ' : '').$this->file.'.dbc for locales '.implode(', ', array_keys($this->fileRefs))); if ($this->localized)
CLI::write(' - reading and merging '.$this->file.'.dbc for locales '.implode(', ', array_keys($this->fileRefs)));
else
CLI::write(' - reading '.$this->file.'.dbc');
if (!$this->read()) if (!$this->read())
{ {

View File

@@ -58,11 +58,11 @@ class FileGen
'static/wowsounds/' 'static/wowsounds/'
); );
public static $txtConstants = array( private static $txtConstants = array(
'CFG_NAME' => CFG_NAME, 'CFG_NAME' => '',
'CFG_NAME_SHORT' => CFG_NAME_SHORT, 'CFG_NAME_SHORT' => '',
'HOST_URL' => HOST_URL, 'HOST_URL' => '',
'STATIC_URL' => STATIC_URL 'STATIC_URL' => ''
); );
public static function init(int $mode = self::MODE_NORMAL, array $updScripts = []) : bool public static function init(int $mode = self::MODE_NORMAL, array $updScripts = []) : bool
@@ -76,15 +76,6 @@ class FileGen
return false; return false;
} }
// handle command prompts
if (!self::handleCLIOpts($doScripts))
return false;
// check passed subscript names; limit to real scriptNames
self::$subScripts = array_merge(array_keys(self::$tplFiles), array_keys(self::$datasets));
if ($doScripts || $updScripts)
self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts);
// create directory structure // create directory structure
CLI::write('FileGen::init() - creating required directories'); CLI::write('FileGen::init() - creating required directories');
$pathOk = 0; $pathOk = 0;
@@ -95,6 +86,15 @@ class FileGen
CLI::write('created '.$pathOk.' extra paths'.($pathOk == count(self::$reqDirs) ? '' : ' with errors')); CLI::write('created '.$pathOk.' extra paths'.($pathOk == count(self::$reqDirs) ? '' : ' with errors'));
CLI::write(); CLI::write();
// handle command prompts
if (!self::handleCLIOpts($doScripts))
return false;
// check passed subscript names; limit to real scriptNames
self::$subScripts = array_merge(array_keys(self::$tplFiles), array_keys(self::$datasets));
if ($doScripts || $updScripts)
self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts);
return true; return true;
} }
@@ -183,10 +183,14 @@ class FileGen
{ {
[$file, $destPath, $deps] = self::$tplFiles[$key]; [$file, $destPath, $deps] = self::$tplFiles[$key];
if ($content = file_get_contents(FileGen::$tplPath.$file.'.in')) foreach (self::$txtConstants as $n => &$c)
if (!$c && defined($n))
$c = constant($n);
if ($content = file_get_contents(self::$tplPath.$file.'.in'))
{ {
// replace constants // replace constants
$content = strtr($content, FileGen::$txtConstants); $content = strtr($content, self::$txtConstants);
// check for required auxiliary DBC files // check for required auxiliary DBC files
foreach ($reqDBC as $req) foreach ($reqDBC as $req)
@@ -217,7 +221,7 @@ class FileGen
$success = true; $success = true;
} }
else else
CLI::write(sprintf(ERR_READ_FILE, CLI::bold(FileGen::$tplPath.$file.'.in')), CLI::LOG_ERROR); CLI::write(sprintf(ERR_READ_FILE, CLI::bold(self::$tplPath.$file.'.in')), CLI::LOG_ERROR);
} }
else if (!empty(self::$datasets[$key])) else if (!empty(self::$datasets[$key]))
{ {
@@ -234,7 +238,7 @@ class FileGen
CLI::write(' - subscript \''.$key.'\' not defined in included file', CLI::LOG_ERROR); CLI::write(' - subscript \''.$key.'\' not defined in included file', CLI::LOG_ERROR);
} }
set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script set_time_limit(self::$defaultExecTime); // reset to default for the next script
return $success; return $success;
} }

View File

@@ -103,7 +103,7 @@ SqlGen::register(new class extends SetupScript
// spawn does not really match on a map, but we need at least one result // spawn does not really match on a map, but we need at least one result
if (!$result) if (!$result)
{ {
usort($points, function ($a, $b) { return ($a['quality'] < $b['quality']) ? -1 : 1; }); usort($points, function ($a, $b) { return ($a['dist'] < $b['dist']) ? -1 : 1; });
$result = [1.0, $points[0]]; $result = [1.0, $points[0]];
} }