From cd94a2fa4e8a7677aa6e0a75f85358c69c5f0e57 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 17 Jun 2025 17:28:21 +0200 Subject: [PATCH] Profiler/Misc * fix realm selection in profiler filters * minor cleanup of prQueue --- includes/types/arenateam.class.php | 29 ++-------------------------- includes/types/basetype.class.php | 31 ++++++++++++++++++++++++++++++ includes/types/guild.class.php | 29 ++-------------------------- includes/types/profile.class.php | 29 ++-------------------------- prQueue | 31 +++++++++++++++--------------- 5 files changed, 52 insertions(+), 97 deletions(-) diff --git a/includes/types/arenateam.class.php b/includes/types/arenateam.class.php index b8ec9835..4f4bd946 100644 --- a/includes/types/arenateam.class.php +++ b/includes/types/arenateam.class.php @@ -46,6 +46,8 @@ class ArenaTeamList extends BaseType class ArenaTeamListFilter extends Filter { + use TrProfilerFilter; + public $extraOpts = []; protected $genericFilter = []; @@ -86,33 +88,6 @@ class ArenaTeamListFilter extends Filter return $parts; } - - protected function cbRegionCheck(string &$v) : bool - { - if (in_array($v, Util::$regions)) - { - $this->parentCats[0] = $v; // directly redirect onto this region - $v = ''; // remove from filter - - return true; - } - - return false; - } - - protected function cbServerCheck(string &$v) : bool - { - foreach (Profiler::getRealms() as $realm) - if ($realm['name'] == $v) - { - $this->parentCats[1] = Profiler::urlize($v);// directly redirect onto this server - $v = ''; // remove from filter - - return true; - } - - return false; - } } diff --git a/includes/types/basetype.class.php b/includes/types/basetype.class.php index be9c6c95..a5e2b919 100644 --- a/includes/types/basetype.class.php +++ b/includes/types/basetype.class.php @@ -918,6 +918,37 @@ trait sourceHelper } } +trait TrProfilerFilter +{ + protected function cbRegionCheck(string &$v) : bool + { + if (in_array($v, Util::$regions)) + { + $this->parentCats[0] = $v; // directly redirect onto this region + $v = ''; // remove from filter + + return true; + } + + return false; + } + + protected function cbServerCheck(string &$v) : bool + { + foreach (Profiler::getRealms() as $realm) + { + if (Profiler::urlize($realm['name']) != $v) + continue; + + $this->parentCats[1] = $v; // directly redirect onto this server + $v = ''; // remove from filter + + return true; + } + + return false; + } +} abstract class Filter { diff --git a/includes/types/guild.class.php b/includes/types/guild.class.php index ea496173..4c95443e 100644 --- a/includes/types/guild.class.php +++ b/includes/types/guild.class.php @@ -89,6 +89,8 @@ class GuildList extends BaseType class GuildListFilter extends Filter { + use TrProfilerFilter; + public $extraOpts = []; protected $genericFilter = []; @@ -124,33 +126,6 @@ class GuildListFilter extends Filter return $parts; } - - protected function cbRegionCheck(string &$v) : bool - { - if (in_array($v, Util::$regions)) - { - $this->parentCats[0] = $v; // directly redirect onto this region - $v = ''; // remove from filter - - return true; - } - - return false; - } - - protected function cbServerCheck(string &$v) : bool - { - foreach (Profiler::getRealms() as $realm) - if ($realm['name'] == $v) - { - $this->parentCats[1] = Profiler::urlize($v);// directly redirect onto this server - $v = ''; // remove from filter - - return true; - } - - return false; - } } diff --git a/includes/types/profile.class.php b/includes/types/profile.class.php index 8d435521..ced02086 100644 --- a/includes/types/profile.class.php +++ b/includes/types/profile.class.php @@ -239,6 +239,8 @@ class ProfileList extends BaseType class ProfileListFilter extends Filter { + use TrProfilerFilter; + public $useLocalList = false; public $extraOpts = []; @@ -359,33 +361,6 @@ class ProfileListFilter extends Filter return $parts; } - protected function cbRegionCheck(string &$v) : bool - { - if (in_array($v, Util::$regions)) - { - $this->parentCats[0] = $v; // directly redirect onto this region - $v = ''; // remove from filter - - return true; - } - - return false; - } - - protected function cbServerCheck(string &$v) : bool - { - foreach (Profiler::getRealms() as $realm) - if ($realm['name'] == $v) - { - $this->parentCats[1] = Profiler::urlize($v);// directly redirect onto this server - $v = ''; // remove from filter - - return true; - } - - return false; - } - protected function cbProfession(int $cr, int $crs, string $crv, $skillId) : ?array { if (!Util::checkNumeric($crv, NUM_CAST_INT) || !$this->int2Op($crs)) diff --git a/prQueue b/prQueue index c206e197..4e7f388f 100755 --- a/prQueue +++ b/prQueue @@ -29,17 +29,16 @@ CLI::write('profiler queue started', CLI::LOG_OK); set_time_limit(0); $tCycle = microtime(true); -$error = function ($type, $realmGUID, $realmId) +$error = function (int $type, int $realmGUID, int $realmId) : void { - $what = ''; - if ($type == Type::PROFILE) - $what = 'char'; - if ($type == Type::GUILD) - $what = 'guild'; - if ($type == Type::ARENA_TEAM) - $what = 'arena team'; + $what = match ($type) + { + Type::PROFILE => 'char', + Type::GUILD => 'guild', + Type::ARENA_TEAM => 'arena team' + }; - DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = ?d WHERE realm = ?d AND realmGUID = ?d AND type = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_CHAR, $realmId, $realmGUID, $type); + DB::Aowow()->query('UPDATE ?_profiler_sync SET `status` = ?d, `errorCode` = ?d WHERE `realm` = ?d AND `realmGUID` = ?d AND `type` = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_CHAR, $realmId, $realmGUID, $type); trigger_error('prQueue - '.$what.' #'.$realmGUID.' on realm #'.$realmId.' not found. Truncating local placeholder.', E_USER_WARNING); }; @@ -54,7 +53,7 @@ while (Cfg::get('PROFILER_ENABLE', true)) usleep($wait * 1000 * 1000); } - $row = DB::Aowow()->selectRow('SELECT * FROM ?_profiler_sync WHERE status = ?d ORDER BY requestTime ASC', PR_QUEUE_STATUS_WAITING); + $row = DB::Aowow()->selectRow('SELECT * FROM ?_profiler_sync WHERE `status` = ?d ORDER BY `requestTime` ASC', PR_QUEUE_STATUS_WAITING); if (!$row) { // nothing more to do @@ -68,12 +67,12 @@ while (Cfg::get('PROFILER_ENABLE', true)) if (empty(Profiler::getRealms()[$row['realm']])) { - DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = ?d WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_ARMORY, $row['realm'], $row['type'], $row['typeId']); + DB::Aowow()->query('UPDATE ?_profiler_sync SET `status` = ?d, `errorCode` = ?d WHERE `realm` = ?d AND `type` = ?d AND `typeId` = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_ARMORY, $row['realm'], $row['type'], $row['typeId']); CLI::write('realm #'.$row['realm'].' for subject guid '.$row['realmGUID'].' is undefined', CLI::LOG_WARN); continue; } else - DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_WORKING, $row['realm'], $row['type'], $row['typeId']); + DB::Aowow()->query('UPDATE ?_profiler_sync SET `status` = ?d WHERE `realm` = ?d AND `type` = ?d AND `typeId` = ?d', PR_QUEUE_STATUS_WORKING, $row['realm'], $row['type'], $row['typeId']); switch ($row['type']) { @@ -81,7 +80,7 @@ while (Cfg::get('PROFILER_ENABLE', true)) if (!Profiler::getCharFromRealm($row['realm'], $row['realmGUID'])) { $error(Type::PROFILE, $row['realmGUID'], $row['realm']); - DB::Aowow()->query('DELETE FROM ?_profiler_profiles WHERE realm = ?d AND realmGUID = ?d', $row['realm'], $row['realmGUID']); + DB::Aowow()->query('DELETE FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); continue 2; } @@ -90,7 +89,7 @@ while (Cfg::get('PROFILER_ENABLE', true)) if (!Profiler::getGuildFromRealm($row['realm'], $row['realmGUID'])) { $error(Type::GUILD, $row['realmGUID'], $row['realm']); - DB::Aowow()->query('DELETE FROM ?_profiler_guild WHERE realm = ?d AND realmGUID = ?d', $row['realm'], $row['realmGUID']); + DB::Aowow()->query('DELETE FROM ?_profiler_guild WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); continue 2; } @@ -99,7 +98,7 @@ while (Cfg::get('PROFILER_ENABLE', true)) if (!Profiler::getArenaTeamFromRealm($row['realm'], $row['realmGUID'])) { $error(Type::ARENA_TEAM, $row['realmGUID'], $row['realm']); - DB::Aowow()->query('DELETE FROM ?_profiler_arena_team WHERE realm = ?d AND realmGUID = ?d', $row['realm'], $row['realmGUID']); + DB::Aowow()->query('DELETE FROM ?_profiler_arena_team WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); continue 2; } @@ -112,7 +111,7 @@ while (Cfg::get('PROFILER_ENABLE', true)) $tCycle = microtime(true); // mark as ready - DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = 0 WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_READY, $row['realm'], $row['type'], $row['typeId']); + DB::Aowow()->query('UPDATE ?_profiler_sync SET `status` = ?d, `errorCode` = 0 WHERE `realm` = ?d AND `type` = ?d AND `typeId` = ?d', PR_QUEUE_STATUS_READY, $row['realm'], $row['type'], $row['typeId']); } Profiler::queueFree();