From 366f68f24f742d924cf28b2b2baeceffa7ee5a0b Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Mon, 28 Feb 2022 21:01:07 +0100 Subject: [PATCH] Setup/Misc * squash some more php warnings during setup * automaticly sync if required by updates --- setup/tools/clisetup/dbconfig.func.php | 2 +- setup/tools/clisetup/setup.func.php | 17 +++++++++++------ setup/tools/clisetup/sync.func.php | 2 +- setup/tools/filegen/itemsets.func.php | 3 +-- setup/tools/filegen/simpleImg.func.php | 3 ++- setup/tools/filegen/talentCalc.func.php | 2 +- setup/tools/sqlgen/itemset.func.php | 4 ++-- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/setup/tools/clisetup/dbconfig.func.php b/setup/tools/clisetup/dbconfig.func.php index 99218012..4bf24d88 100644 --- a/setup/tools/clisetup/dbconfig.func.php +++ b/setup/tools/clisetup/dbconfig.func.php @@ -31,7 +31,7 @@ function dbconfig() : void DB::test($dbInfo, $errStr); $buff .= $errStr ? CLI::red('ERR ') : CLI::green('OK '); - $buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', mb_strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].($port ? ':'.$port : null).'/'.$dbInfo['db']; + $buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', mb_strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].'/'.$dbInfo['db']; $buff .= ($dbInfo['prefix'] ? ' table prefix: '.$dbInfo['prefix'] : null).' '.$errStr; } else diff --git a/setup/tools/clisetup/setup.func.php b/setup/tools/clisetup/setup.func.php index e627a511..dfd4a401 100644 --- a/setup/tools/clisetup/setup.func.php +++ b/setup/tools/clisetup/setup.func.php @@ -24,10 +24,11 @@ function setup() : void /* define steps */ /****************/ + $upd = [[], []]; // ref to pass commands from 'update' to 'sync' $steps = array( // clisetup, params, test function, introText, errorText - ['dbconfig', null, 'testDB', 'Please enter your database credentials.', 'could not establish connection to:'], - ['siteconfig', null, 'testSelf', 'SITE_HOST and STATIC_HOST '.CLI::bold('must').' be set. Also enable FORCE_SSL if needed. You may also want to change other variables such as NAME, NAME_SHORT or LOCALES.', 'could not access:'], + ['dbconfig', [null], 'testDB', 'Please enter your database credentials.', 'could not establish connection to:'], + ['siteconfig', [null], 'testSelf', 'SITE_HOST and STATIC_HOST '.CLI::bold('must').' be set. Also enable FORCE_SSL if needed. You may also want to change other variables such as NAME, NAME_SHORT or LOCALES.', 'could not access:'], // sql- and build- stuff here ['SqlGen::generate', 'areatrigger', null, null, null], ['SqlGen::generate', 'achievementcriteria', null, null, null], @@ -98,8 +99,9 @@ function setup() : void ['FileGen::generate', 'profiler', null, null, null], ['FileGen::generate', 'weightPresets', null, null, null], // apply sql-updates from repository - ['update', null, null, null, null], - ['account', null, 'testAcc', 'Please create your admin account.', 'There is no user with administrator privileges in the DB.'] + ['update', &$upd, null, null, null], + ['sync', &$upd, null, null, null], + ['account', [null], 'testAcc', 'Please create your admin account.', 'There is no user with administrator privileges in the DB.'] ); @@ -244,7 +246,7 @@ function setup() : void if ($startStep) { - CLI::write('Found firstrun progression info. (Halted on subscript '.($steps[$startStep][1] ?: $steps[$startStep][0]).')', CLI::LOG_INFO); + CLI::write('Found firstrun progression info. (Halted on subscript '.($steps[$startStep][1][0] ? $steps[$startStep][1] : $steps[$startStep][0]).')', CLI::LOG_INFO); $inp = ['x' => ['continue setup? (y/n)', true, '/y|n/i']]; $msg = ''; if (!CLI::read($inp, true) || !$inp || strtolower($inp['x']) == 'n') @@ -286,7 +288,10 @@ function setup() : void while (true) { - $res = call_user_func($step[0], $step[1]); + if (strpos($step[0], '::')) + $res = call_user_func($step[0], $step[1]); + else + $res = $step[0](...$step[1]); // check script result if ($step[2]) diff --git a/setup/tools/clisetup/sync.func.php b/setup/tools/clisetup/sync.func.php index 0697efba..388d4c7f 100644 --- a/setup/tools/clisetup/sync.func.php +++ b/setup/tools/clisetup/sync.func.php @@ -17,7 +17,7 @@ require_once 'setup/tools/clisetup/build.func.php'; function sync(array $s = [], array $b = []) : void { - if ((!$s && !$b && !CLISetup::getOpt('sync')) || CLISetup::getOpt('help')) + if ((!$s && !$b && !CLISetup::getOpt('sync') && !CLISetup::getOpt('setup')) || CLISetup::getOpt('help')) { CLI::write(); CLI::write(' usage: php aowow --sync= [--locales: --mpqDataDir: --force -f]', -1, false); diff --git a/setup/tools/filegen/itemsets.func.php b/setup/tools/filegen/itemsets.func.php index cb5d64fb..36c1b24c 100644 --- a/setup/tools/filegen/itemsets.func.php +++ b/setup/tools/filegen/itemsets.func.php @@ -93,8 +93,7 @@ if (!CLI) if (!isset($setOut['setbonus'][$set['bonus'.$i]])) $setOut['setbonus'][$set['bonus'.$i]] = $jsonBonus[$set['spell'.$i]]; else - foreach ($jsonBonus[$set['spell'.$i]] as $k => $v) - @$setOut['setbonus'][$set['bonus'.$i]][$k] += $v; + Util::arraySumByKey($setOut['setbonus'][$set['bonus'.$i]], $jsonBonus[$set['spell'.$i]]); } foreach ($setOut['setbonus'] as $k => $v) diff --git a/setup/tools/filegen/simpleImg.func.php b/setup/tools/filegen/simpleImg.func.php index f7b59c1c..595ac452 100644 --- a/setup/tools/filegen/simpleImg.func.php +++ b/setup/tools/filegen/simpleImg.func.php @@ -315,7 +315,8 @@ if (!CLI) ini_set('max_execution_time', 30); // max 30sec per image (loading takes the most time) $src = null; - $img = explode('.', array_pop(explode('/', $f))); + $na = explode('/', $f); + $img = explode('.', array_pop($na)); array_pop($img); // there are a hand full of images with multiple file endings or random dots in the name $img = implode('.', $img); diff --git a/setup/tools/filegen/talentCalc.func.php b/setup/tools/filegen/talentCalc.func.php index 025c0e9e..10e6d68d 100644 --- a/setup/tools/filegen/talentCalc.func.php +++ b/setup/tools/filegen/talentCalc.func.php @@ -118,7 +118,7 @@ if (!CLI) if (!isset($tNums[$talents[$talentIdx]['reqTalent']])) $depLinks[$talents[$talentIdx]['reqTalent']] = $talentIdx; - $r = @[$tNums[$talents[$talentIdx]['reqTalent']], $talents[$talentIdx]['reqRank'] + 1]; + $r = [$tNums[$talents[$talentIdx]['reqTalent']] ?? 0, $talents[$talentIdx]['reqRank'] + 1]; } $result[$tabIdx]['t'][$talentIdx] = array( diff --git a/setup/tools/sqlgen/itemset.func.php b/setup/tools/sqlgen/itemset.func.php index 853cf347..9adb9d5f 100644 --- a/setup/tools/sqlgen/itemset.func.php +++ b/setup/tools/sqlgen/itemset.func.php @@ -230,9 +230,9 @@ SqlGen::register(new class extends SetupScript $row['bonusParsed'] = serialize($gains); foreach (array_column($spells, 0) as $idx => $spellId) - $row['spell'.$idx+1] = $spellId; + $row['spell'.($idx+1)] = $spellId; foreach (array_column($spells, 1) as $idx => $nItems) - $row['bonus'.$idx+1] = $nItems; + $row['bonus'.($idx+1)] = $nItems; /**************************/