From: Matthias Schmidt Date: Sun, 17 Jul 2016 17:56:30 +0000 (+0200) Subject: Add `PreparedStatement::fetchMap()` method X-Git-Tag: 3.0.0_Beta_1~1063 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0557bb04a62a11d773b48e0d77165101dce4da00;p=GitHub%2FWoltLab%2FWCF.git Add `PreparedStatement::fetchMap()` method --- diff --git a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php index a06387b852..3076c7eeaf 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php @@ -497,9 +497,7 @@ class StyleAddForm extends AbstractForm { FROM wcf".WCF_N."_style_variable"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - while ($row = $statement->fetchArray()) { - $this->variables[$row['variableName']] = $row['defaultValue']; - } + $this->variables = $statement->fetchMap('variableName', 'defaultValue'); } /** diff --git a/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php b/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php index 219a9e5cd1..cb39ac8580 100755 --- a/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php @@ -126,11 +126,7 @@ class UserAssignToGroupForm extends AbstractForm { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $groups = []; - while ($row = $statement->fetchArray()) { - $groups[$row['userID']][] = $row['groupID']; - } + $groups = $statement->fetchMap('userID', 'groupID', false); foreach ($this->users as $user) { if (!UserGroup::isAccessibleGroup($groups[$user->userID])) { diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php index 90938988b1..64d30ab06a 100644 --- a/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php @@ -207,9 +207,7 @@ class UserGroupOptionForm extends AbstractForm { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $this->values[$row['groupID']] = $row['optionValue']; - } + $this->values = $statement->fetchMap('groupID', 'optionValue'); } // create form elements for each group diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index 73fca7e944..3cddaddc7a 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -243,8 +243,6 @@ class UserListPage extends SortablePage { // get user data if (!empty($userIDs)) { - $userToGroups = []; - // get group ids $conditions = new PreparedStatementConditionBuilder(); $conditions->add("user_table.userID IN (?)", [$userIDs]); @@ -254,9 +252,7 @@ class UserListPage extends SortablePage { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $userToGroups[$row['userID']][] = $row['groupID']; - } + $userToGroups = $statement->fetchMap('userID', 'groupID', false); $sql = "SELECT user_avatar.*, option_value.*, user_table.* FROM wcf".WCF_N."_user user_table diff --git a/wcfsetup/install/files/lib/data/comment/response/LikeableCommentResponseProvider.class.php b/wcfsetup/install/files/lib/data/comment/response/LikeableCommentResponseProvider.class.php index 046caa3b99..910bf0664a 100644 --- a/wcfsetup/install/files/lib/data/comment/response/LikeableCommentResponseProvider.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/LikeableCommentResponseProvider.class.php @@ -62,7 +62,6 @@ class LikeableCommentResponseProvider extends AbstractObjectTypeProvider impleme } // get objects type ids - $responses = []; $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('comment_response.responseID IN (?)', [$responseIDs]); $sql = "SELECT comment.objectTypeID, comment_response.responseID @@ -72,9 +71,7 @@ class LikeableCommentResponseProvider extends AbstractObjectTypeProvider impleme ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - while ($row = $statement->fetchArray()) { - $responses[$row['responseID']] = $row['objectTypeID']; - } + $responses = $statement->fetchMap('responseID', 'objectTypeID'); // group likes by object type id $likeData = []; diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 70b7d4d1d9..6b94b8e14e 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -42,10 +42,7 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject FROM wcf".WCF_N."_option"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $optionIDs = []; - while ($row = $statement->fetchArray()) { - $optionIDs[$row['optionName']] = $row['optionID']; - } + $optionIDs = $statement->fetchMap('optionName', 'optionID'); $newOptions = []; foreach ($options as $name => $value) { diff --git a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php index 5fcbe76bce..c70b8952c5 100644 --- a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php +++ b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php @@ -150,10 +150,7 @@ class PackageUpdateAction extends AbstractDatabaseObjectAction { FROM wcf".WCF_N."_package"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $installedPackages = []; - while ($row = $statement->fetchArray()) { - $installedPackages[$row['package']] = $row['packageVersion']; - } + $installedPackages = $statement->fetchMap('package', 'packageVersion'); // filter by version $conditions = new PreparedStatementConditionBuilder(); diff --git a/wcfsetup/install/files/lib/data/poll/PollAction.class.php b/wcfsetup/install/files/lib/data/poll/PollAction.class.php index 15cfe22264..cd2710b175 100644 --- a/wcfsetup/install/files/lib/data/poll/PollAction.class.php +++ b/wcfsetup/install/files/lib/data/poll/PollAction.class.php @@ -281,14 +281,7 @@ class PollAction extends AbstractDatabaseObjectAction implements IGroupedUserLis WHERE pollID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->poll->pollID]); - $voteData = []; - while ($row = $statement->fetchArray()) { - if (!isset($voteData[$row['optionID']])) { - $voteData[$row['optionID']] = []; - } - - $voteData[$row['optionID']][] = $row['userID']; - } + $voteData = $statement->fetchMap('optionID', 'userID', false); // assign user ids foreach ($voteData as $optionID => $userIDs) { diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index 46ad6e6056..0e0b6c8d13 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -633,10 +633,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject WHERE language_item.languageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->styleDescription]); - $styleDescriptions = []; - while ($row = $statement->fetchArray()) { - $styleDescriptions[$row['languageCode']] = $row['languageItemValue']; - } + $styleDescriptions = $statement->fetchMap('languageCode', 'languageItemValue'); // create style info file $xml = new XMLWriter(); diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php index ebf479c43f..0676369ea0 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php @@ -351,16 +351,13 @@ class UserGroup extends DatabaseObject implements ITitledObject { public function getGroupOption($name) { if ($this->groupOptions === null) { // get all options and filter options with low priority - $this->groupOptions = $groupOptionIDs = []; + $this->groupOptions = []; $sql = "SELECT optionName, optionID FROM wcf".WCF_N."_user_group_option"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - - while ($row = $statement->fetchArray()) { - $groupOptionIDs[$row['optionName']] = $row['optionID']; - } + $groupOptionIDs = $statement->fetchMap('optionName', 'optionID'); if (!empty($groupOptionIDs)) { $conditions = new PreparedStatementConditionBuilder(); @@ -374,9 +371,7 @@ class UserGroup extends DatabaseObject implements ITitledObject { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $this->groupOptions[$row['optionName']] = $row['optionValue']; - } + $this->groupOptions = $statement->fetchMap('optionName', 'optionValue'); } } diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php index 6c3bd6c943..105b3fff80 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php @@ -118,10 +118,7 @@ class UserGroupAction extends AbstractDatabaseObjectAction { $statement->execute(); } - $optionValues = []; - while ($row = $statement->fetchArray()) { - $optionValues[$row['optionID']] = $row['optionValue']; - } + $optionValues = $statement->fetchMap('optionID', 'optionValue'); $groupAction = new UserGroupAction([], 'create', [ 'data' => [ diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index d453edcc65..6871c272c1 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -1127,10 +1127,7 @@ class WCFSetup extends WCF { FROM wcf".WCF_N."_package_installation_queue"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $queues = []; - while ($row = $statement->fetchArray()) { - $queues[$row['queueID']] = $row['parentQueueID']; - } + $queues = $statement->fetchMap('queueID', 'parentQueueID'); $queueIDs = []; /** @noinspection PhpUndefinedVariableInspection */ diff --git a/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php b/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php index b1d80e2d76..a1160d628a 100644 --- a/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php +++ b/wcfsetup/install/files/lib/system/acl/ACLHandler.class.php @@ -351,10 +351,7 @@ class ACLHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - while ($row = $statement->fetchArray()) { - $data['user']['label'][$row['userID']] = $row['username']; - } + $data['user']['label'] = $statement->fetchMap('userID', 'username'); } } } diff --git a/wcfsetup/install/files/lib/system/bulk/processing/user/AbstractUserBulkProcessingAction.class.php b/wcfsetup/install/files/lib/system/bulk/processing/user/AbstractUserBulkProcessingAction.class.php index c617ab64cf..381517f00f 100644 --- a/wcfsetup/install/files/lib/system/bulk/processing/user/AbstractUserBulkProcessingAction.class.php +++ b/wcfsetup/install/files/lib/system/bulk/processing/user/AbstractUserBulkProcessingAction.class.php @@ -41,15 +41,7 @@ abstract class AbstractUserBulkProcessingAction extends AbstractBulkProcessingAc ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - - $groupIDs = []; - while ($row = $statement->fetchArray()) { - if (!isset($groupIDs[$row['userID']])) { - $groupIDs[$row['userID']] = []; - } - - $groupIDs[$row['userID']][] = $row['groupID']; - } + $groupIDs = $statement->fetchMap('userID', 'groupID', false); $users = []; foreach ($userList as $user) { diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php index 3703b19848..0992fa5ca7 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php @@ -20,15 +20,6 @@ class ClipboardPageCacheBuilder extends AbstractCacheBuilder { $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $data = []; - while ($row = $statement->fetchArray()) { - if (!isset($data[$row['pageClassName']])) { - $data[$row['pageClassName']] = []; - } - - $data[$row['pageClassName']][] = $row['actionID']; - } - - return $data; + return $statement->fetchMap('pageClassName', 'actionID', false); } } diff --git a/wcfsetup/install/files/lib/system/cache/builder/TagCloudCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/TagCloudCacheBuilder.class.php index 67855b992f..cd2ab33931 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/TagCloudCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/TagCloudCacheBuilder.class.php @@ -80,7 +80,6 @@ class TagCloudCacheBuilder extends AbstractCacheBuilder { if (!empty($this->objectTypeIDs)) { // get tag ids - $tagIDs = []; $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('object.objectTypeID IN (?)', [$this->objectTypeIDs]); $conditionBuilder->add('object.languageID IN (?)', [$this->languageIDs]); @@ -91,9 +90,7 @@ class TagCloudCacheBuilder extends AbstractCacheBuilder { ORDER BY counter DESC"; $statement = WCF::getDB()->prepareStatement($sql, 500); $statement->execute($conditionBuilder->getParameters()); - while ($row = $statement->fetchArray()) { - $tagIDs[$row['tagID']] = $row['counter']; - } + $tagIDs = $statement->fetchMap('tagID', 'counter'); // get tags if (!empty($tagIDs)) { diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index d4e42ac9ba..32725f05f0 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -141,14 +141,7 @@ class UserClipboardAction extends AbstractClipboardAction { $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $userToGroup = []; - while ($row = $statement->fetchArray()) { - if (!isset($userToGroup[$row['userID']])) { - $userToGroup[$row['userID']] = []; - } - - $userToGroup[$row['userID']][] = $row['groupID']; - } + $userToGroup = $statement->fetchMap('userID', 'groupID', false); // validate if user's group is accessible for current user foreach ($userIDs as $userID) { diff --git a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php index ade6ffac60..d0d2f70474 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -185,6 +185,36 @@ class PreparedStatement { return $objects; } + /** + * Returns a map of all fetched rows using one column as key and another column as value. + * + * @param string $keyColumn name of the key column + * @param string $valueColumn name of the value column + * @param boolean $uniqueKey if `true`, a one-dimensional array is returned, otherwise, for each key an array of fetched values is returned + * @return string[]|string[][] + */ + public function fetchMap($keyColumn, $valueColumn, $uniqueKey = true) { + $map = []; + + while (($row = $this->fetchArray())) { + $key = $row[$keyColumn]; + $value = $row[$valueColumn]; + + if ($uniqueKey) { + $map[$key] = $value; + } + else { + if (!isset($map[$key])) { + $map[$key] = []; + } + + $map[$key][] = $value; + } + } + + return $map; + } + /** * Counts number of affected rows by the last sql statement (INSERT, UPDATE or DELETE). * diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php index 3052c16d24..818fc04f4a 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTextParser.class.php @@ -236,11 +236,7 @@ class HtmlInputNodeTextParser { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $users = []; - while ($row = $statement->fetchArray()) { - $users[$row['userID']] = $row['username']; - } + $users = $statement->fetchMap('userID', 'username'); // sort usernames with the longest one being first uasort($users, function($a, $b) { diff --git a/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php index 688ffacff9..3e5a32552c 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractACLImporter.class.php @@ -39,9 +39,7 @@ class AbstractACLImporter extends AbstractImporter { WHERE objectTypeID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->objectTypeID]); - while ($row = $statement->fetchArray()) { - $this->options[$row['optionName']] = $row['optionID']; - } + $this->options = $statement->fetchMap('optionName', 'optionID'); } /** diff --git a/wcfsetup/install/files/lib/system/label/LabelHandler.class.php b/wcfsetup/install/files/lib/system/label/LabelHandler.class.php index 957884271d..bef973e676 100644 --- a/wcfsetup/install/files/lib/system/label/LabelHandler.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelHandler.class.php @@ -210,15 +210,7 @@ class LabelHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $labels = []; - while ($row = $statement->fetchArray()) { - if (!isset($labels[$row['labelID']])) { - $labels[$row['labelID']] = []; - } - - $labels[$row['labelID']][] = $row['objectID']; - } + $labels = $statement->fetchMap('labelID', 'objectID', false); // optionally filter out labels without permissions if ($validatePermissions) { diff --git a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php index 51e1ee21aa..e9a90dccaf 100644 --- a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php +++ b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php @@ -284,10 +284,7 @@ class I18nHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $languageItemIDs = []; - while ($row = $statement->fetchArray()) { - $languageItemIDs[$row['languageID']] = $row['languageItemID']; - } + $languageItemIDs = $statement->fetchMap('languageID', 'languageItemID'); $insertLanguageIDs = $updateLanguageIDs = []; foreach ($languageIDs as $languageID) { diff --git a/wcfsetup/install/files/lib/system/package/ACPTemplatesFileHandler.class.php b/wcfsetup/install/files/lib/system/package/ACPTemplatesFileHandler.class.php index 678bf555c5..a62f3aecd9 100644 --- a/wcfsetup/install/files/lib/system/package/ACPTemplatesFileHandler.class.php +++ b/wcfsetup/install/files/lib/system/package/ACPTemplatesFileHandler.class.php @@ -52,11 +52,7 @@ class ACPTemplatesFileHandler extends PackageInstallationFileHandler { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $lockedFiles = []; - while ($row = $statement->fetchArray()) { - $lockedFiles[$row['templateName']] = $row['packageID']; - } + $lockedFiles = $statement->fetchMap('templateName', 'packageID'); // check if acp templates from the package beeing // installed are in conflict with already installed diff --git a/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php b/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php index 86f9d44e39..dab7686603 100644 --- a/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php +++ b/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php @@ -32,10 +32,7 @@ class FilesFileHandler extends PackageInstallationFileHandler { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $lockedFiles = []; - while ($row = $statement->fetchArray()) { - $lockedFiles[$row['filename']] = $row['packageID']; - } + $lockedFiles = $statement->fetchMap('filename', 'packageID'); // check delivered files if (!empty($lockedFiles)) { diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php index a7acbc1f43..7397993940 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationSQLParser.class.php @@ -199,9 +199,7 @@ class PackageInstallationSQLParser extends SQLParser { AND sqlIndex = ''"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - while ($row = $statement->fetchArray()) { - $this->knownTables[$row['sqlTable']] = $row['packageID']; - } + $this->knownTables = $statement->fetchMap('sqlTable', 'packageID'); } /** diff --git a/wcfsetup/install/files/lib/system/package/TemplatesFileHandler.class.php b/wcfsetup/install/files/lib/system/package/TemplatesFileHandler.class.php index aa17970c53..8503bddca5 100644 --- a/wcfsetup/install/files/lib/system/package/TemplatesFileHandler.class.php +++ b/wcfsetup/install/files/lib/system/package/TemplatesFileHandler.class.php @@ -35,7 +35,7 @@ class TemplatesFileHandler extends ACPTemplatesFileHandler { unset($file); // get existing templates - $existingTemplates = $updateTemplateIDs = []; + $updateTemplateIDs = []; $sql = "SELECT templateName, templateID FROM wcf".WCF_N."_template WHERE packageID = ? @@ -43,9 +43,7 @@ class TemplatesFileHandler extends ACPTemplatesFileHandler { AND templateGroupID IS NULL"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$packageID, $this->application]); - while ($row = $statement->fetchArray()) { - $existingTemplates[$row['templateName']] = $row['templateID']; - } + $existingTemplates = $statement->fetchMap('templateName', 'templateID'); // save new templates $sql = "INSERT INTO wcf".WCF_N."_template diff --git a/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php index 49ba49bfe7..51e5f1d1e3 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php @@ -88,15 +88,7 @@ class FilePackageInstallationPlugin extends AbstractPackageInstallationPlugin { WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->installation->getPackageID()]); - - $files = []; - while ($row = $statement->fetchArray()) { - if (!isset($files[$row['application']])) { - $files[$row['application']] = []; - } - - $files[$row['application']][] = $row['filename']; - } + $files = $statement->fetchMap('application', 'filename', false); foreach ($files as $application => $filenames) { /** @noinspection PhpUndefinedMethodInspection */ diff --git a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php index b4c05ceabb..e68142d734 100644 --- a/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php @@ -41,10 +41,7 @@ class MenuItemACPSearchResultProvider extends AbstractACPSearchResultProvider im ORDER BY languageItemValue ASC"; $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here $statement->execute($conditions->getParameters()); - $languageItems = []; - while ($row = $statement->fetchArray()) { - $languageItems[$row['languageItem']] = $row['languageItemValue']; - } + $languageItems = $statement->fetchMap('languageItem', 'languageItemValue'); if (empty($languageItems)) { return []; diff --git a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php index acd49aaa45..03d58838d0 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -133,10 +133,7 @@ class UserNotificationHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $notifications = []; - while ($row = $statement->fetchArray()) { - $notifications[$row['userID']] = $row['notificationID']; - } + $notifications = $statement->fetchMap('userID', 'notificationID'); // check if event supports stacking and author should be added if (!empty($notifications) && $event->isStackable()) { diff --git a/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php b/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php index 0c44b4c5f8..b0592d5cfc 100644 --- a/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php +++ b/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php @@ -71,15 +71,12 @@ class VisitTracker extends SingletonFactory { // cache does not exist or is outdated if ($data === null) { - $this->userVisits = []; $sql = "SELECT objectTypeID, visitTime FROM wcf".WCF_N."_tracked_visit_type WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([WCF::getUser()->userID]); - while ($row = $statement->fetchArray()) { - $this->userVisits[$row['objectTypeID']] = $row['visitTime']; - } + $this->userVisits = $statement->fetchMap('objectTypeID', 'visitTime'); // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'trackedUserVisits', serialize($this->userVisits)); diff --git a/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php index 681ae73450..40e5d86f70 100644 --- a/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php @@ -86,12 +86,7 @@ class ArticleRebuildDataWorker extends AbstractRebuildDataWorker { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $cumulativeLikes = []; - - /** @noinspection PhpAssignmentInConditionInspection */ - while ($row = $statement->fetchArray()) { - $cumulativeLikes[$row['objectID']] = $row['cumulativeLikes']; - } + $cumulativeLikes = $statement->fetchMap('objectID', 'cumulativeLikes'); foreach ($this->objectList as $article) { $editor = new ArticleEditor($article); diff --git a/wcfsetup/install/files/lib/system/worker/LikeUserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/LikeUserRebuildDataWorker.class.php index 52f804e544..4c598280ff 100644 --- a/wcfsetup/install/files/lib/system/worker/LikeUserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/LikeUserRebuildDataWorker.class.php @@ -81,10 +81,7 @@ class LikeUserRebuildDataWorker extends AbstractRebuildDataWorker { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $usernames = []; - while ($row = $statement->fetchArray()) { - $usernames[$row['userID']] = $row['username']; - } + $usernames = $statement->fetchMap('userID', 'username'); // update like objects $sql = "UPDATE wcf".WCF_N."_like_object