diff --git a/includes/components/profiler.class.php b/includes/components/profiler.class.php index 9cb503c0..786e4351 100644 --- a/includes/components/profiler.class.php +++ b/includes/components/profiler.class.php @@ -11,6 +11,13 @@ class Profiler public const /* string */ PID_FILE = 'config/pr-queue-pid'; public const /* int */ CHAR_GMFLAGS = 0x1 | 0x8 | 0x10 | 0x20; // PLAYER_EXTRA_ :: GM_ON | TAXICHEAT | GM_INVISIBLE | GM_CHAT + public const /* int */ FETCH_RESULT_OK = 1; + public const /* int */ FETCH_RESULT_OK_UNCHANGED = 2; + public const /* int */ FETCH_RESULT_ERR_NOT_FOUND = 3; + public const /* int */ FETCH_RESULT_ERR_NAME_EMPTY = 4; + public const /* int */ FETCH_RESULT_ERR_NO_MEMBERS = 5; + public const /* int */ FETCH_RESULT_ERR_INTERNAL = 6; + public const /* array */ REGIONS = array( // see cfg_categories.dbc 'us' => [2, 3, 4, 5], // US (us, oceanic, latin america, americas - tournament) 'kr' => [6, 7], // KR (kr, tournament) @@ -359,22 +366,19 @@ class Profiler return Util::toJSON($response); } - public static function getCharFromRealm(int $realmId, int $charGuid) : bool + public static function getCharFromRealm(int $realmId, int $charGuid) : int { $char = DB::Characters($realmId)->selectRow('SELECT c.* FROM characters c WHERE c.`guid` = ?d', $charGuid); if (!$char) - return false; + return self::FETCH_RESULT_ERR_NOT_FOUND; if (!$char['name']) - { - trigger_error('char #'.$charGuid.' on realm #'.$realmId.' has empty name. skipping...', E_USER_WARNING); - return false; - } + return self::FETCH_RESULT_ERR_NAME_EMPTY; // reminder: this query should not fail: a placeholder entry is created as soon as a char listview is created or profile detail page is called $profile = DB::Aowow()->selectRow('SELECT `id`, `lastupdated` FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` = ?d', $realmId, $char['guid']); if (!$profile) - return false; // well ... it failed + return self::FETCH_RESULT_ERR_INTERNAL; // well ... it failed $profileId = $profile['id']; @@ -383,8 +387,7 @@ class Profiler if (!$char['online'] && $char['logout_time'] <= $profile['lastupdated']) { DB::Aowow()->query('UPDATE ?_profiler_profiles SET `lastupdated` = ?d WHERE `id` = ?d', time(), $profileId); - CLI::write('char did not log in since last update. skipping...'); - return true; + return self::FETCH_RESULT_OK_UNCHANGED; } CLI::write('writing...'); @@ -888,20 +891,17 @@ class Profiler if (DB::Aowow()->query('UPDATE ?_profiler_profiles SET ?a WHERE `realm` = ?d AND `realmGUID` = ?d', $data, $realmId, $charGuid) !== null) DB::Aowow()->query('UPDATE ?_profiler_profiles SET `stub` = 0 WHERE `id` = ?d', $profileId); - return true; + return self::FETCH_RESULT_OK; } - public static function getGuildFromRealm(int $realmId, int $guildGuid) : bool + public static function getGuildFromRealm(int $realmId, int $guildGuid) : int { $guild = DB::Characters($realmId)->selectRow('SELECT `guildId`, `name`, `createDate`, `info`, `backgroundColor`, `emblemStyle`, `emblemColor`, `borderStyle`, `borderColor` FROM guild WHERE `guildId` = ?d', $guildGuid); if (!$guild) - return false; + return self::FETCH_RESULT_ERR_NOT_FOUND; if (!$guild['name']) - { - trigger_error('guild #'.$guildGuid.' on realm #'.$realmId.' has empty name. skipping...', E_USER_WARNING); - return false; - } + return self::FETCH_RESULT_ERR_NAME_EMPTY; // reminder: this query should not fail: a placeholder entry is created as soon as a team listview is created or team detail page is called $guildId = DB::Aowow()->selectCell('SELECT `id` FROM ?_profiler_guild WHERE `realm` = ?d AND `realmGUID` = ?d', $realmId, $guild['guildId']); @@ -941,10 +941,10 @@ class Profiler // this here should all happen within ProfileList $members = new RemoteProfileList($conditions, ['sv' => $realmId]); - if (!$members->error) - $members->initializeLocalEntries(); - else - return false; + if ($members->error) + return self::FETCH_RESULT_ERR_NO_MEMBERS; + + $members->initializeLocalEntries(); CLI::write(' ..guild members'); @@ -955,20 +955,17 @@ class Profiler DB::Aowow()->query('UPDATE ?_profiler_guild SET `stub` = 0 WHERE `id` = ?d', $guildId); - return true; + return self::FETCH_RESULT_OK; } - public static function getArenaTeamFromRealm(int $realmId, int $teamGuid) : bool + public static function getArenaTeamFromRealm(int $realmId, int $teamGuid) : int { $team = DB::Characters($realmId)->selectRow('SELECT `arenaTeamId`, `name`, `type`, `captainGuid`, `rating`, `seasonGames`, `seasonWins`, `weekGames`, `weekWins`, `rank`, `backgroundColor`, `emblemStyle`, `emblemColor`, `borderStyle`, `borderColor` FROM arena_team WHERE `arenaTeamId` = ?d', $teamGuid); if (!$team) - return false; + return self::FETCH_RESULT_ERR_NOT_FOUND; if (!$team['name']) - { - trigger_error('arena team #'.$teamGuid.' on realm #'.$realmId.' has empty name. skipping...', E_USER_WARNING); - return false; - } + return self::FETCH_RESULT_ERR_NAME_EMPTY; // reminder: this query should not fail: a placeholder entry is created as soon as a team listview is created or team detail page is called $teamId = DB::Aowow()->selectCell('SELECT `id` FROM ?_profiler_arena_team WHERE `realm` = ?d AND `realmGUID` = ?d', $realmId, $team['arenaTeamId']); @@ -1017,7 +1014,7 @@ class Profiler $mProfiles = new RemoteProfileList($conditions, ['sv' => $realmId]); if ($mProfiles->error) - return false; + return self::FETCH_RESULT_ERR_NO_MEMBERS; $mProfiles->initializeLocalEntries(); foreach ($mProfiles->iterate() as $__) @@ -1055,7 +1052,7 @@ class Profiler DB::Aowow()->query('UPDATE ?_profiler_arena_team SET `stub` = 0 WHERE `id` = ?d', $teamId); - return true; + return self::FETCH_RESULT_OK; } } diff --git a/prQueue b/prQueue index 4e7f388f..10bd8ac5 100755 --- a/prQueue +++ b/prQueue @@ -29,7 +29,7 @@ CLI::write('profiler queue started', CLI::LOG_OK); set_time_limit(0); $tCycle = microtime(true); -$error = function (int $type, int $realmGUID, int $realmId) : void +$error = function (int $type, int $realmGUID, int $realmId, int $fetchResult) : void { $what = match ($type) { @@ -38,8 +38,17 @@ $error = function (int $type, int $realmGUID, int $realmId) : void Type::ARENA_TEAM => 'arena team' }; + $msg = match ($fetchResult) + { + Profiler::FETCH_RESULT_ERR_NAME_EMPTY => 'Subject has an empty name and was skipped.', + Profiler::FETCH_RESULT_ERR_NOT_FOUND => 'Subject was not found. Truncating local placeholder.', + Profiler::FETCH_RESULT_ERR_NO_MEMBERS => 'Subject has no members. Truncating local placeholder.', + Profiler::FETCH_RESULT_ERR_INTERNAL => 'Internal Error - Data stub is missing.' + }; + + trigger_error('prQueue - [realm: '.$realmId.' '.$what.' guid: '.$realmGUID.'] '.$msg, E_USER_WARNING); + 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); }; @@ -68,7 +77,7 @@ 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']); - CLI::write('realm #'.$row['realm'].' for subject guid '.$row['realmGUID'].' is undefined', CLI::LOG_WARN); + CLI::write('realm #'.$row['realm'].' for subject guid '.$row['realmGUID'].' is missing/inaccessible.', CLI::LOG_WARN); continue; } else @@ -77,32 +86,45 @@ while (Cfg::get('PROFILER_ENABLE', true)) switch ($row['type']) { case Type::PROFILE: - if (!Profiler::getCharFromRealm($row['realm'], $row['realmGUID'])) + switch ($result = 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']); - continue 2; + case Profiler::FETCH_RESULT_OK_UNCHANGED: + CLI::write('char #'.$row['realmGUID'].' on realm #'.$row['realm'].' did not log in since last update. skipping...'); + case Profiler::FETCH_RESULT_OK: + break 2; + case Profiler::FETCH_RESULT_ERR_NAME_EMPTY: + case Profiler::FETCH_RESULT_ERR_NOT_FOUND: + DB::Aowow()->query('DELETE FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); + default: + $error(Type::PROFILE, $row['realmGUID'], $row['realm'], $result); + continue 3; } - - break; case Type::GUILD: - if (!Profiler::getGuildFromRealm($row['realm'], $row['realmGUID'])) + switch ($result = 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']); - continue 2; + case Profiler::FETCH_RESULT_OK: + break 2; + case Profiler::FETCH_RESULT_ERR_NAME_EMPTY: + case Profiler::FETCH_RESULT_ERR_NOT_FOUND: + case Profiler::FETCH_RESULT_ERR_NO_MEMBERS: + DB::Aowow()->query('DELETE FROM ?_profiler_guild WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); + default: + $error(Type::GUILD, $row['realmGUID'], $row['realm'], $result); + continue 3; } - - break; case Type::ARENA_TEAM: - if (!Profiler::getArenaTeamFromRealm($row['realm'], $row['realmGUID'])) + switch ($result = 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']); - continue 2; + case Profiler::FETCH_RESULT_OK: + break 2; + case Profiler::FETCH_RESULT_ERR_NAME_EMPTY: + case Profiler::FETCH_RESULT_ERR_NOT_FOUND: + case Profiler::FETCH_RESULT_ERR_NO_MEMBERS: + DB::Aowow()->query('DELETE FROM ?_profiler_arena_team WHERE `realm` = ?d AND `realmGUID` = ?d', $row['realm'], $row['realmGUID']); + default: + $error(Type::ARENA_TEAM, $row['realmGUID'], $row['realm'], $result); + continue 3; } - - break; default: DB::Aowow()->query('DELETE FROM ?_profiler_sync WHERE realm = ?d AND type = ?d AND typeId = ?d', $row['realm'], $row['type'], $row['typeId']); trigger_error('prQueue - unknown type #'.$row['type'].' to sync into profiler. Removing from queue...', E_USER_ERROR);