From: Matthias Schmidt Date: Sat, 7 May 2016 20:38:01 +0000 (+0200) Subject: Add PreparedStatement::fetchColumns() X-Git-Tag: 3.0.0_Beta_1~1749 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0e41dd997c049c3e087f59cb7af9f8ba97a6746a;p=GitHub%2FWoltLab%2FWCF.git Add PreparedStatement::fetchColumns() --- diff --git a/wcfsetup/install/files/lib/acp/action/UserQuickSearchAction.class.php b/wcfsetup/install/files/lib/acp/action/UserQuickSearchAction.class.php index 5bed3552b7..effab7b639 100644 --- a/wcfsetup/install/files/lib/acp/action/UserQuickSearchAction.class.php +++ b/wcfsetup/install/files/lib/acp/action/UserQuickSearchAction.class.php @@ -97,9 +97,7 @@ class UserQuickSearchAction extends AbstractAction { WHERE banned = ?"; $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); break; case 'newest': @@ -113,9 +111,7 @@ class UserQuickSearchAction extends AbstractAction { ORDER BY user_table.registrationDate DESC"; $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute(); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); break; case 'disabled': @@ -129,9 +125,7 @@ class UserQuickSearchAction extends AbstractAction { ORDER BY user_table.registrationDate DESC"; $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute(array(0)); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); break; case 'disabledAvatars': @@ -142,9 +136,7 @@ class UserQuickSearchAction extends AbstractAction { WHERE disableAvatar = ?"; $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); break; case 'disabledSignatures': @@ -155,9 +147,7 @@ class UserQuickSearchAction extends AbstractAction { WHERE disableSignature = ?"; $statement = WCF::getDB()->prepareStatement($sql, $this->maxResults); $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); break; } diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index 7d3f6f57fb..f861b04d47 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -317,10 +317,7 @@ class BoxAddForm extends AbstractForm { " . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $this->pageIDs = []; - while ($row = $statement->fetchArray()) { - $this->pageIDs[] = $row['pageID']; - } + $this->pageIDs = $statement->fetchColumns(); } // validate images diff --git a/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php b/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php index 68e9c3ad35..6c94b85c8d 100644 --- a/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/MenuAddForm.class.php @@ -132,10 +132,7 @@ class MenuAddForm extends AbstractForm { " . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $this->pageIDs = []; - while ($row = $statement->fetchArray()) { - $this->pageIDs[] = $row['pageID']; - } + $this->pageIDs = $statement->fetchColumns(); } } diff --git a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php index 437b5c3caa..ca1002f98d 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php @@ -336,10 +336,7 @@ class StyleAddForm extends AbstractForm { FROM wcf".WCF_N."_style_variable"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $variables = []; - while ($row = $statement->fetchArray()) { - $variables[] = $row['variableName']; - } + $variables = $statement->fetchColumns(); $lines = explode("\n", StringUtil::unifyNewlines($this->variables['overrideScss'])); $regEx = new Regex('^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\.\(\)\%\#-]+);$'); diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index ff52bf4830..2beb0b4f5a 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -233,7 +233,6 @@ class UserListPage extends SortablePage { */ protected function readUsers() { // get user ids - $userIDs = []; $sql = "SELECT user_table.userID FROM wcf".WCF_N."_user user_table ".(isset($this->options[$this->sortField]) ? "LEFT JOIN wcf".WCF_N."_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)" : '')." @@ -241,9 +240,7 @@ class UserListPage extends SortablePage { ORDER BY ".(($this->sortField != 'email' && isset($this->options[$this->sortField])) ? 'user_option_value.userOption'.$this->options[$this->sortField]->optionID : $this->sortField)." ".$this->sortOrder; $statement = WCF::getDB()->prepareStatement($sql, $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage); $statement->execute($this->conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); // get user data if (!empty($userIDs)) { diff --git a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php index 104e343885..1bef8c9893 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php @@ -165,9 +165,7 @@ abstract class DatabaseObjectList implements \Countable, ITraversableObject { ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : ''); $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset); $statement->execute($this->getConditionBuilder()->getParameters()); - while ($row = $statement->fetchArray()) { - $this->objectIDs[] = $row['objectID']; - } + $this->objectIDs = $statement->fetchColumns(); } /** diff --git a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php index d3d4d67622..171e0713fc 100644 --- a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php +++ b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php @@ -245,7 +245,6 @@ class AttachmentAction extends AbstractDatabaseObjectAction implements ISortable $this->parameters['attachmentIDs'] = ArrayUtil::toIntegerArray($this->parameters['attachmentIDs']); // check attachment ids - $attachmentIDs = []; $conditions = new PreparedStatementConditionBuilder(); $conditions->add("attachmentID IN (?)", [$this->parameters['attachmentIDs']]); $conditions->add("objectTypeID = ?", [$objectType->objectTypeID]); @@ -262,9 +261,7 @@ class AttachmentAction extends AbstractDatabaseObjectAction implements ISortable ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $attachmentIDs[] = $row['attachmentID']; - } + $attachmentIDs = $statement->fetchColumns(); foreach ($this->parameters['attachmentIDs'] as $attachmentID) { if (!in_array($attachmentID, $attachmentIDs)) { diff --git a/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php b/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php index 444214adfe..2ef4ed8e95 100644 --- a/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php +++ b/wcfsetup/install/files/lib/data/bbcode/BBCodeAction.class.php @@ -51,11 +51,7 @@ class BBCodeAction extends AbstractDatabaseObjectAction implements IToggleAction WHERE optionType = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array('BBCodeSelect')); - - $optionIDs = array(); - while ($optionID = $statement->fetchColumn()) { - $optionIDs[] = $optionID; - } + $optionIDs = $statement->fetchColumns(); if (!empty($optionIDs)) { $conditionBuilder = new PreparedStatementConditionBuilder(); diff --git a/wcfsetup/install/files/lib/data/box/Box.class.php b/wcfsetup/install/files/lib/data/box/Box.class.php index 15a5acac0d..3d3d6a56aa 100644 --- a/wcfsetup/install/files/lib/data/box/Box.class.php +++ b/wcfsetup/install/files/lib/data/box/Box.class.php @@ -454,15 +454,13 @@ class Box extends DatabaseObject { */ public function getPageIDs() { if ($this->pageIDs === null) { - $this->pageIDs = []; $sql = "SELECT pageID FROM wcf" . WCF_N . "_box_to_page WHERE boxID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->boxID]); - while ($pageID = $statement->fetchColumn()) { - $this->pageIDs[] = $pageID; - } + + $this->pageIDs = $statement->fetchColumns(); } return $this->pageIDs; diff --git a/wcfsetup/install/files/lib/data/comment/CommentEditor.class.php b/wcfsetup/install/files/lib/data/comment/CommentEditor.class.php index 2a581f8f7e..1903c579c9 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentEditor.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentEditor.class.php @@ -29,10 +29,7 @@ class CommentEditor extends DatabaseObjectEditor { ORDER BY time ASC, responseID ASC"; $statement = WCF::getDB()->prepareStatement($sql, 5); $statement->execute(array($this->commentID)); - $responseIDs = array(); - while ($row = $statement->fetchArray()) { - $responseIDs[] = $row['responseID']; - } + $responseIDs = $statement->fetchColumns(); $this->update(array( 'responseIDs' => serialize($responseIDs) diff --git a/wcfsetup/install/files/lib/data/label/LabelAction.class.php b/wcfsetup/install/files/lib/data/label/LabelAction.class.php index 4908c4222a..b3a90c19dc 100644 --- a/wcfsetup/install/files/lib/data/label/LabelAction.class.php +++ b/wcfsetup/install/files/lib/data/label/LabelAction.class.php @@ -100,10 +100,7 @@ class LabelAction extends AbstractDatabaseObjectAction implements ISortableActio ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $languageItemIDs = []; - while ($row = $statement->fetchArray()) { - $languageItemIDs[] = $row['languageItemID']; - } + $languageItemIDs = $statement->fetchColumns(); $objectAction = new LanguageItemAction($languageItemIDs, 'delete'); $objectAction->executeAction(); diff --git a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php index 941fc79f16..43072696d6 100644 --- a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php +++ b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php @@ -120,10 +120,7 @@ class ModerationQueueAction extends AbstractDatabaseObjectAction { ORDER BY moderation_queue.lastChangeTime DESC"; $statement = WCF::getDB()->prepareStatement($sql, 5); $statement->execute($conditions->getParameters()); - $queueIDs = array(); - while ($row = $statement->fetchArray()) { - $queueIDs[] = $row['queueID']; - } + $queueIDs = $statement->fetchColumns(); $queues = array(); if (!empty($queueIDs)) { diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 42d7373003..b40033b1cf 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -270,15 +270,12 @@ class Page extends DatabaseObject implements ILinkableObject, ITitledObject { */ public function getBoxIDs() { if ($this->boxIDs === null) { - $this->boxIDs = []; $sql = "SELECT boxID FROM wcf" . WCF_N . "_box_to_page WHERE pageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->pageID]); - while ($row = $statement->fetchArray()) { - $this->boxIDs[] = $row['boxID']; - } + $this->boxIDs = $statement->fetchColumns(); } return $this->boxIDs; diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index 6c0a623745..7d541668cb 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -420,9 +420,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject WHERE templateGroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$style->templateGroupID]); - while ($row = $statement->fetchArray()) { - $knownTemplates[] = $row['templateName']; - } + $knownTemplates = $statement->fetchColumns(); } // copy templates diff --git a/wcfsetup/install/files/lib/data/user/TeamList.class.php b/wcfsetup/install/files/lib/data/user/TeamList.class.php index 0b89b4d684..6836c7bbd4 100644 --- a/wcfsetup/install/files/lib/data/user/TeamList.class.php +++ b/wcfsetup/install/files/lib/data/user/TeamList.class.php @@ -51,9 +51,7 @@ class TeamList extends UserProfileList { ORDER BY user_group.priority DESC".(!empty($this->sqlOrderBy) ? ", ".$this->sqlOrderBy : ''); $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset); $statement->execute(); - while ($row = $statement->fetchArray()) { - $this->objectIDs[] = $row['objectID']; - } + $this->objectIDs = $statement->fetchColumns(); } /** diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 93519df6a1..c9fb307322 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -203,15 +203,12 @@ final class User extends DatabaseObject implements IRouteController, IUserConten // cache does not exist or is outdated if ($data === null || $skipCache) { - $this->groupIDs = []; $sql = "SELECT groupID FROM wcf".WCF_N."_user_to_group WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->userID]); - while ($row = $statement->fetchArray()) { - $this->groupIDs[] = $row['groupID']; - } + $this->groupIDs = $statement->fetchColumns(); // update storage data if (!$skipCache) { @@ -249,9 +246,7 @@ final class User extends DatabaseObject implements IRouteController, IUserConten WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->userID]); - while ($row = $statement->fetchArray()) { - $this->languageIDs[] = $row['languageID']; - } + $this->languageIDs = $statement->fetchColumns(); // update storage data UserStorageHandler::getInstance()->update($this->userID, 'languageIDs', serialize($this->languageIDs)); diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 5d237cf103..251c8127ea 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -95,11 +95,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $groupIDs = []; - while ($row = $statement->fetchArray()) { - $groupIDs[] = $row['groupID']; - } + $groupIDs = $statement->fetchColumns(); if (!UserGroup::isAccessibleGroup($groupIDs)) { throw new PermissionDeniedException(); diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index 9b7418de4d..934dbac131 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -168,9 +168,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->userID]); - while ($row = $statement->fetchArray()) { - $this->followingUserIDs[] = $row['followUserID']; - } + $this->followingUserIDs = $statement->fetchColumns(); // update storage data UserStorageHandler::getInstance()->update($this->userID, 'followingUserIDs', serialize($this->followingUserIDs)); @@ -204,9 +202,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { WHERE followUserID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->userID]); - while ($row = $statement->fetchArray()) { - $this->followerUserIDs[] = $row['userID']; - } + $this->followerUserIDs = $statement->fetchColumns(); // update storage data UserStorageHandler::getInstance()->update($this->userID, 'followerUserIDs', serialize($this->followerUserIDs)); @@ -240,9 +236,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->userID]); - while ($row = $statement->fetchArray()) { - $this->ignoredUserIDs[] = $row['ignoreUserID']; - } + $this->ignoredUserIDs = $statement->fetchColumns(); // update storage data UserStorageHandler::getInstance()->update($this->userID, 'ignoredUserIDs', serialize($this->ignoredUserIDs)); diff --git a/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php b/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php index 389b6347a9..38a9b0f14a 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php @@ -198,10 +198,7 @@ class UserFollowAction extends AbstractDatabaseObjectAction implements IGroupedU WHERE followUserID = ?"; $statement = WCF::getDB()->prepareStatement($sql, 20, ($this->parameters['pageNo'] - 1) * 20); $statement->execute(array($this->parameters['userID'])); - $userIDs = array(); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); // create group $group = new GroupedUserList(); diff --git a/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php b/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php index 79c4726578..46f79b55ee 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php @@ -52,10 +52,7 @@ class UserFollowingAction extends UserFollowAction { WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql, 20, ($this->parameters['pageNo'] - 1) * 20); $statement->execute(array($this->parameters['userID'])); - $userIDs = array(); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['followUserID']; - } + $userIDs = $statement->fetchColumns(); // create group $group = new GroupedUserList(); diff --git a/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php b/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php index df6e3a76a0..c5ed9b5d09 100644 --- a/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php +++ b/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php @@ -62,10 +62,7 @@ class UserProfileVisitorAction extends AbstractDatabaseObjectAction implements I ORDER BY time DESC"; $statement = WCF::getDB()->prepareStatement($sql, 20, ($this->parameters['pageNo'] - 1) * 20); $statement->execute(array($this->parameters['userID'])); - $userIDs = array(); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); // create group $group = new GroupedUserList(); diff --git a/wcfsetup/install/files/lib/form/SearchForm.class.php b/wcfsetup/install/files/lib/form/SearchForm.class.php index 6bb83176e2..4531812256 100644 --- a/wcfsetup/install/files/lib/form/SearchForm.class.php +++ b/wcfsetup/install/files/lib/form/SearchForm.class.php @@ -495,9 +495,7 @@ class SearchForm extends AbstractCaptchaForm { WHERE username ".($this->nameExactly ? "= ?" : "LIKE ?"); $statement = WCF::getDB()->prepareStatement($sql, 100); $statement->execute(array($this->username.(!$this->nameExactly ? '%' : ''))); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); if (empty($userIDs)) { $this->throwNoMatchesException(); diff --git a/wcfsetup/install/files/lib/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/form/UserSearchForm.class.php index 0eecfc025b..04d6e7bf6b 100644 --- a/wcfsetup/install/files/lib/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/form/UserSearchForm.class.php @@ -175,9 +175,7 @@ class UserSearchForm extends UserOptionListForm { // do search $statement = WCF::getDB()->prepareStatement($sql.$this->conditions, $this->maxResults); $statement->execute($this->conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $this->matches[] = $row['userID']; - } + $this->matches = $statement->fetchColumns(); } /** diff --git a/wcfsetup/install/files/lib/system/cronjob/AttachmentCleanUpCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/AttachmentCleanUpCronjob.class.php index 5215fe646a..f7979d8fec 100644 --- a/wcfsetup/install/files/lib/system/cronjob/AttachmentCleanUpCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/AttachmentCleanUpCronjob.class.php @@ -22,7 +22,6 @@ class AttachmentCleanUpCronjob extends AbstractCronjob { parent::execute($cronjob); // delete orphaned attachments - $attachmentIDs = array(); $sql = "SELECT attachmentID FROM wcf".WCF_N."_attachment WHERE objectID = ? @@ -32,9 +31,7 @@ class AttachmentCleanUpCronjob extends AbstractCronjob { 0, (TIME_NOW - 86400) )); - while ($row = $statement->fetchArray()) { - $attachmentIDs[] = $row['attachmentID']; - } + $attachmentIDs = $statement->fetchColumns(); if (!empty($attachmentIDs)) { AttachmentEditor::deleteAll($attachmentIDs); diff --git a/wcfsetup/install/files/lib/system/cronjob/DailyMailNotificationCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/DailyMailNotificationCronjob.class.php index 8193471d02..dc1fe3cd3c 100644 --- a/wcfsetup/install/files/lib/system/cronjob/DailyMailNotificationCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/DailyMailNotificationCronjob.class.php @@ -32,7 +32,6 @@ class DailyMailNotificationCronjob extends AbstractCronjob { parent::execute($cronjob); // get user ids - $userIDs = array(); $sql = "SELECT DISTINCT userID FROM wcf".WCF_N."_user_notification WHERE mailNotified = ? @@ -44,9 +43,7 @@ class DailyMailNotificationCronjob extends AbstractCronjob { TIME_NOW - 3600 * 23, 0 )); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); if (empty($userIDs)) return; // get users diff --git a/wcfsetup/install/files/lib/system/cronjob/ModerationQueueCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/ModerationQueueCronjob.class.php index 5e8c04eae7..4171428aa6 100644 --- a/wcfsetup/install/files/lib/system/cronjob/ModerationQueueCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/ModerationQueueCronjob.class.php @@ -32,10 +32,7 @@ class ModerationQueueCronjob extends AbstractCronjob { ModerationQueue::STATUS_DONE, (TIME_NOW - (86400 * 30)) )); - $queueIDs = array(); - while ($row = $statement->fetchArray()) { - $queueIDs[] = $row['queueID']; - } + $queueIDs = $statement->fetchColumns(); if (!empty($queueIDs)) { $conditions = new PreparedStatementConditionBuilder(); diff --git a/wcfsetup/install/files/lib/system/cronjob/UserQuitCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/UserQuitCronjob.class.php index 445e983314..f65050eab2 100644 --- a/wcfsetup/install/files/lib/system/cronjob/UserQuitCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/UserQuitCronjob.class.php @@ -21,7 +21,6 @@ class UserQuitCronjob extends AbstractCronjob { public function execute(Cronjob $cronjob) { parent::execute($cronjob); - $userIDs = array(); $sql = "SELECT userID FROM wcf".WCF_N."_user WHERE quitStarted > ? @@ -31,9 +30,7 @@ class UserQuitCronjob extends AbstractCronjob { 0, (TIME_NOW - 7 * 24 * 3600) )); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); if (!empty($userIDs)) { $action = new UserAction($userIDs, 'delete'); 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 9be0d7ce3e..7d39de6c8a 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -159,6 +159,21 @@ class PreparedStatement { return $column; } + /** + * Returns a specific column for all of the remaining rows. + * + * @param integer $columnNumber + * @return array + */ + public function fetchColumns($columnNumber = 0) { + $columns = []; + while ($column = $this->fetchColumn($columnNumber)) { + $columns[] = $column; + } + + return $columns; + } + /** * Fetches the next row from a result set in a database object. * diff --git a/wcfsetup/install/files/lib/system/edit/EditHistoryManager.class.php b/wcfsetup/install/files/lib/system/edit/EditHistoryManager.class.php index 8aa0f280c5..92de7cc17c 100644 --- a/wcfsetup/install/files/lib/system/edit/EditHistoryManager.class.php +++ b/wcfsetup/install/files/lib/system/edit/EditHistoryManager.class.php @@ -133,10 +133,7 @@ class EditHistoryManager extends SingletonFactory { $userIDs )); - $entryIDs = array(); - while ($entryID = $statement->fetchColumn()) { - $entryIDs[] = $entryID; - } + $entryIDs = $statement->fetchColumns(); if (empty($entryIDs)) return; $list = new EditHistoryEntryList(); diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php index 86ae1a002f..bcb05ec292 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCommentResponseImporter.class.php @@ -42,8 +42,7 @@ class AbstractCommentResponseImporter extends AbstractImporter { ORDER BY time ASC, responseID ASC"; $statement = WCF::getDB()->prepareStatement($sql, 5); $statement->execute(array($response->commentID)); - $responseIDs = array(); - while ($responseID = $statement->fetchColumn()) $responseIDs[] = $responseID; + $responseIDs = $statement->fetchColumns(); // update parent comment $sql = "UPDATE wcf".WCF_N."_comment diff --git a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php index 123dbe7875..7b91f835de 100644 --- a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php @@ -49,9 +49,7 @@ class UserImporter extends AbstractImporter { WHERE preset = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $this->eventIDs[] = $row['eventID']; - } + $this->eventIDs = $statement->fetchColumns(); $userOptionList = new UserOptionList(); $userOptionList->readObjects(); diff --git a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php index 09d756aabb..be94ea0474 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php @@ -89,10 +89,7 @@ abstract class AbstractModerationQueueHandler implements IModerationQueueHandler ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $queueIDs = array(); - while ($row = $statement->fetchArray()) { - $queueIDs[] = $row['queueID']; - } + $queueIDs = $statement->fetchColumns(); if (!empty($queueIDs)) { $queueAction = new ModerationQueueAction($queueIDs, 'delete'); diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php index 52649bcb92..d66ebbabbe 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php @@ -464,7 +464,6 @@ class PackageInstallationScheduler { // get highest version of the required major release if (preg_match('/(\d+\.\d+\.)/', $version, $match)) { - $packageVersions = array(); $sql = "SELECT DISTINCT packageVersion FROM wcf".WCF_N."_package_update_version WHERE packageUpdateID IN ( @@ -478,9 +477,7 @@ class PackageInstallationScheduler { $package->package, $match[1].'%' )); - while ($row = $statement->fetchArray()) { - $packageVersions[] = $row['packageVersion']; - } + $packageVersions = $statement->fetchColumns(); if (count($packageVersions) > 1) { // sort by version number diff --git a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php index b7a0edd627..efc2f2bc69 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php @@ -345,10 +345,7 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $pageIDs = []; - while ($pageID = $statement->fetchColumn()) { - $pageIDs[] = $pageID; - } + $pageIDs = $statement->fetchColumns(); // save page ids foreach ($pageIDs as $pageID) { diff --git a/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php index 82cec96692..0ae8e847c0 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php @@ -258,10 +258,7 @@ class MenuPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin " . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $pageIDs = []; - while ($row = $statement->fetchArray()) { - $pageIDs[] = $row['pageID']; - } + $pageIDs = $statement->fetchColumns(); // save page ids foreach ($pageIDs as $pageID) { diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 62a713c4c2..0e390a8796 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -623,15 +623,12 @@ class SessionHandler extends SingletonFactory { // work-around for setup process (package wcf does not exist yet) if (!PACKAGE_ID) { - $groupIDs = array(); $sql = "SELECT groupID FROM wcf".WCF_N."_user_to_group WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->user->userID)); - while ($row = $statement->fetchArray()) { - $groupIDs[] = $row['groupID']; - } + $groupIDs = $statement->fetchColumns(); } else { $groupIDs = $this->user->getGroupIDs(); @@ -674,9 +671,7 @@ class SessionHandler extends SingletonFactory { WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->user->userID)); - while ($row = $statement->fetchArray()) { - $this->languageIDs[] = $row['languageID']; - } + $this->languageIDs = $statement->fetchColumns(); } else { $this->languageIDs = $this->user->getLanguageIDs(); diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php index ca55460324..f5f28a51cc 100644 --- a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php @@ -102,9 +102,7 @@ class UserCollapsibleContentHandler extends SingletonFactory { $objectTypeID, WCF::getUser()->userID )); - while ($row = $statement->fetchArray()) { - $this->collapsedContent[$objectTypeID][] = $row['objectID']; - } + $this->collapsedContent[$objectTypeID] = $statement->fetchColumns(); // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'collapsedContent-'.$objectTypeID, serialize($this->collapsedContent[$objectTypeID])); 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 4729c6fa48..15404ef42b 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -156,10 +156,7 @@ class UserNotificationHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $notificationIDs = array(); - while ($row = $statement->fetchArray()) { - $notificationIDs[] = $row['notificationID']; - } + $notificationIDs = $statement->fetchColumns(); // filter array of existing notifications and remove values which // do not have a notification from this author yet (inverse logic!) @@ -709,11 +706,7 @@ class UserNotificationHandler extends SingletonFactory { $statement->execute(array( $objectTypeObj->objectTypeID )); - - $eventIDs = array(); - while ($row = $statement->fetchArray()) { - $eventIDs[] = $row['eventID']; - } + $eventIDs = $statement->fetchColumns(); if (!empty($eventIDs)) { $conditions = new PreparedStatementConditionBuilder(); @@ -725,11 +718,7 @@ class UserNotificationHandler extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - - $userIDs = array(); - while ($userID = $statement->fetchColumn()) { - $userIDs[] = $userID; - } + $userIDs = $statement->fetchColumns(); // reset number of notifications if (!empty($userIDs)) { diff --git a/wcfsetup/install/files/lib/system/user/notification/object/type/TMultiRecipientModerationQueueCommentUserNotificationObjectType.class.php b/wcfsetup/install/files/lib/system/user/notification/object/type/TMultiRecipientModerationQueueCommentUserNotificationObjectType.class.php index 884dc21266..2869de50b1 100644 --- a/wcfsetup/install/files/lib/system/user/notification/object/type/TMultiRecipientModerationQueueCommentUserNotificationObjectType.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/object/type/TMultiRecipientModerationQueueCommentUserNotificationObjectType.class.php @@ -30,8 +30,6 @@ trait TMultiRecipientModerationQueueCommentUserNotificationObjectType { return []; } - $recipientIDs = []; - // 1. fetch assigned user // 2. fetch users who commented on the moderation queue entry // 3. fetch users who responded to a comment on the moderation queue entry @@ -65,9 +63,7 @@ trait TMultiRecipientModerationQueueCommentUserNotificationObjectType { $comment->objectID, $objectTypeID ]); - while ($userID = $statement->fetchColumn()) { - $recipientIDs[] = $userID; - } + $recipientIDs = $statement->fetchColumns(); // make sure that all users can (still) access the moderation queue entry if (!empty($recipientIDs)) { @@ -80,11 +76,7 @@ trait TMultiRecipientModerationQueueCommentUserNotificationObjectType { ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - - $recipientIDs = []; - while ($userID = $statement->fetchColumn()) { - $recipientIDs[] = $userID; - } + $recipientIDs = $statement->fetchColumns(); // make sure that all users (still) have permission to access moderation if (!$recipientIDs) { diff --git a/wcfsetup/install/files/lib/system/user/object/watch/UserObjectWatchHandler.class.php b/wcfsetup/install/files/lib/system/user/object/watch/UserObjectWatchHandler.class.php index 4a3973b712..23b2ccfddb 100644 --- a/wcfsetup/install/files/lib/system/user/object/watch/UserObjectWatchHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/object/watch/UserObjectWatchHandler.class.php @@ -53,7 +53,6 @@ class UserObjectWatchHandler extends SingletonFactory { $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.user.objectWatch', $objectType); // get subscriber - $userIDs = array(); $conditionsBuilder = new PreparedStatementConditionBuilder(); $conditionsBuilder->add('objectTypeID = ?', array($objectTypeObj->objectTypeID)); $conditionsBuilder->add('objectID IN (?)', array($objectIDs)); @@ -62,9 +61,7 @@ class UserObjectWatchHandler extends SingletonFactory { ".$conditionsBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionsBuilder->getParameters()); - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchColumns(); if (!empty($userIDs)) { // reset user storage