From 481a3dc63f2a436a92bef029c17809e21671fe29 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Wed, 31 Jul 2024 00:40:11 +0200 Subject: [PATCH] MySQL/Compat * fixed several deprecation notices and warnings from MySQL8, most notably: - SQL_CALC_FOUND_ROWS: stopped using DBSimple::selectPage and query 'SELECT COUNT(*) ...' separately where needed - ON DUPLICATE KEY UPDATE ... VALUES(): use row alias for new values instead of VALUES function - boolean shorthands to long form (&& -> AND, etc) --- includes/basetype.class.php | 26 +++-- includes/community.class.php | 110 ++++++++++++++++------ includes/profiler.class.php | 62 ++++++------ includes/types/achievement.class.php | 2 +- includes/types/areatrigger.class.php | 4 +- includes/types/arenateam.class.php | 4 +- includes/types/charclass.class.php | 4 +- includes/types/creature.class.php | 2 +- includes/types/currency.class.php | 4 +- includes/types/emote.class.php | 4 +- includes/types/enchantment.class.php | 4 +- includes/types/faction.class.php | 4 +- includes/types/gameobject.class.php | 2 +- includes/types/guide.class.php | 4 +- includes/types/guild.class.php | 4 +- includes/types/icon.class.php | 4 +- includes/types/item.class.php | 13 +-- includes/types/itemset.class.php | 4 +- includes/types/mail.class.php | 4 +- includes/types/profile.class.php | 6 +- includes/types/quest.class.php | 2 +- includes/types/skill.class.php | 4 +- includes/types/sound.class.php | 4 +- includes/types/spell.class.php | 4 +- includes/types/title.class.php | 4 +- includes/types/worldevent.class.php | 4 +- includes/types/zone.class.php | 2 +- pages/achievements.php | 4 +- pages/areatriggers.php | 2 +- pages/arenateams.php | 2 +- pages/enchantments.php | 2 +- pages/faction.php | 8 +- pages/guilds.php | 2 +- pages/icons.php | 2 +- pages/items.php | 2 +- pages/itemsets.php | 2 +- pages/npcs.php | 2 +- pages/object.php | 2 +- pages/objects.php | 2 +- pages/profiles.php | 2 +- pages/quest.php | 2 +- pages/quests.php | 2 +- pages/search.php | 56 +++++------ pages/sounds.php | 2 +- pages/spells.php | 2 +- pages/zone.php | 4 +- setup/tools/filegen/img-talentcalc.ss.php | 2 +- setup/tools/sqlgen/questsstartend.ss.php | 18 ++-- setup/tools/sqlgen/source.ss.php | 30 +++--- 49 files changed, 250 insertions(+), 197 deletions(-) diff --git a/includes/basetype.class.php b/includes/basetype.class.php index cbd51f29..5ed6bc6d 100644 --- a/includes/basetype.class.php +++ b/includes/basetype.class.php @@ -55,12 +55,15 @@ abstract class BaseType * results in * WHERE ((`id` = 45) OR (`name` NOT LIKE "test%") OR ((`flags` & 255) AND (`flags2` & 15)) OR ((`mask` & 3) = 0)) OR (`joinedTbl`.`field` IS NULL) LIMIT 5 */ - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { $where = []; $linking = ' AND '; $limit = Cfg::get('SQL_LIMIT_DEFAULT'); + $calcTotal = false; + $totalQuery = ''; + if (!$this->queryBase || $conditions === null) return; @@ -70,10 +73,13 @@ abstract class BaseType else $prefixes['base'] = ''; - if ($miscData && !empty($miscData['extraOpts'])) + if (!empty($miscData['extraOpts'])) $this->extendQueryOpts($miscData['extraOpts']); - $resolveCondition = function ($c, $supLink) use (&$resolveCondition, &$prefixes, $miscData) + if (!empty($miscData['calcTotal'])) + $calcTotal = true; + + $resolveCondition = function ($c, $supLink) use (&$resolveCondition, &$prefixes) { $subLink = ''; @@ -253,20 +259,28 @@ abstract class BaseType if ($o = array_filter(array_column($this->queryOpts, 'o'))) $this->queryBase .= ' ORDER BY '.implode(', ', $o); + // without applied LIMIT + if ($calcTotal) + $totalQuery = $this->queryBase; + // apply limit if ($limit) $this->queryBase .= ' LIMIT '.$limit; // execute query (finally) - $mtch = 0; $rows = []; // this is purely because of multiple realms per server foreach ($this->dbNames as $dbIdx => $n) { $query = str_replace('DB_IDX', $dbIdx, $this->queryBase); - if ($rows = DB::{$n}($dbIdx)->SelectPage($mtch, $query)) + if ($rows = DB::{$n}($dbIdx)->select($query)) { - $this->matches += $mtch; + if ($calcTotal) + { + $totalQuery = substr_replace($totalQuery, 'SELECT COUNT(*) ', 0, strpos($totalQuery, 'FROM')); + $this->matches += DB::{$n}($dbIdx)->selectCell($totalQuery); + } + foreach ($rows as $id => $row) { if (isset($this->templates[$id])) diff --git a/includes/community.class.php b/includes/community.class.php index aecc4d4a..01b9a44a 100644 --- a/includes/community.class.php +++ b/includes/community.class.php @@ -40,7 +40,7 @@ class CommunityContent WHERE c.`replyTo` = ?d AND c.`type` = ?d AND c.`typeId` = ?d AND ((c.`flags` & ?d) = 0 OR c.`userId` = ?d OR ?d) GROUP BY c.`id` - ORDER BY `date` ASC'; + ORDER BY c.`date` ASC'; private static string $ssQuery = 'SELECT s.`id` AS ARRAY_KEY, s.`id`, a.`displayName` AS `user`, s.`date`, s.`width`, s.`height`, s.`caption`, IF(s.`status` & ?d, 1, 0) AS "sticky", s.`type`, s.`typeId` @@ -75,8 +75,8 @@ class CommunityContent WHERE %s ((c.`flags` & ?d) = 0 OR c.`userId` = ?d OR ?d) GROUP BY c.`id` - ORDER BY `date` DESC - LIMIT ?d'; + ORDER BY c.`date` DESC + { LIMIT ?d }'; private static function addSubject(int $type, int $typeId) : void { @@ -123,9 +123,10 @@ class CommunityContent // else // pick both and no extra constraint needed for that - $comments = DB::Aowow()->selectPage( - $nFound, - sprintf(self::$previewQuery, implode(' ', $w)), + $query = sprintf(self::$previewQuery, implode(' ', $w)); + + $comments = DB::Aowow()->select( + $query, CC_FLAG_DELETED, CC_FLAG_DELETED, User::$id, @@ -133,6 +134,18 @@ class CommunityContent Cfg::get('SQL_LIMIT_DEFAULT') ); + if (!$comments) + return []; + + $nFound = DB::Aowow()->selectCell( + substr_replace($query, 'SELECT COUNT(*) ', 0, strpos($query, 'FROM')), + CC_FLAG_DELETED, + CC_FLAG_DELETED, + User::$id, + User::isInGroup(U_GROUP_COMMENTS_MODERATOR), + DBSIMPLE_SKIP + ); + foreach ($comments as $c) self::addSubject($c['type'], $c['typeId']); @@ -172,31 +185,38 @@ class CommunityContent $query = $limit > 0 ? self::$coQuery.' LIMIT '.$limit : self::$coQuery; // get replies - $results = DB::Aowow()->selectPage($nFound, $query, User::$id, RATING_COMMENT, Report::MODE_COMMENT, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); - foreach ($results as $r) + if ($results = DB::Aowow()->select($query, User::$id, RATING_COMMENT, Report::MODE_COMMENT, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR))) { - (new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals); - - $reply = array( - 'commentid' => $commentId, - 'id' => $r['id'], - 'body' => $r['body'], - 'username' => $r['user'], - 'roles' => $r['roles'], - 'creationdate' => date(Util::$dateFormatInternal, $r['date']), - 'lasteditdate' => date(Util::$dateFormatInternal, $r['editDate']), - 'rating' => (string)$r['rating'] + $nFound = DB::Aowow()->selectCell( + substr_replace(self::$coQuery, 'SELECT COUNT(*) ', 0, strpos(self::$coQuery, 'FROM')), + User::$id, RATING_COMMENT, Report::MODE_COMMENT, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR) ); - if ($r['userReported']) - $reply['reportedByUser'] = true; + foreach ($results as $r) + { + (new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals); - if ($r['userRating'] > 0) - $reply['votedByUser'] = true; - else if ($r['userRating'] < 0) - $reply['downvotedByUser'] = true; + $reply = array( + 'commentid' => $commentId, + 'id' => $r['id'], + 'body' => $r['body'], + 'username' => $r['user'], + 'roles' => $r['roles'], + 'creationdate' => date(Util::$dateFormatInternal, $r['date']), + 'lasteditdate' => date(Util::$dateFormatInternal, $r['editDate']), + 'rating' => (string)$r['rating'] + ); - $replies[] = $reply; + if ($r['userReported']) + $reply['reportedByUser'] = true; + + if ($r['userRating'] > 0) + $reply['votedByUser'] = true; + else if ($r['userRating'] < 0) + $reply['downvotedByUser'] = true; + + $replies[] = $reply; + } } return $replies; @@ -383,9 +403,9 @@ class CommunityContent return $comments; } - public static function getVideos(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0, bool $dateFmt = true) : array + public static function getVideos(int $typeOrUser = 0, int $typeId = 0, ?int &$nFound = 0, bool $dateFmt = true) : array { - $videos = DB::Aowow()->selectPage($nFound, self::$viQuery, + $videos = DB::Aowow()->select(self::$viQuery, CC_FLAG_STICKY, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, @@ -396,6 +416,21 @@ class CommunityContent !$typeOrUser ? Cfg::get('SQL_LIMIT_SEARCH') : DBSIMPLE_SKIP ); + if (!$videos) + return []; + + $nFound = DB::Aowow()->selectCell( + substr_replace(self::$viQuery, 'SELECT COUNT(*) ', 0, strpos(self::$viQuery, 'FROM')), + CC_FLAG_STICKY, + $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, + $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, + $typeOrUser > 0 ? $typeId : DBSIMPLE_SKIP, + CC_FLAG_APPROVED, + CC_FLAG_DELETED, + !$typeOrUser ? 'date' : DBSIMPLE_SKIP, + DBSIMPLE_SKIP + ); + if ($typeOrUser <= 0) // not for search by type/typeId { foreach ($videos as $v) @@ -428,9 +463,9 @@ class CommunityContent return array_values($videos); } - public static function getScreenshots(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0, bool $dateFmt = true) : array + public static function getScreenshots(int $typeOrUser = 0, int $typeId = 0, ?int &$nFound = 0, bool $dateFmt = true) : array { - $screenshots = DB::Aowow()->selectPage($nFound, self::$ssQuery, + $screenshots = DB::Aowow()->select(self::$ssQuery, CC_FLAG_STICKY, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, @@ -441,6 +476,21 @@ class CommunityContent !$typeOrUser ? Cfg::get('SQL_LIMIT_SEARCH') : DBSIMPLE_SKIP ); + if (!$screenshots) + return []; + + $nFound = DB::Aowow()->selectCell( + substr_replace(self::$ssQuery, 'SELECT COUNT(*) ', 0, strpos(self::$ssQuery, 'FROM')), + CC_FLAG_STICKY, + $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, + $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, + $typeOrUser > 0 ? $typeId : DBSIMPLE_SKIP, + CC_FLAG_APPROVED, + CC_FLAG_DELETED, + !$typeOrUser ? 'date' : DBSIMPLE_SKIP, + DBSIMPLE_SKIP + ); + if ($typeOrUser <= 0) // not for search by type/typeId { foreach ($screenshots as $s) diff --git a/includes/profiler.class.php b/includes/profiler.class.php index deb44bc4..762dc0f6 100644 --- a/includes/profiler.class.php +++ b/includes/profiler.class.php @@ -614,7 +614,7 @@ class Profiler $skAllowed = DB::Aowow()->selectCol('SELECT `id` FROM ?_skillline WHERE `typeCat` IN (9, 11) AND (`cuFlags` & ?d) = 0', CUSTOM_EXCLUDE_FOR_LISTVIEW); $skills = DB::Characters($realmId)->select('SELECT ?d AS `id`, `skill` AS `skillId`, `value`, `max` FROM character_skills WHERE `guid` = ?d AND `skill` IN (?a)', $profileId, $char['guid'], $skAllowed); - $racials = DB::Aowow()->select('SELECT `effect1MiscValue` AS ARRAY_KEY, `effect1DieSides` + `effect1BasePoints` AS qty, `reqRaceMask`, `reqClassMask` FROM ?_spell WHERE `typeCat` = -4 AND `effect1Id` = 6 AND `effect1AuraId` = 98'); + $racials = DB::Aowow()->select('SELECT `effect1MiscValue` AS ARRAY_KEY, `effect1DieSides` + `effect1BasePoints` AS qty, `reqRaceMask`, `reqClassMask` FROM ?_spell WHERE `typeCat` = -4 AND `effect1Id` = ?d AND `effect1AuraId` = ?d', SPELL_EFFECT_APPLY_AURA, SPELL_AURA_MOD_SKILL_TALENT); foreach ($skills as &$sk) // apply racial profession bonuses { @@ -644,14 +644,10 @@ class Profiler // get base values for this race/class $reputation = []; $baseRep = DB::Aowow()->selectCol( - 'SELECT `id` AS ARRAY_KEY, `baseRepValue1` FROM aowow_factions WHERE `baseRepValue1` && (`baseRepRaceMask1` & ?d || (!`baseRepRaceMask1` AND `baseRepClassMask1`)) && - ((`baseRepClassMask1` & ?d) || !`baseRepClassMask1`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue2` FROM aowow_factions WHERE `baseRepValue2` && (`baseRepRaceMask2` & ?d || (!`baseRepRaceMask2` AND `baseRepClassMask2`)) && - ((`baseRepClassMask2` & ?d) || !`baseRepClassMask2`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue3` FROM aowow_factions WHERE `baseRepValue3` && (`baseRepRaceMask3` & ?d || (!`baseRepRaceMask3` AND `baseRepClassMask3`)) && - ((`baseRepClassMask3` & ?d) || !`baseRepClassMask3`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue4` FROM aowow_factions WHERE `baseRepValue4` && (`baseRepRaceMask4` & ?d || (!`baseRepRaceMask4` AND `baseRepClassMask4`)) && - ((`baseRepClassMask4` & ?d) || !`baseRepClassMask4`)', + 'SELECT `id` AS ARRAY_KEY, `baseRepValue1` FROM aowow_factions WHERE `baseRepValue1` AND (`baseRepRaceMask1` & ?d OR (`baseRepClassMask1` AND NOT `baseRepRaceMask1`)) AND ((`baseRepClassMask1` & ?d) OR NOT `baseRepClassMask1`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue2` FROM aowow_factions WHERE `baseRepValue2` AND (`baseRepRaceMask2` & ?d OR (`baseRepClassMask2` AND NOT `baseRepRaceMask2`)) AND ((`baseRepClassMask2` & ?d) OR NOT `baseRepClassMask2`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue3` FROM aowow_factions WHERE `baseRepValue3` AND (`baseRepRaceMask3` & ?d OR (`baseRepClassMask3` AND NOT `baseRepRaceMask3`)) AND ((`baseRepClassMask3` & ?d) OR NOT `baseRepClassMask3`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue4` FROM aowow_factions WHERE `baseRepValue4` AND (`baseRepRaceMask4` & ?d OR (`baseRepClassMask4` AND NOT `baseRepRaceMask4`)) AND ((`baseRepClassMask4` & ?d) OR NOT `baseRepClassMask4`)', $ra, $cl, $ra, $cl, $ra, $cl, $ra, $cl ); @@ -760,7 +756,7 @@ class Profiler /****************/ // guilds - if ($guild = DB::Characters($realmId)->selectRow('SELECT g.name AS name, g.guildid AS id, gm.rank FROM guild_member gm JOIN guild g ON g.guildid = gm.guildid WHERE gm.guid = ?d', $char['guid'])) + if ($guild = DB::Characters($realmId)->selectRow('SELECT g.`name` AS `name`, g.`guildid` AS `id`, gm.`rank` FROM guild_member gm JOIN guild g ON g.`guildid` = gm.`guildid` WHERE gm.`guid` = ?d', $char['guid'])) { $guildId = 0; if (!($guildId = DB::Aowow()->selectCell('SELECT id FROM ?_profiler_guild WHERE realm = ?d AND realmGUID = ?d', $realmId, $guild['id']))) @@ -784,11 +780,11 @@ class Profiler // arena teams - $teams = DB::Characters($realmId)->select('SELECT at.arenaTeamId AS ARRAY_KEY, at.name, at.type, IF(at.captainGuid = atm.guid, 1, 0) AS captain, atm.* FROM arena_team at JOIN arena_team_member atm ON atm.arenaTeamId = at.arenaTeamId WHERE atm.guid = ?d', $char['guid']); + $teams = DB::Characters($realmId)->select('SELECT at.`arenaTeamId` AS ARRAY_KEY, at.`name`, at.`type`, IF(at.`captainGuid` = atm.`guid`, 1, 0) AS `captain`, atm.* FROM arena_team at JOIN arena_team_member atm ON atm.`arenaTeamId` = at.`arenaTeamId` WHERE atm.`guid` = ?d', $char['guid']); foreach ($teams as $rGuid => $t) { $teamId = 0; - if (!($teamId = DB::Aowow()->selectCell('SELECT id FROM ?_profiler_arena_team WHERE realm = ?d AND realmGUID = ?d', $realmId, $rGuid))) + if (!($teamId = DB::Aowow()->selectCell('SELECT `id` FROM ?_profiler_arena_team WHERE `realm` = ?d AND `realmGUID` = ?d', $realmId, $rGuid))) { $team = array( // only most basic data 'realm' => $realmId, @@ -832,15 +828,15 @@ class Profiler /* mark char as done */ /*********************/ - 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 cuFlags = cuFlags & ?d WHERE id = ?d', ~PROFILER_CU_NEEDS_RESYNC, $profileId); + 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 `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $profileId); return true; } public static function getGuildFromRealm($realmId, $guildGuid) { - $guild = DB::Characters($realmId)->selectRow('SELECT guildId, name, createDate, info, backgroundColor, emblemStyle, emblemColor, borderStyle, borderColor FROM guild WHERE guildId = ?d', $guildGuid); + $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; @@ -851,7 +847,7 @@ class Profiler } // 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']); + $guildId = DB::Aowow()->selectCell('SELECT `id` FROM ?_profiler_guild WHERE `realm` = ?d AND `realmGUID` = ?d', $realmId, $guild['guildId']); CLI::write('fetching guild #'.$guildGuid.' from realm #'.$realmId); CLI::write('writing...'); @@ -867,8 +863,8 @@ class Profiler DB::Aowow()->query('UPDATE ?_profiler_guild SET ?a WHERE realm = ?d AND realmGUID = ?d', $guild, $realmId, $guildGuid); // ranks - DB::Aowow()->query('DELETE FROM ?_profiler_guild_rank WHERE guildId = ?d', $guildId); - if ($ranks = DB::Characters($realmId)->select('SELECT ?d AS guildId, rid AS `rank`, rname AS name FROM guild_rank WHERE guildid = ?d', $guildId, $guildGuid)) + DB::Aowow()->query('DELETE FROM ?_profiler_guild_rank WHERE `guildId` = ?d', $guildId); + if ($ranks = DB::Characters($realmId)->select('SELECT ?d AS `guildId`, `rid` AS `rank`, `rname` AS `name` FROM guild_rank WHERE `guildid` = ?d', $guildId, $guildGuid)) foreach (Util::createSqlBatchInsert($ranks) as $r) DB::Aowow()->query('INSERT INTO ?_profiler_guild_rank (?#) VALUES '.$r, array_keys(reset($ranks))); @@ -900,14 +896,14 @@ class Profiler /* mark guild as done */ /*********************/ - DB::Aowow()->query('UPDATE ?_profiler_guild SET cuFlags = cuFlags & ?d WHERE id = ?d', ~PROFILER_CU_NEEDS_RESYNC, $guildId); + DB::Aowow()->query('UPDATE ?_profiler_guild SET `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $guildId); return true; } public static function getArenaTeamFromRealm($realmId, $teamGuid) { - $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); + $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; @@ -933,7 +929,7 @@ class Profiler unset($team['arenaTeamId']); $team['nameUrl'] = self::urlize($team['name']); - DB::Aowow()->query('UPDATE ?_profiler_arena_team SET ?a WHERE realm = ?d AND realmGUID = ?d', $team, $realmId, $teamGuid); + DB::Aowow()->query('UPDATE ?_profiler_arena_team SET ?a WHERE `realm` = ?d AND `realmGUID` = ?d', $team, $realmId, $teamGuid); CLI::write(' ..team data'); @@ -942,18 +938,14 @@ class Profiler /* Member Data */ /***************/ - $members = DB::Characters($realmId)->select(' - SELECT - atm.guid AS ARRAY_KEY, atm.arenaTeamId, atm.weekGames, atm.weekWins, atm.seasonGames, atm.seasonWins, atm.personalrating - FROM - arena_team_member atm - JOIN - characters c ON c.guid = atm.guid AND - c.deleteInfos_Account IS NULL AND - c.level <= ?d AND - (c.extra_flags & ?d) = 0 - WHERE - arenaTeamId = ?d', + $members = DB::Characters($realmId)->select( + 'SELECT atm.`guid` AS ARRAY_KEY, atm.`arenaTeamId`, atm.`weekGames`, atm.`weekWins`, atm.`seasonGames`, atm.`seasonWins`, atm.`personalrating` + FROM arena_team_member atm + JOIN characters c ON c.`guid` = atm.`guid` AND + c.`deleteInfos_Account` IS NULL AND + c.`level` <= ?d AND + (c.`extra_flags` & ?d) = 0 + WHERE `arenaTeamId` = ?d', MAX_LEVEL, self::CHAR_GMFLAGS, $teamGuid @@ -991,7 +983,7 @@ class Profiler ); // ...and purge this teams member - DB::Aowow()->query('DELETE FROM ?_profiler_arena_team_member WHERE arenaTeamId = ?d', $teamId); + DB::Aowow()->query('DELETE FROM ?_profiler_arena_team_member WHERE `arenaTeamId` = ?d', $teamId); foreach (Util::createSqlBatchInsert($members) as $m) DB::Aowow()->query('INSERT INTO ?_profiler_arena_team_member (?#) VALUES '.$m, array_keys(reset($members))); @@ -1005,7 +997,7 @@ class Profiler /* mark team as done */ /*********************/ - DB::Aowow()->query('UPDATE ?_profiler_arena_team SET cuFlags = cuFlags & ?d WHERE id = ?d', ~PROFILER_CU_NEEDS_RESYNC, $teamId); + DB::Aowow()->query('UPDATE ?_profiler_arena_team SET `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $teamId); return true; } diff --git a/includes/types/achievement.class.php b/includes/types/achievement.class.php index b9559d78..c349888f 100644 --- a/includes/types/achievement.class.php +++ b/includes/types/achievement.class.php @@ -25,7 +25,7 @@ class AchievementList extends BaseType todo: evaluate TC custom-data-tables: a*_criteria_data should be merged on installation */ - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/areatrigger.class.php b/includes/types/areatrigger.class.php index 5b309b91..8b23beef 100644 --- a/includes/types/areatrigger.class.php +++ b/includes/types/areatrigger.class.php @@ -19,9 +19,9 @@ class AreaTriggerList extends BaseType 's' => ['j' => ['?_spawns s ON s.type = 503 AND s.typeId = a.id', true], 's' => ', s.areaId'] ); - public function __construct($conditions) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); foreach ($this->iterate() as $id => &$_curTpl) if (!$_curTpl['name']) diff --git a/includes/types/arenateam.class.php b/includes/types/arenateam.class.php index 78618e75..5cdb6c3a 100644 --- a/includes/types/arenateam.class.php +++ b/includes/types/arenateam.class.php @@ -126,7 +126,7 @@ class RemoteArenaTeamList extends ArenaTeamList private $members = []; private $rankOrder = []; - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { // select DB by realm if (!$this->selectRealms($miscData)) @@ -324,7 +324,7 @@ class LocalArenaTeamList extends ArenaTeamList { protected $queryBase = 'SELECT at.*, at.id AS ARRAY_KEY FROM ?_profiler_arena_team at'; - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/charclass.class.php b/includes/types/charclass.class.php index e58ddf9b..a7ae347c 100644 --- a/includes/types/charclass.class.php +++ b/includes/types/charclass.class.php @@ -12,9 +12,9 @@ class CharClassList extends BaseType protected $queryBase = 'SELECT c.*, id AS ARRAY_KEY FROM ?_classes c'; - public function __construct($conditions = []) + public function __construct($conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); foreach ($this->iterate() as $k => &$_curTpl) $_curTpl['skills'] = explode(' ', $_curTpl['skills']); diff --git a/includes/types/creature.class.php b/includes/types/creature.class.php index 65bd9eb4..909256a1 100644 --- a/includes/types/creature.class.php +++ b/includes/types/creature.class.php @@ -24,7 +24,7 @@ class CreatureList extends BaseType 's' => ['j' => ['?_spawns s ON s.type = 1 AND s.typeId = ct.id', true]] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/currency.class.php b/includes/types/currency.class.php index e289a845..edd2d4b2 100644 --- a/includes/types/currency.class.php +++ b/includes/types/currency.class.php @@ -16,9 +16,9 @@ class CurrencyList extends BaseType 'ic' => ['j' => ['?_icons ic ON ic.id = c.iconId', true], 's' => ', ic.name AS iconString'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); foreach ($this->iterate() as &$_curTpl) $_curTpl['iconString'] = $_curTpl['iconString'] ?: DEFAULT_ICON; diff --git a/includes/types/emote.class.php b/includes/types/emote.class.php index ce0969f3..3be95cf0 100644 --- a/includes/types/emote.class.php +++ b/includes/types/emote.class.php @@ -12,9 +12,9 @@ class EmoteList extends BaseType protected $queryBase = 'SELECT e.*, e.id AS ARRAY_KEY FROM ?_emotes e'; - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as &$curTpl) diff --git a/includes/types/enchantment.class.php b/includes/types/enchantment.class.php index 126fd04f..7080ab9b 100644 --- a/includes/types/enchantment.class.php +++ b/includes/types/enchantment.class.php @@ -22,9 +22,9 @@ class EnchantmentList extends BaseType 'is' => ['j' => ['?_item_stats `is` ON `is`.`type` = 502 AND `is`.`typeId` = `ie`.`id`', true], 's' => ', `is`.*'], ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as &$curTpl) diff --git a/includes/types/faction.class.php b/includes/types/faction.class.php index 2ac9e042..492af71f 100644 --- a/includes/types/faction.class.php +++ b/includes/types/faction.class.php @@ -17,9 +17,9 @@ class FactionList extends BaseType 'ft' => ['j' => '?_factiontemplate ft ON ft.factionId = f.id'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); if ($this->error) return; diff --git a/includes/types/gameobject.class.php b/includes/types/gameobject.class.php index 5e2edc4c..4802cf26 100644 --- a/includes/types/gameobject.class.php +++ b/includes/types/gameobject.class.php @@ -21,7 +21,7 @@ class GameObjectList extends BaseType 's' => ['j' => '?_spawns s ON s.type = 2 AND s.typeId = o.id'] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/guide.class.php b/includes/types/guide.class.php index b5980b97..d183670a 100644 --- a/includes/types/guide.class.php +++ b/includes/types/guide.class.php @@ -31,9 +31,9 @@ class GuideList extends BaseType 'c' => ['j' => ['?_comments c ON c.`type` = '.Type::GUIDE.' AND c.`typeId` = g.`id` AND (c.`flags` & '.CC_FLAG_DELETED.') = 0', true], 's' => ', COUNT(c.`id`) AS `comments`'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); if ($this->error) return; diff --git a/includes/types/guild.class.php b/includes/types/guild.class.php index a24f2806..872a0541 100644 --- a/includes/types/guild.class.php +++ b/includes/types/guild.class.php @@ -161,7 +161,7 @@ class RemoteGuildList extends GuildList 'c' => ['j' => 'characters c ON c.guid = gm.guid', 's' => ', BIT_OR(IF(c.race IN (1, 3, 4, 7, 11), 1, 2)) - 1 AS faction'] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { // select DB by realm if (!$this->selectRealms($miscData)) @@ -273,7 +273,7 @@ class LocalGuildList extends GuildList { protected $queryBase = 'SELECT g.*, g.id AS ARRAY_KEY FROM ?_profiler_guild g'; - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/icon.class.php b/includes/types/icon.class.php index 538c2402..42589f55 100644 --- a/includes/types/icon.class.php +++ b/includes/types/icon.class.php @@ -34,9 +34,9 @@ class IconList extends BaseType ); */ - public function __construct($conditions) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); if (!$this->getFoundIDs()) return; diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 2adc142b..082a8613 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -35,7 +35,7 @@ class ItemList extends BaseType 'src' => ['j' => ['?_source `src` ON `src`.`type` = 3 AND `src`.`typeId` = `i`.`id`', true], 's' => ', moreType, moreTypeId, moreZoneId, moreMask, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10, src11, src12, src13, src14, src15, src16, src17, src18, src19, src20, src21, src22, src23, src24'] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); @@ -1037,15 +1037,12 @@ class ItemList extends BaseType // handle special cases where: // > itemset has items of different qualities (handled by not limiting for this in the initial query) // > itemset is virtual and multiple instances have the same itemLevel but not quality (filter below) - if ($itemset->getMatches() > 1) + foreach ($itemset->iterate() as $id => $__) { - foreach ($itemset->iterate() as $id => $__) + if ($itemset->getField('quality') == $this->curTpl['quality']) { - if ($itemset->getField('quality') == $this->curTpl['quality']) - { - $itemset->pieceToSet = array_filter($itemset->pieceToSet, function($x) use ($id) { return $id == $x; }); - break; - } + $itemset->pieceToSet = array_filter($itemset->pieceToSet, function($x) use ($id) { return $id == $x; }); + break; } } diff --git a/includes/types/itemset.class.php b/includes/types/itemset.class.php index fb1de42a..b89d55f1 100644 --- a/includes/types/itemset.class.php +++ b/includes/types/itemset.class.php @@ -22,9 +22,9 @@ class ItemsetList extends BaseType 'src' => ['j' => ['?_source src ON `src`.`typeId` = `set`.`id` AND `src`.`type` = 4', true], 's' => ', src1, src2, src3, src4, src5, src6, src7, src8, src9, src10, src11, src12, src13, src14, src15, src16, src17, src18, src19, src20, src21, src22, src23, src24'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as &$_curTpl) diff --git a/includes/types/mail.class.php b/includes/types/mail.class.php index b20fdf16..666b413e 100644 --- a/includes/types/mail.class.php +++ b/includes/types/mail.class.php @@ -13,9 +13,9 @@ class MailList extends BaseType protected $queryBase = 'SELECT m.*, m.id AS ARRAY_KEY FROM ?_mails m'; protected $queryOpts = []; - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); if ($this->error) return; diff --git a/includes/types/profile.class.php b/includes/types/profile.class.php index a11a6a13..a89214ad 100644 --- a/includes/types/profile.class.php +++ b/includes/types/profile.class.php @@ -513,7 +513,7 @@ class RemoteProfileList extends ProfileList private $rnItr = []; // rename iterator [name => nCharsWithThisName] - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { // select DB by realm if (!$this->selectRealms($miscData)) @@ -708,7 +708,7 @@ class RemoteProfileList extends ProfileList if ($baseData) { foreach (Util::createSqlBatchInsert($baseData) as $ins) - DB::Aowow()->query('INSERT INTO ?_profiler_profiles (?#) VALUES '.$ins.' ON DUPLICATE KEY UPDATE name = VALUES(name), renameItr = VALUES(renameItr)', array_keys(reset($baseData))); + DB::Aowow()->query('INSERT INTO ?_profiler_profiles (?#) VALUES '.$ins.' AS newP(`r`, `rg`, `na`, `itr`, `ra`, `cl`, `lvl`, `ge`, `g`, `gr`, `cf`) ON DUPLICATE KEY UPDATE `name` = newP.`na`, `renameItr` = newP.`itr`', array_keys(reset($baseData))); // merge back local ids $localIds = DB::Aowow()->select( @@ -737,7 +737,7 @@ class LocalProfileList extends ProfileList 'g' => ['j' => ['?_profiler_guild g ON g.id = p.guild', true], 's' => ', g.name AS guildname'] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/quest.class.php b/includes/types/quest.class.php index b0c9d39b..9566be48 100644 --- a/includes/types/quest.class.php +++ b/includes/types/quest.class.php @@ -22,7 +22,7 @@ class QuestList extends BaseType 'e' => ['j' => ['?_events e ON e.id = `q`.eventId', true], 's' => ', e.holidayId'] ); - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/includes/types/skill.class.php b/includes/types/skill.class.php index 9df43246..2c3620a5 100644 --- a/includes/types/skill.class.php +++ b/includes/types/skill.class.php @@ -16,9 +16,9 @@ class SkillList extends BaseType 'ic' => ['j' => ['?_icons ic ON ic.id = sl.iconId', true], 's' => ', ic.name AS iconString'], ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as &$_curTpl) diff --git a/includes/types/sound.class.php b/includes/types/sound.class.php index df532a70..535cb5e6 100644 --- a/includes/types/sound.class.php +++ b/includes/types/sound.class.php @@ -21,9 +21,9 @@ class SoundList extends BaseType SOUND_TYPE_MP3 => 'audio/mpeg' ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as $id => &$_curTpl) diff --git a/includes/types/spell.class.php b/includes/types/spell.class.php index ef4ef8b5..a95ef44c 100644 --- a/includes/types/spell.class.php +++ b/includes/types/spell.class.php @@ -102,9 +102,9 @@ class SpellList extends BaseType 'src' => ['j' => ['?_source src ON type = 6 AND typeId = s.id', true], 's' => ', moreType, moreTypeId, moreZoneId, moreMask, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10, src11, src12, src13, src14, src15, src16, src17, src18, src19, src20, src21, src22, src23, src24'] ); - public function __construct($conditions = [], $miscData = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); if ($this->error) return; diff --git a/includes/types/title.class.php b/includes/types/title.class.php index 6aaba73d..84a02f86 100644 --- a/includes/types/title.class.php +++ b/includes/types/title.class.php @@ -20,9 +20,9 @@ class TitleList extends BaseType 'src' => ['j' => ['?_source src ON type = 11 AND typeId = t.id', true], 's' => ', src13, moreType, moreTypeId'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // post processing foreach ($this->iterate() as $id => &$_curTpl) diff --git a/includes/types/worldevent.class.php b/includes/types/worldevent.class.php index 1c25969e..14ee4ea9 100644 --- a/includes/types/worldevent.class.php +++ b/includes/types/worldevent.class.php @@ -16,9 +16,9 @@ class WorldEventList extends BaseType 'h' => ['j' => ['?_holidays h ON e.holidayId = h.id', true], 'o' => '-e.id ASC'] ); - public function __construct($conditions = []) + public function __construct(array $conditions = [], array $miscData = []) { - parent::__construct($conditions); + parent::__construct($conditions, $miscData); // unseting elements while we iterate over the array will cause the pointer to reset $replace = []; diff --git a/includes/types/zone.class.php b/includes/types/zone.class.php index ea67a238..e8975a64 100644 --- a/includes/types/zone.class.php +++ b/includes/types/zone.class.php @@ -14,7 +14,7 @@ class ZoneList extends BaseType protected $queryBase = 'SELECT z.*, id AS ARRAY_KEY FROM ?_zones z'; - public function __construct($conditions = [], $miscData = null) + public function __construct(array $conditions = [], array $miscData = []) { parent::__construct($conditions, $miscData); diff --git a/pages/achievements.php b/pages/achievements.php index f69e40e1..27251c1d 100644 --- a/pages/achievements.php +++ b/pages/achievements.php @@ -76,7 +76,7 @@ class AchievementsPage extends GenericPage if ($fiCnd = $this->filterObj->getConditions()) $conditions[] = $fiCnd; - $acvList = new AchievementList($conditions); + $acvList = new AchievementList($conditions, ['calcTotal' => true]); if (!$acvList->getMatches()) { $category = [!empty($this->category) ? (int)end($this->category) : 0]; @@ -86,7 +86,7 @@ class AchievementsPage extends GenericPage if ($catList = DB::Aowow()->SelectCol('SELECT Id FROM ?_achievementcategory WHERE parentCat IN (?a) OR parentCat2 IN (?a) ', $category, $category)) $conditions[] = ['category', $catList]; - $acvList = new AchievementList($conditions); + $acvList = new AchievementList($conditions, ['calcTotal' => true]); } $tabData = []; diff --git a/pages/areatriggers.php b/pages/areatriggers.php index 6495668b..8214e347 100644 --- a/pages/areatriggers.php +++ b/pages/areatriggers.php @@ -49,7 +49,7 @@ class AreaTriggersPage extends GenericPage $conditions[] = $_; $tabData = []; - $trigger = new AreaTriggerList($conditions); + $trigger = new AreaTriggerList($conditions, ['calcTotal' => true]); if (!$trigger->error) { $tabData['data'] = array_values($trigger->getListviewData()); diff --git a/pages/arenateams.php b/pages/arenateams.php index 9150f85b..5e55d100 100644 --- a/pages/arenateams.php +++ b/pages/arenateams.php @@ -93,7 +93,7 @@ class ArenaTeamsPage extends GenericPage if (empty($this->filter['sz'])) $tabData['visibleCols'][] = 'size'; - $miscParams = []; + $miscParams = ['calcTotal' => true]; if ($this->realm) $miscParams['sv'] = $this->realm; if ($this->region) diff --git a/pages/enchantments.php b/pages/enchantments.php index d66a3b8e..5e18640f 100644 --- a/pages/enchantments.php +++ b/pages/enchantments.php @@ -45,7 +45,7 @@ class EnchantmentsPage extends GenericPage if ($_ = $this->filterObj->getConditions()) $conditions[] = $_; - $ench = new EnchantmentList($conditions); + $ench = new EnchantmentList($conditions, ['calcTotal' => true]); $tabData['data'] = array_values($ench->getListviewData()); $this->extendGlobalData($ench->getJSGlobals()); diff --git a/pages/faction.php b/pages/faction.php index 3cdb12b5..efd75f40 100644 --- a/pages/faction.php +++ b/pages/faction.php @@ -173,7 +173,7 @@ class FactionPage extends GenericPage /**************/ // tab: items - $items = new ItemList(array(['requiredFaction', $this->typeId])); + $items = new ItemList(array(['requiredFaction', $this->typeId]), ['calcTotal' => true]); if (!$items->error) { $this->extendGlobalData($items->getJSGlobals(GLOBALINFO_SELF)); @@ -204,7 +204,7 @@ class FactionPage extends GenericPage if ($cRep) { - $killCreatures = new CreatureList(array(['id', array_keys($cRep)])); + $killCreatures = new CreatureList(array(['id', array_keys($cRep)]), ['calcTotal' => true]); if (!$killCreatures->error) { $data = $killCreatures->getListviewData(); @@ -228,7 +228,7 @@ class FactionPage extends GenericPage // tab: members if ($_ = $this->subject->getField('templateIds')) { - $members = new CreatureList(array(['faction', $_])); + $members = new CreatureList(array(['faction', $_]), ['calcTotal' => true]); if (!$members->error) { $tabData = array( @@ -261,7 +261,7 @@ class FactionPage extends GenericPage ['AND', ['rewardFactionId5', $this->typeId], ['rewardFactionValue5', 0, '>']], 'OR' ); - $quests = new QuestList($conditions); + $quests = new QuestList($conditions, ['calcTotal' => true]); if (!$quests->error) { $this->extendGlobalData($quests->getJSGlobals(GLOBALINFO_ANY)); diff --git a/pages/guilds.php b/pages/guilds.php index 6c61e1c2..af4341f4 100644 --- a/pages/guilds.php +++ b/pages/guilds.php @@ -86,7 +86,7 @@ class GuildsPage extends GenericPage 'hiddenCols' => ['guild'], ); - $miscParams = []; + $miscParams = ['calcTotal' => true]; if ($this->realm) $miscParams['sv'] = $this->realm; if ($this->region) diff --git a/pages/icons.php b/pages/icons.php index 5e01d595..b822005b 100644 --- a/pages/icons.php +++ b/pages/icons.php @@ -44,7 +44,7 @@ class IconsPage extends GenericPage if ($_ = $this->filterObj->getConditions()) $conditions[] = $_; - $icons = new IconList($conditions); + $icons = new IconList($conditions, ['calcTotal' => true]); $tabData['data'] = array_values($icons->getListviewData()); $this->extendGlobalData($icons->getJSGlobals()); diff --git a/pages/items.php b/pages/items.php index 67b8ef5d..d6893f1d 100644 --- a/pages/items.php +++ b/pages/items.php @@ -315,7 +315,7 @@ class ItemsPage extends GenericPage $finalCnd = $conditions; } - $items = new ItemList($finalCnd, ['extraOpts' => array_merge($extraOpts, $this->filterObj->extraOpts)]); + $items = new ItemList($finalCnd, ['extraOpts' => array_merge($extraOpts, $this->filterObj->extraOpts), 'calcTotal' => true]); if ($items->error) continue; diff --git a/pages/itemsets.php b/pages/itemsets.php index 71e34170..540d6a9a 100644 --- a/pages/itemsets.php +++ b/pages/itemsets.php @@ -41,7 +41,7 @@ class ItemsetsPage extends GenericPage if ($_ = $this->filterObj->getConditions()) $conditions[] = $_; - $itemsets = new ItemsetList($conditions); + $itemsets = new ItemsetList($conditions, ['calcTotal' => true]); $this->extendGlobalData($itemsets->getJSGlobals()); // recreate form selection diff --git a/pages/npcs.php b/pages/npcs.php index d170ca71..a2feafde 100644 --- a/pages/npcs.php +++ b/pages/npcs.php @@ -52,7 +52,7 @@ class NpcsPage extends GenericPage $conditions[] = $_; // beast subtypes are selected via filter - $npcs = new CreatureList($conditions, ['extraOpts' => $this->filterObj->extraOpts]); + $npcs = new CreatureList($conditions, ['extraOpts' => $this->filterObj->extraOpts, 'calcTotal' => true]); // recreate form selection $this->filter = $this->filterObj->getForm(); diff --git a/pages/object.php b/pages/object.php index cb2c2a2a..803028a7 100644 --- a/pages/object.php +++ b/pages/object.php @@ -424,7 +424,7 @@ class ObjectPage extends GenericPage // tab: Spell Focus for if ($sfId = $this->subject->getField('spellFocusId')) { - $focusSpells = new SpellList(array(['spellFocusObject', $sfId])); + $focusSpells = new SpellList(array(['spellFocusObject', $sfId]), ['calcTotal' => true]); if (!$focusSpells->error) { $tabData = array( diff --git a/pages/objects.php b/pages/objects.php index 37a63870..7f173ac7 100644 --- a/pages/objects.php +++ b/pages/objects.php @@ -55,7 +55,7 @@ class ObjectsPage extends GenericPage $conditions[] = $_; $tabData = ['data' => []]; - $objects = new GameObjectList($conditions, ['extraOpts' => $this->filterObj->extraOpts]); + $objects = new GameObjectList($conditions, ['extraOpts' => $this->filterObj->extraOpts, 'calcTotal' => true]); if (!$objects->error) { $tabData['data'] = array_values($objects->getListviewData()); diff --git a/pages/profiles.php b/pages/profiles.php index 47c8dec4..ac829572 100644 --- a/pages/profiles.php +++ b/pages/profiles.php @@ -117,7 +117,7 @@ class ProfilesPage extends GenericPage $tabData['extraCols'] = $xc; } - $miscParams = []; + $miscParams = ['calcTotal' => true]; if ($this->realm) $miscParams['sv'] = $this->realm; if ($this->region) diff --git a/pages/quest.php b/pages/quest.php index fff446d6..bceaba9c 100644 --- a/pages/quest.php +++ b/pages/quest.php @@ -121,7 +121,7 @@ class QuestPage extends GenericPage $loremaster = new AchievementList($conditions); $this->extendGlobalData($loremaster->getJSGlobals(GLOBALINFO_SELF)); - switch ($loremaster->getMatches()) + switch (count($loremaster->getFoundIds())) { case 0: break; diff --git a/pages/quests.php b/pages/quests.php index f8068852..6ddc9431 100644 --- a/pages/quests.php +++ b/pages/quests.php @@ -47,7 +47,7 @@ class QuestsPage extends GenericPage if ($_ = $this->filterObj->getConditions()) $conditions[] = $_; - $quests = new QuestList($conditions, ['extraOpts' => $this->filterObj->extraOpts]); + $quests = new QuestList($conditions, ['extraOpts' => $this->filterObj->extraOpts, 'calcTotal' => true]); $this->extendGlobalData($quests->getJSGlobals()); diff --git a/pages/search.php b/pages/search.php index 43aa3a28..5bbdbe23 100644 --- a/pages/search.php +++ b/pages/search.php @@ -378,7 +378,7 @@ class SearchPage extends GenericPage private function _searchCharClass($cndBase) // 0 Classes: $searchMask & 0x00000001 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $classes = new CharClassList($cnd); + $classes = new CharClassList($cnd, ['calcTotal' => true]); if ($data = $classes->getListviewData()) { @@ -404,7 +404,7 @@ class SearchPage extends GenericPage private function _searchCharRace($cndBase) // 1 Races: $searchMask & 0x00000002 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $races = new CharRaceList($cnd); + $races = new CharRaceList($cnd, ['calcTotal' => true]); if ($data = $races->getListviewData()) { @@ -430,7 +430,7 @@ class SearchPage extends GenericPage private function _searchTitle($cndBase) // 2 Titles: $searchMask & 0x00000004 { $cnd = array_merge($cndBase, [$this->createLookup(['male_loc'.User::$localeId, 'female_loc'.User::$localeId])]); - $titles = new TitleList($cnd); + $titles = new TitleList($cnd, ['calcTotal' => true]); if ($data = $titles->getListviewData()) { @@ -462,7 +462,7 @@ class SearchPage extends GenericPage ['AND', $this->createLookup(['e.description']), ['e.holidayId', 0]] ) )); - $wEvents = new WorldEventList($cnd); + $wEvents = new WorldEventList($cnd, ['calcTotal' => true]); if ($data = $wEvents->getListviewData()) { @@ -489,7 +489,7 @@ class SearchPage extends GenericPage private function _searchCurrency($cndBase) // 4 Currencies $searchMask & 0x0000010 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $money = new CurrencyList($cnd); + $money = new CurrencyList($cnd, ['calcTotal' => true]); if ($data = $money->getListviewData()) { @@ -515,7 +515,7 @@ class SearchPage extends GenericPage private function _searchItemset($cndBase, &$shared) // 5 Itemsets $searchMask & 0x0000020 { $cnd = array_merge($cndBase, [is_int($this->query) ? ['id', $this->query] : $this->createLookup()]); - $sets = new ItemsetList($cnd); + $sets = new ItemsetList($cnd, ['calcTotal' => true]); if ($data = $sets->getListviewData()) { @@ -550,7 +550,7 @@ class SearchPage extends GenericPage private function _searchItem($cndBase, &$shared) // 6 Items $searchMask & 0x0000040 { - $miscData = []; + $miscData = ['calcTotal' => true]; $cndAdd = empty($this->query) ? [] : (is_int($this->query) ? ['id', $this->query] : $this->createLookup()); if (($this->searchMask & SEARCH_TYPE_JSON) && ($this->searchMask & 0x20) && !empty($shared['pcsToSet'])) @@ -630,7 +630,7 @@ class SearchPage extends GenericPage [['s.attributes0', 0x80, '&'], 0], $this->createLookup() )); - $abilities = new SpellList($cnd); + $abilities = new SpellList($cnd, ['calcTotal' => true]); if ($data = $abilities->getListviewData()) { @@ -695,7 +695,7 @@ class SearchPage extends GenericPage ['s.typeCat', [-7, -2]], $this->createLookup() )); - $talents = new SpellList($cnd); + $talents = new SpellList($cnd, ['calcTotal' => true]); if ($data = $talents->getListviewData()) { @@ -746,7 +746,7 @@ class SearchPage extends GenericPage ['s.typeCat', -13], $this->createLookup() )); - $glyphs = new SpellList($cnd); + $glyphs = new SpellList($cnd, ['calcTotal' => true]); if ($data = $glyphs->getListviewData()) { @@ -788,7 +788,7 @@ class SearchPage extends GenericPage ['s.typeCat', -11], $this->createLookup() )); - $prof = new SpellList($cnd); + $prof = new SpellList($cnd, ['calcTotal' => true]); if ($data = $prof->getListviewData()) { @@ -830,7 +830,7 @@ class SearchPage extends GenericPage ['s.typeCat', [9, 11]], $this->createLookup() )); - $prof = new SpellList($cnd); + $prof = new SpellList($cnd, ['calcTotal' => true]); if ($data = $prof->getListviewData()) { @@ -872,7 +872,7 @@ class SearchPage extends GenericPage ['s.typeCat', -6], $this->createLookup() )); - $vPets = new SpellList($cnd); + $vPets = new SpellList($cnd, ['calcTotal' => true]); if ($data = $vPets->getListviewData()) { @@ -914,7 +914,7 @@ class SearchPage extends GenericPage ['s.typeCat', -5], $this->createLookup() )); - $mounts = new SpellList($cnd); + $mounts = new SpellList($cnd, ['calcTotal' => true]); if ($data = $mounts->getListviewData()) { @@ -956,7 +956,7 @@ class SearchPage extends GenericPage [['cuFlags', NPC_CU_DIFFICULTY_DUMMY, '&'], 0], // exclude difficulty entries $this->createLookup() )); - $npcs = new CreatureList($cnd); + $npcs = new CreatureList($cnd, ['calcTotal' => true]); if ($data = $npcs->getListviewData()) { @@ -990,7 +990,7 @@ class SearchPage extends GenericPage [['flags', CUSTOM_UNAVAILABLE | CUSTOM_DISABLED, '&'], 0], $this->createLookup() )); - $quests = new QuestList($cnd); + $quests = new QuestList($cnd, ['calcTotal' => true]); if ($data = $quests->getListviewData()) { @@ -1023,7 +1023,7 @@ class SearchPage extends GenericPage [['flags', ACHIEVEMENT_FLAG_COUNTER, '&'], 0], // not a statistic $this->createLookup() )); - $acvs = new AchievementList($cnd); + $acvs = new AchievementList($cnd, ['calcTotal' => true]); if ($data = $acvs->getListviewData()) { @@ -1063,7 +1063,7 @@ class SearchPage extends GenericPage ['flags', ACHIEVEMENT_FLAG_COUNTER, '&'], // is a statistic $this->createLookup() )); - $stats = new AchievementList($cnd); + $stats = new AchievementList($cnd, ['calcTotal' => true]); if ($data = $stats->getListviewData()) { @@ -1099,7 +1099,7 @@ class SearchPage extends GenericPage private function _searchZone($cndBase) // 18 Zones $searchMask & 0x0040000 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $zones = new ZoneList($cnd); + $zones = new ZoneList($cnd, ['calcTotal' => true]); if ($data = $zones->getListviewData()) { @@ -1124,7 +1124,7 @@ class SearchPage extends GenericPage private function _searchObject($cndBase) // 19 Objects $searchMask & 0x0080000 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $objects = new GameObjectList($cnd); + $objects = new GameObjectList($cnd, ['calcTotal' => true]); if ($data = $objects->getListviewData()) { @@ -1154,7 +1154,7 @@ class SearchPage extends GenericPage private function _searchFaction($cndBase) // 20 Factions $searchMask & 0x0100000 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $factions = new FactionList($cnd); + $factions = new FactionList($cnd, ['calcTotal' => true]); if ($data = $factions->getListviewData()) { @@ -1176,7 +1176,7 @@ class SearchPage extends GenericPage private function _searchSkill($cndBase) // 21 Skills $searchMask & 0x0200000 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $skills = new SkillList($cnd); + $skills = new SkillList($cnd, ['calcTotal' => true]); if ($data = $skills->getListviewData()) { @@ -1202,7 +1202,7 @@ class SearchPage extends GenericPage private function _searchPet($cndBase) // 22 Pets $searchMask & 0x0400000 { $cnd = array_merge($cndBase, [$this->createLookup()]); - $pets = new PetList($cnd); + $pets = new PetList($cnd, ['calcTotal' => true]); if ($data = $pets->getListviewData()) { @@ -1234,7 +1234,7 @@ class SearchPage extends GenericPage ['s.typeCat', -8], $this->createLookup() )); - $npcAbilities = new SpellList($cnd); + $npcAbilities = new SpellList($cnd, ['calcTotal' => true]); if ($data = $npcAbilities->getListviewData()) { @@ -1283,7 +1283,7 @@ class SearchPage extends GenericPage ], $this->createLookup() )); - $misc = new SpellList($cnd); + $misc = new SpellList($cnd, ['calcTotal' => true]); if ($data = $misc->getListviewData()) { @@ -1322,7 +1322,7 @@ class SearchPage extends GenericPage private function _searchEmote($cndBase) // 25 Emotes $searchMask & 0x2000000 { $cnd = array_merge($cndBase, [$this->createLookup(['cmd', 'meToExt_loc'.User::$localeId, 'meToNone_loc'.User::$localeId, 'extToMe_loc'.User::$localeId, 'extToExt_loc'.User::$localeId, 'extToNone_loc'.User::$localeId])]); - $emote = new EmoteList($cnd); + $emote = new EmoteList($cnd, ['calcTotal' => true]); if ($data = $emote->getListviewData()) { @@ -1341,7 +1341,7 @@ class SearchPage extends GenericPage private function _searchEnchantment($cndBase) // 26 Enchantments $searchMask & 0x4000000 { $cnd = array_merge($cndBase, [$this->createLookup(['name_loc'.User::$localeId])]); - $enchantment = new EnchantmentList($cnd); + $enchantment = new EnchantmentList($cnd, ['calcTotal' => true]); if ($data = $enchantment->getListviewData()) { @@ -1374,7 +1374,7 @@ class SearchPage extends GenericPage private function _searchSound($cndBase) // 27 Sounds $searchMask & 0x8000000 { $cnd = array_merge($cndBase, [$this->createLookup(['name'])]); - $sounds = new SoundList($cnd); + $sounds = new SoundList($cnd, ['calcTotal' => true]); if ($data = $sounds->getListviewData()) { diff --git a/pages/sounds.php b/pages/sounds.php index 5d69b368..244d1117 100644 --- a/pages/sounds.php +++ b/pages/sounds.php @@ -48,7 +48,7 @@ class SoundsPage extends GenericPage $this->filter['query'] = $this->_get['filter']; $tabData = []; - $sounds = new SoundList($conditions); + $sounds = new SoundList($conditions, ['calcTotal' => true]); if (!$sounds->error) { $tabData['data'] = array_values($sounds->getListviewData()); diff --git a/pages/spells.php b/pages/spells.php index 92535283..632a9004 100644 --- a/pages/spells.php +++ b/pages/spells.php @@ -386,7 +386,7 @@ class SpellsPage extends GenericPage if ($_ = $this->filterObj->getConditions()) $conditions[] = $_; - $spells = new SpellList($conditions); + $spells = new SpellList($conditions, ['calcTotal' => true]); $this->extendGlobalData($spells->getJSGlobals(GLOBALINFO_SELF | GLOBALINFO_RELATED)); diff --git a/pages/zone.php b/pages/zone.php index 208acf55..cdef4f67 100644 --- a/pages/zone.php +++ b/pages/zone.php @@ -179,8 +179,8 @@ class ZonePage extends GenericPage if (!User::isInGroup(U_GROUP_STAFF)) $conditions[] = [['cuFlags', CUSTOM_EXCLUDE_FOR_LISTVIEW, '&'], 0]; - $objectSpawns = new GameObjectList($conditions); - $creatureSpawns = new CreatureList($conditions); + $objectSpawns = new GameObjectList($conditions, ['calcTotal' => true]); + $creatureSpawns = new CreatureList($conditions, ['calcTotal' => true]); $atSpawns = new AreaTriggerList($conditions); $questsLV = $rewardsLV = []; diff --git a/setup/tools/filegen/img-talentcalc.ss.php b/setup/tools/filegen/img-talentcalc.ss.php index 13b1e34e..77908825 100644 --- a/setup/tools/filegen/img-talentcalc.ss.php +++ b/setup/tools/filegen/img-talentcalc.ss.php @@ -53,7 +53,7 @@ CLISetup::registerSetup("build", new class extends SetupScript sleep(2); - $tTabs = DB::Aowow()->select('SELECT tt.creatureFamilyMask, tt.textureFile, tt.tabNumber, cc.fileString FROM dbc_talenttab tt LEFT JOIN dbc_chrclasses cc ON cc.id = (LOG(2, tt.classMask) + 1)'); + $tTabs = DB::Aowow()->select('SELECT tt.`creatureFamilyMask`, tt.`textureFile`, tt.`tabNumber`, cc.`fileString` FROM dbc_talenttab tt LEFT JOIN dbc_chrclasses cc ON cc.`id` = IF(tt.`classMask`, LOG(2, tt.`classMask`) + 1, 0)'); if (!$tTabs) { CLI::write(' - TalentTab.dbc or ChrClasses.dbc is empty...?', CLI::LOG_ERROR); diff --git a/setup/tools/sqlgen/questsstartend.ss.php b/setup/tools/sqlgen/questsstartend.ss.php index 61a43ebb..23119f36 100644 --- a/setup/tools/sqlgen/questsstartend.ss.php +++ b/setup/tools/sqlgen/questsstartend.ss.php @@ -18,16 +18,16 @@ CLISetup::registerSetup("sql", new class extends SetupScript public function generate(array $ids = []) : bool { $query['NPC'] = - 'SELECT 1 AS type, id AS typeId, quest AS questId, 1 AS method, 0 AS eventId FROM creature_queststarter UNION - SELECT 1 AS type, id AS typeId, quest AS questId, 2 AS method, 0 AS eventId FROM creature_questender UNION - SELECT 1 AS type, id AS typeId, quest AS questId, 1 AS method, eventEntry AS eventId FROM game_event_creature_quest'; + 'SELECT 1 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 1 AS `method`, 0 AS `eventId` FROM creature_queststarter UNION + SELECT 1 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 2 AS `method`, 0 AS `eventId` FROM creature_questender UNION + SELECT 1 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 1 AS `method`, `eventEntry` AS `eventId` FROM game_event_creature_quest'; $query['Object'] = - 'SELECT 2 AS type, id AS typeId, quest AS questId, 1 AS method, 0 AS eventId FROM gameobject_queststarter UNION - SELECT 2 AS type, id AS typeId, quest AS questId, 2 AS method, 0 AS eventId FROM gameobject_questender UNION - SELECT 2 AS type, id AS typeId, quest AS questId, 1 AS method, eventEntry AS eventId FROM game_event_gameobject_quest'; + 'SELECT 2 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 1 AS `method`, 0 AS `eventId` FROM gameobject_queststarter UNION + SELECT 2 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 2 AS `method`, 0 AS `eventId` FROM gameobject_questender UNION + SELECT 2 AS `type`, `id` AS `typeId`, `quest` AS `questId`, 1 AS `method`, `eventEntry` AS `eventId` FROM game_event_gameobject_quest'; - $query['Item'] = 'SELECT 3 AS type, entry AS typeId, startquest AS questId, 1 AS method, 0 AS eventId FROM item_template WHERE startquest <> 0'; + $query['Item'] = 'SELECT 3 AS `type`, `entry` AS `typeId`, `startquest` AS `questId`, 1 AS `method`, 0 AS `eventId` FROM item_template WHERE `startquest` <> 0'; DB::Aowow()->query('TRUNCATE ?_quests_startend'); @@ -37,11 +37,11 @@ CLISetup::registerSetup("sql", new class extends SetupScript $data = DB::World()->select($q); foreach ($data as $d) - DB::Aowow()->query('INSERT INTO ?_quests_startend (?#) VALUES (?a) ON DUPLICATE KEY UPDATE method = method | VALUES(method), eventId = IF(eventId = 0, VALUES(eventId), eventId)', array_keys($d), array_values($d)); + DB::Aowow()->query('INSERT INTO ?_quests_startend (?#) VALUES (?a) AS newQSE(`t`, `ti`, `qi`, `m`, `ei`) ON DUPLICATE KEY UPDATE `method` = `method` | newQSE.`m`, `eventId` = IF(`eventId` = 0, newQSE.`ei`, `eventId`)', array_keys($d), array_values($d)); } // update quests without start as unavailable - Db::Aowow()->query('UPDATE ?_quests q LEFT JOIN ?_quests_startend qse ON qse.questId = q.id AND qse.method & 1 SET q.cuFlags = q.cuFlags | ?d WHERE qse.questId IS NULL', CUSTOM_UNAVAILABLE); + Db::Aowow()->query('UPDATE ?_quests q LEFT JOIN ?_quests_startend qse ON qse.`questId` = q.`id` AND qse.`method` & 1 SET q.`cuFlags` = q.`cuFlags` | ?d WHERE qse.`questId` IS NULL', CUSTOM_UNAVAILABLE); return true; } diff --git a/setup/tools/sqlgen/source.ss.php b/setup/tools/sqlgen/source.ss.php index ea027f6c..7e166633 100644 --- a/setup/tools/sqlgen/source.ss.php +++ b/setup/tools/sqlgen/source.ss.php @@ -434,17 +434,17 @@ CLISetup::registerSetup("sql", new class extends SetupScript $quests = DB::World()->select( 'SELECT n.`item` AS ARRAY_KEY, n.`Id` AS `quest`, SUM(n.`qty`) AS `qty`, BIT_OR(n.`side`) AS `side`, IF(COUNT(DISTINCT `zone`) > 1, 0, `zone`) AS `zone`, it.`class`, it.`subclass`, it.`spellid_1`, it.`spelltrigger_1`, it.`spellid_2`, it.`spelltrigger_2` - FROM (SELECT `RewardChoiceItemID1` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID1` > 0 GROUP BY `item` UNION - SELECT `RewardChoiceItemID2` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID2` > 0 GROUP BY `item` UNION - SELECT `RewardChoiceItemID3` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID3` > 0 GROUP BY `item` UNION - SELECT `RewardChoiceItemID4` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID4` > 0 GROUP BY `item` UNION - SELECT `RewardChoiceItemID5` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID5` > 0 GROUP BY `item` UNION - SELECT `RewardChoiceItemID6` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID6` > 0 GROUP BY `item` UNION - SELECT `RewardItem1` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem1` > 0 GROUP BY `item` UNION - SELECT `RewardItem2` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem2` > 0 GROUP BY `item` UNION - SELECT `RewardItem3` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem3` > 0 GROUP BY `item` UNION - SELECT `RewardItem4` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem4` > 0 GROUP BY `item` UNION - SELECT `StartItem` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `StartItem` > 0 GROUP BY `item`) n + FROM (SELECT `RewardChoiceItemID1` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID1` > 0 GROUP BY `item` UNION + SELECT `RewardChoiceItemID2` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID2` > 0 GROUP BY `item` UNION + SELECT `RewardChoiceItemID3` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID3` > 0 GROUP BY `item` UNION + SELECT `RewardChoiceItemID4` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID4` > 0 GROUP BY `item` UNION + SELECT `RewardChoiceItemID5` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID5` > 0 GROUP BY `item` UNION + SELECT `RewardChoiceItemID6` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardChoiceItemID6` > 0 GROUP BY `item` UNION + SELECT `RewardItem1` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem1` > 0 GROUP BY `item` UNION + SELECT `RewardItem2` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem2` > 0 GROUP BY `item` UNION + SELECT `RewardItem3` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem3` > 0 GROUP BY `item` UNION + SELECT `RewardItem4` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `RewardItem4` > 0 GROUP BY `item` UNION + SELECT `StartItem` AS `item`, `ID`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone` FROM quest_template WHERE `StartItem` > 0 GROUP BY `item`) n JOIN item_template it ON it.`entry` = n.`item` GROUP BY `item`', RACE_MASK_HORDE, RACE_MASK_ALLIANCE, SIDE_HORDE, RACE_MASK_ALLIANCE, RACE_MASK_HORDE, SIDE_ALLIANCE, SIDE_BOTH, @@ -473,7 +473,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript } $mailLoot = DB::World()->select( - 'SELECT IF(mlt.`Reference` > 0, -mlt.`Reference`, mlt.`Item`) AS ARRAY_KEY, qt.`Id` AS `entry`, it.`class`, it.`subclass`, it.`spellid_1`, it.`spelltrigger_1`, it.`spellid_2`, it.`spelltrigger_2`, COUNT(1) AS `qty`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone`, BIT_OR(IF(qt.`AllowableRaces` & ?d AND !(qt.`AllowableRaces` & ?d), ?d, IF(qt.`AllowableRaces` & ?d AND !(qt.`AllowableRaces` & ?d), ?d, ?d))) AS `side` + 'SELECT IF(mlt.`Reference` > 0, -mlt.`Reference`, mlt.`Item`) AS ARRAY_KEY, qt.`Id` AS `entry`, it.`class`, it.`subclass`, it.`spellid_1`, it.`spelltrigger_1`, it.`spellid_2`, it.`spelltrigger_2`, COUNT(1) AS `qty`, IF(COUNT(DISTINCT `QuestSortID`) > 1, 0, GREATEST(`QuestSortID`, 0)) AS `zone`, BIT_OR(IF(qt.`AllowableRaces` & ?d AND NOT (qt.`AllowableRaces` & ?d), ?d, IF(qt.`AllowableRaces` & ?d AND NOT (qt.`AllowableRaces` & ?d), ?d, ?d))) AS `side` FROM mail_loot_template mlt JOIN quest_template_addon qta ON qta.`RewardMailTemplateId` = mlt.`entry` JOIN quest_template qt ON qt.`ID` = qta.`ID` @@ -1009,8 +1009,8 @@ CLISetup::registerSetup("sql", new class extends SetupScript $quests = DB::World()->select( 'SELECT `spell` AS ARRAY_KEY, `id`, SUM(`qty`) AS `qty`, BIT_OR(`side`) AS `side`, IF(COUNT(DISTINCT `zone`) > 1, 0, `zone`) AS `zone` - FROM (SELECT IF(`RewardSpell` = 0, `RewardDisplaySpell`, `RewardSpell`) AS `spell`, `Id`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template WHERE IF(`RewardSpell` = 0, `RewardDisplaySpell`, `RewardSpell`) > 0 GROUP BY `spell` UNION - SELECT qta.`SourceSpellId` AS `spell`, qt.`Id`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template qt JOIN quest_template_addon qta ON qta.ID = qt.ID WHERE qta.`SourceSpellId` > 0 GROUP BY `spell`) t + FROM (SELECT IF(`RewardSpell` = 0, `RewardDisplaySpell`, `RewardSpell`) AS `spell`, `Id`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template WHERE IF(`RewardSpell` = 0, `RewardDisplaySpell`, `RewardSpell`) > 0 GROUP BY `spell` UNION + SELECT qta.`SourceSpellId` AS `spell`, qt.`Id`, COUNT(1) AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template qt JOIN quest_template_addon qta ON qta.ID = qt.ID WHERE qta.`SourceSpellId` > 0 GROUP BY `spell`) t GROUP BY `spell`', RACE_MASK_HORDE, RACE_MASK_ALLIANCE, SIDE_HORDE, RACE_MASK_ALLIANCE, RACE_MASK_HORDE, SIDE_ALLIANCE, SIDE_BOTH, RACE_MASK_HORDE, RACE_MASK_ALLIANCE, SIDE_HORDE, RACE_MASK_ALLIANCE, RACE_MASK_HORDE, SIDE_ALLIANCE, SIDE_BOTH @@ -1140,7 +1140,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript $quests = DB::World()->select( 'SELECT `RewardTitle` AS ARRAY_KEY, `ID` AS `id`, SUM(`qty`) AS `qty`, BIT_OR(`side`) AS `side`, IF(COUNT(DISTINCT `zone`) > 1, 0, `zone`) AS `zone` - FROM (SELECT `RewardTitle`, `ID`, 1 AS `qty`, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND !(`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template WHERE `RewardTitle` > 0) q + FROM (SELECT `RewardTitle`, `ID`, 1 AS `qty`, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, IF(`AllowableRaces` & ?d AND NOT (`AllowableRaces` & ?d), ?d, ?d)) AS `side`, GREATEST(`QuestSortID`, 0) AS `zone` FROM quest_template WHERE `RewardTitle` > 0) q GROUP BY `RewardTitle`', RACE_MASK_HORDE, RACE_MASK_ALLIANCE, SIDE_HORDE, RACE_MASK_ALLIANCE, RACE_MASK_HORDE, SIDE_ALLIANCE, SIDE_BOTH );