From: Matthias Schmidt Date: Mon, 28 Mar 2016 12:34:37 +0000 (+0200) Subject: Use PreparedStatement::fetchSingleColumn() X-Git-Tag: 3.0.0_Beta_1~1286^2~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5c6ddd857408125b65a786d9eb228cd512d425f3;p=GitHub%2FWoltLab%2FWCF.git Use PreparedStatement::fetchSingleColumn() --- diff --git a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php index 9f20400428..7c0450b27f 100644 --- a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php @@ -272,13 +272,12 @@ class DataImportForm extends AbstractForm { if (empty($_POST)) { if (!$this->exporterName) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_import_mapping"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $row = $statement->fetchArray(); - if ($row['count']) { + if ($statement->fetchSingleColumn()) { $this->showMappingNotice = true; } } diff --git a/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php index ead4b3cdb6..da113ae9cb 100644 --- a/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php @@ -157,13 +157,13 @@ class TemplateAddForm extends AbstractForm { $conditionBuilder->add('packageID = ?', array($this->packageID)); } - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_template ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $row = $statement->fetchArray(); - if ($row['count']) { + + if ($statement->fetchSingleColumn()) { throw new UserInputException('tplName', 'notUnique'); } } diff --git a/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php index 937a9aaaf4..769bf8fba2 100644 --- a/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php @@ -89,13 +89,13 @@ class TemplateGroupAddForm extends AbstractForm { throw new UserInputException('templateGroupName'); } - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_template_group WHERE templateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->templateGroupName)); - $row = $statement->fetchArray(); - if ($row['count']) { + + if ($statement->fetchSingleColumn()) { throw new UserInputException('templateGroupName', 'notUnique'); } } @@ -112,13 +112,13 @@ class TemplateGroupAddForm extends AbstractForm { throw new UserInputException('templateGroupFolderName', 'notValid'); } - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_template_group WHERE templateGroupFolderName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->templateGroupFolderName)); - $row = $statement->fetchArray(); - if ($row['count']) { + + if ($statement->fetchSingleColumn()) { throw new UserInputException('templateGroupFolderName', 'notUnique'); } } diff --git a/wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php b/wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php index b6e4b13243..265bd5319a 100755 --- a/wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php @@ -117,12 +117,12 @@ class UserEmailAddressExportForm extends AbstractForm { $conditions->add("userID IN (?)", array($this->userIDs)); // count users - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $count = $statement->fetchArray(); + $count = $statement->fetchSingleColumn(); // get users $sql = "SELECT email @@ -138,7 +138,7 @@ class UserEmailAddressExportForm extends AbstractForm { echo "
\n"; } else { - echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : ''); + echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count ? $this->separator : ''); } $i++; } diff --git a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php index 5ef133d475..c94897bd77 100755 --- a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php @@ -51,13 +51,12 @@ class IndexPage extends AbstractPage { $usersAwaitingApproval = 0; if (REGISTER_ACTIVATION_METHOD == 2) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user WHERE activationCode <> 0"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $row = $statement->fetchArray(); - $usersAwaitingApproval = $row['count']; + $usersAwaitingApproval = $statement->fetchSingleColumn(); } WCF::getTPL()->assign([ diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index d0dc3c12b9..ff52bf4830 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -219,13 +219,13 @@ class UserListPage extends SortablePage { // call countItems event EventHandler::getInstance()->fireAction($this, 'countItems'); - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user user_table ".$this->conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($this->conditions->getParameters()); - $row = $statement->fetchArray(); - return $row['count']; + + return $statement->fetchColumn(); } /** diff --git a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php index 52094685d3..f59a281c0b 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php @@ -143,14 +143,14 @@ abstract class DatabaseObjectList implements \Countable, ITraversableObject { * @return integer */ public function countObjects() { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()." ".$this->sqlConditionJoins." ".$this->getConditionBuilder(); $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($this->getConditionBuilder()->getParameters()); - $row = $statement->fetchArray(); - return $row['count']; + + return $statement->fetchSingleColumn(); } /** diff --git a/wcfsetup/install/files/lib/data/like/LikeAction.class.php b/wcfsetup/install/files/lib/data/like/LikeAction.class.php index 3a45946375..790aa9ba84 100644 --- a/wcfsetup/install/files/lib/data/like/LikeAction.class.php +++ b/wcfsetup/install/files/lib/data/like/LikeAction.class.php @@ -373,7 +373,7 @@ class LikeAction extends AbstractDatabaseObjectAction implements IGroupedUserLis // if ($newLikeObject->objectUserID) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_like WHERE objectTypeID = ? AND objectID = ? @@ -384,17 +384,17 @@ class LikeAction extends AbstractDatabaseObjectAction implements IGroupedUserLis $this->parameters['targetObjectID'], Like::LIKE )); - $row = $statement->fetchArray(); + $count = $statement->fetchSingleColumn(); - if ($row['count']) { + if ($count) { // update received likes $userEditor = new UserEditor(new User($newLikeObject->objectUserID)); $userEditor->updateCounters(array( - 'likesReceived' => $row['count'] + 'likesReceived' => $count )); // add activity points - UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $row['count'])); + UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $count)); } } } diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index e89d25b322..9fa893d461 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -236,14 +236,13 @@ class Package extends DatabaseObject { * @return boolean */ public static function isAlreadyInstalled($package) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_package WHERE package = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package)); - $row = $statement->fetchArray(); - return ($row['count'] ? true : false); + return $statement->fetchSingleColumn() > 0; } /** diff --git a/wcfsetup/install/files/lib/data/poll/PollEditor.class.php b/wcfsetup/install/files/lib/data/poll/PollEditor.class.php index 82452e1678..febb71d6ce 100644 --- a/wcfsetup/install/files/lib/data/poll/PollEditor.class.php +++ b/wcfsetup/install/files/lib/data/poll/PollEditor.class.php @@ -26,7 +26,7 @@ class PollEditor extends DatabaseObjectEditor { // update option votes $sql = "UPDATE wcf".WCF_N."_poll_option poll_option SET poll_option.votes = ( - SELECT COUNT(*) AS count + SELECT COUNT(*) FROM wcf".WCF_N."_poll_option_vote WHERE optionID = poll_option.optionID ) @@ -37,9 +37,9 @@ class PollEditor extends DatabaseObjectEditor { // update total count $sql = "UPDATE wcf".WCF_N."_poll poll SET poll.votes = ( - SELECT COUNT(DISTINCT userID) AS count - FROM wcf".WCF_N."_poll_option_vote - WHERE pollID = poll.pollID + SELECT COUNT(DISTINCT userID) + FROM wcf".WCF_N."_poll_option_vote + WHERE pollID = poll.pollID ) WHERE poll.pollID = ?"; $statement = WCF::getDB()->prepareStatement($sql); diff --git a/wcfsetup/install/files/lib/data/session/virtual/SessionVirtual.class.php b/wcfsetup/install/files/lib/data/session/virtual/SessionVirtual.class.php index 8fe7420a21..cd8c0343a6 100644 --- a/wcfsetup/install/files/lib/data/session/virtual/SessionVirtual.class.php +++ b/wcfsetup/install/files/lib/data/session/virtual/SessionVirtual.class.php @@ -66,13 +66,12 @@ class SessionVirtual extends DatabaseObject { * @return integer */ public static function countVirtualSessions($sessionID) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM ".static::getDatabaseTableName()." WHERE sessionID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($sessionID)); - $row = $statement->fetchArray(); - return $row['count']; + return $statement->fetchSingleColumn(); } } diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index 5c3c98c51d..04e9d20b4b 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -351,37 +351,35 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.mb_substr(StringUtil::getRandomID(), 0, 8); $originalTemplateGroupFolderName = $templateGroupFolderName; - + // get unique template group name $i = 1; while (true) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_template_group WHERE templateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$templateGroupName]); - $row = $statement->fetchArray(); - if (!$row['count']) break; + if (!$statement->fetchSingleColumn()) break; $templateGroupName = $originalTemplateGroupName . '_' . $i; $i++; } - + // get unique folder name $i = 1; while (true) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_template_group WHERE templateGroupFolderName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([ FileUtil::addTrailingSlash($templateGroupFolderName) ]); - $row = $statement->fetchArray(); - if (!$row['count']) break; + if (!$statement->fetchSingleColumn()) break; $templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i; $i++; } - + $templateGroupAction = new TemplateGroupAction([], 'create', [ 'data' => [ 'templateGroupName' => $templateGroupName, diff --git a/wcfsetup/install/files/lib/data/user/TeamList.class.php b/wcfsetup/install/files/lib/data/user/TeamList.class.php index 626524412d..e08129b484 100644 --- a/wcfsetup/install/files/lib/data/user/TeamList.class.php +++ b/wcfsetup/install/files/lib/data/user/TeamList.class.php @@ -25,15 +25,15 @@ class TeamList extends UserProfileList { * @see \wcf\data\DatabaseObjectList::countObjects() */ public function countObjects() { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_group user_group, wcf".WCF_N."_user_to_group user_to_group WHERE user_to_group.groupID = user_group.groupID AND user_group.showOnTeamPage = 1"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $row = $statement->fetchArray(); - return $row['count']; + + return $statement->fetchSingleColumn(); } /** diff --git a/wcfsetup/install/files/lib/data/user/authentication/failure/UserAuthenticationFailure.class.php b/wcfsetup/install/files/lib/data/user/authentication/failure/UserAuthenticationFailure.class.php index 80d7c0ecff..8e152880e5 100644 --- a/wcfsetup/install/files/lib/data/user/authentication/failure/UserAuthenticationFailure.class.php +++ b/wcfsetup/install/files/lib/data/user/authentication/failure/UserAuthenticationFailure.class.php @@ -49,12 +49,13 @@ class UserAuthenticationFailure extends DatabaseObject { * @return boolean */ public static function countIPFailures($ipAddress) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_authentication_failure WHERE ipAddress = ? AND time > ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($ipAddress, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT)); + return $statement->fetchColumn(); } @@ -65,12 +66,13 @@ class UserAuthenticationFailure extends DatabaseObject { * @return boolean */ public static function countUserFailures($userID) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_authentication_failure WHERE userID = ? AND time > ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($userID, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT)); + return $statement->fetchColumn(); } } 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 1b48377a2c..1a6cc07dcf 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php @@ -169,13 +169,12 @@ class UserFollowAction extends AbstractDatabaseObjectAction implements IGroupedU */ public function getGroupedUserList() { // resolve page count - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_follow WHERE followUserID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->parameters['userID'])); - $row = $statement->fetchArray(); - $pageCount = ceil($row['count'] / 20); + $pageCount = ceil($statement->fetchSingleColumn() / 20); // get user ids $sql = "SELECT userID 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 b6845f7dd8..768caa8897 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php @@ -39,13 +39,12 @@ class UserFollowingAction extends UserFollowAction { */ public function getGroupedUserList() { // resolve page count - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_follow WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->parameters['userID'])); - $row = $statement->fetchArray(); - $pageCount = ceil($row['count'] / 20); + $pageCount = ceil($statement->fetchSingleColumn() / 20); // get user ids $sql = "SELECT followUserID 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 f4e0037e41..811062be02 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 @@ -47,13 +47,12 @@ class UserProfileVisitorAction extends AbstractDatabaseObjectAction implements I */ public function getGroupedUserList() { // resolve page count - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_profile_visitor WHERE ownerID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->parameters['userID'])); - $row = $statement->fetchArray(); - $pageCount = ceil($row['count'] / 20); + $pageCount = ceil($statement->fetchSingleColumn() / 20); // get user ids $sql = "SELECT userID diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 73c5b8d474..eb2bed913d 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -1146,8 +1146,7 @@ class WCFSetup extends WCF { WHERE package = 'com.woltlab.wcf'"; $statement = self::getDB()->prepareStatement($sql); $statement->execute(); - $row = $statement->fetchArray(); - if (!$row['count']) { + if (!$statement->fetchSingleColumn()) { if (empty($wcfPackageFile)) { throw new SystemException('the essential package com.woltlab.wcf is missing.'); } diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index 50cb817061..77f6bf9ccd 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -390,18 +390,13 @@ class ClipboardHandler extends SingletonFactory { $conditionBuilder->add("objectTypeID = ?", array($objectTypeID)); } - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_clipboard_item ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $count = $statement->fetchArray(); - if ($count['count']) { - return 1; - } - - return 0; + return $statement->fetchSingleColumn() ? 1 : 0; } /** diff --git a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueManager.class.php b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueManager.class.php index 8517afe8e4..5467e9482a 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueManager.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueManager.class.php @@ -223,15 +223,14 @@ class ModerationQueueManager extends SingletonFactory { $conditions->add("moderation_queue_to_user.isAffected = ?", array(1)); $conditions->add("moderation_queue.status IN (?)", array(array(ModerationQueue::STATUS_OUTSTANDING, ModerationQueue::STATUS_PROCESSING))); - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user LEFT JOIN wcf".WCF_N."_moderation_queue moderation_queue ON (moderation_queue.queueID = moderation_queue_to_user.queueID) ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $row = $statement->fetchArray(); - $count = $row['count']; + $count = $statement->fetchSingleColumn(); // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'outstandingModerationCount', $count); @@ -263,7 +262,7 @@ class ModerationQueueManager extends SingletonFactory { $conditions->add("moderation_queue.time > ?", array(VisitTracker::getInstance()->getVisitTime('com.woltlab.wcf.moderation.queue'))); $conditions->add("(moderation_queue.time > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)"); - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user LEFT JOIN wcf".WCF_N."_moderation_queue moderation_queue ON (moderation_queue.queueID = moderation_queue_to_user.queueID) @@ -272,9 +271,8 @@ class ModerationQueueManager extends SingletonFactory { ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $row = $statement->fetchArray(); - $count = $row['count']; - + $count = $statement->fetchSingleColumn(); + // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'unreadModerationCount', $count); } diff --git a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php index 6c28d06737..5d8418cbb0 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php @@ -33,7 +33,7 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager { public function isAlreadyReported($objectType, $objectID) { $objectTypeID = $this->getObjectTypeID($objectType); - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_moderation_queue WHERE objectTypeID = ? AND objectID = ?"; @@ -42,9 +42,8 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager { $objectTypeID, $objectID )); - $row = $statement->fetchArray(); - return ($row['count'] == 0 ? false : true); + return $statement->fetchSingleColumn() > 0; } /** diff --git a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php index 774359e6cd..91d824a095 100644 --- a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php @@ -463,14 +463,13 @@ class PackageArchive { * @return boolean */ public function isAlreadyInstalled() { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_package WHERE package = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->packageInfo['name'])); - $row = $statement->fetchArray(); - return ($row['count'] > 0) ? true : false; + return $statement->fetchSingleColumn() > 0; } /** @@ -493,7 +492,7 @@ class PackageArchive { '%.'.Package::getAbbreviation($this->packageInfo['name']) )); - return $statement->fetchColumn(); + return $statement->fetchSingleColumn() > 0; } /** diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index fbce7a40e9..e8181f7baa 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -699,13 +699,12 @@ class PackageInstallationDispatcher { $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR))); // check if there is already an application - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_package WHERE packageDir = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array('../')); - $row = $statement->fetchArray(); - if ($row['count']) { + if ($statement->fetchSingleColumn()) { // use abbreviation $defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/'; } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationFormManager.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationFormManager.class.php index 5bbd07ec68..d3e10c658e 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationFormManager.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationFormManager.class.php @@ -57,7 +57,7 @@ abstract class PackageInstallationFormManager { * @return boolean */ public static function findForm(PackageInstallationQueue $queue, $formName) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_package_installation_form WHERE queueID = ? AND formName = ?"; @@ -66,9 +66,8 @@ abstract class PackageInstallationFormManager { $queue->queueID, $formName )); - $row = $statement->fetchArray(); - return (bool)$row['count']; + return $statement->fetchSingleColumn() > 0; } /** diff --git a/wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php index 2e4c01992e..62a91ce43b 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php @@ -104,7 +104,7 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati // validate category name if (isset($data['categoryname'])) { - $sql = "SELECT COUNT(categoryID) AS count + $sql = "SELECT COUNT(categoryID) FROM wcf".WCF_N."_".$this->tableName."_category WHERE categoryName = ? AND objectTypeID = ?"; @@ -113,8 +113,8 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati $data['categoryname'], $objectTypeID )); - $row = $statement->fetchArray(); - if (!$row) { + + if (!$statement->fetchSingleColumn()) { throw new SystemException("unknown category '".$data['categoryname']."' for acl object type '".$data['objecttype']."' given"); } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php index f8c0c1984e..9ad13b0cd7 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php @@ -59,14 +59,13 @@ abstract class AbstractMenuPackageInstallationPlugin extends AbstractXMLPackageI return; } - $sql = "SELECT COUNT(menuItemID) AS count + $sql = "SELECT COUNT(menuItemID) FROM ".$this->application.WCF_N."_".$this->tableName." WHERE menuItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($data['parentMenuItem'])); - $row = $statement->fetchArray(); - if (!$row['count']) { + if (!$statement->fetchSingleColumn()) { throw new SystemException("Unable to find parent 'menu item' with name '".$data['parentMenuItem']."' for 'menu item' with name '".$data['menuItem']."'."); } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php index e7bcddbd4d..3c94d1de2a 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php @@ -127,14 +127,13 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag // validate parent if (!empty($data['parentCategoryName'])) { - $sql = "SELECT COUNT(categoryID) AS count + $sql = "SELECT COUNT(categoryID) FROM ".$this->application.WCF_N."_".$this->tableName."_category WHERE categoryName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($data['parentCategoryName'])); - $row = $statement->fetchArray(); - if (!$row['count']) { + if (!$statement->fetchSingleColumn()) { throw new SystemException("Unable to find parent 'option category' with name '".$data['parentCategoryName']."' for category with name '".$data['categoryName']."'."); } } @@ -175,13 +174,13 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag */ public function hasUninstall() { $hasUninstallOptions = parent::hasUninstall(); - $sql = "SELECT COUNT(categoryID) AS count + $sql = "SELECT COUNT(categoryID) FROM ".$this->application.WCF_N."_".$this->tableName."_category WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); - $categoryCount = $statement->fetchArray(); - return ($hasUninstallOptions || $categoryCount['count'] > 0); + + return ($hasUninstallOptions || $statement->fetchSingleColumn() > 0); } /** diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractPackageInstallationPlugin.class.php index 39c8d53ce4..d6fc74dc30 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractPackageInstallationPlugin.class.php @@ -79,13 +79,13 @@ abstract class AbstractPackageInstallationPlugin implements IPackageInstallation // call 'hasUninstall' event EventHandler::getInstance()->fireAction($this, 'hasUninstall'); - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM ".$this->application.WCF_N."_".$this->tableName." WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); - $installationCount = $statement->fetchArray(); - return $installationCount['count']; + + return $statement->fetchSingleColumn() > 0; } /** diff --git a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php index 5fad06d250..0b9ed2440a 100644 --- a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php +++ b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php @@ -71,13 +71,13 @@ class MysqlSearchIndexManager extends AbstractSearchIndexManager { $tableName = SearchIndexManager::getTableName($objectType); // check if table already exists - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_package_installation_sql_log WHERE sqlTable = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($tableName)); - $row = $statement->fetchArray(); - if ($row['count']) { + + if ($statement->fetchSingleColumn()) { // table already exists return false; } diff --git a/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php index 202010a3c4..d390db36e9 100644 --- a/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php +++ b/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php @@ -22,7 +22,7 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler { * @return integer */ protected function getCounter($date, $tableName, $dateColumnName) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM " . $tableName . " WHERE " . $dateColumnName . " BETWEEN ? AND ?"; $statement = WCF::getDB()->prepareStatement($sql); @@ -39,7 +39,7 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler { * @return integer */ protected function getTotal($date, $tableName, $dateColumnName) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM " . $tableName . " WHERE " . $dateColumnName . " < ?"; $statement = WCF::getDB()->prepareStatement($sql); 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 3fd262f312..b9aa49bd6a 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -257,7 +257,7 @@ class UserNotificationHandler extends SingletonFactory { // cache does not exist or is outdated if ($data === null || $skipCache) { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_notification WHERE userID = ? AND confirmTime = ?"; @@ -267,8 +267,7 @@ class UserNotificationHandler extends SingletonFactory { 0 )); - $row = $statement->fetchArray(); - $this->notificationCount = $row['count']; + $this->notificationCount = $statement->fetchSingleColumn(); // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'userNotificationCount', serialize($this->notificationCount)); @@ -288,14 +287,13 @@ class UserNotificationHandler extends SingletonFactory { * @return integer */ public function countAllNotifications() { - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user_notification WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(WCF::getUser()->userID)); - $row = $statement->fetchArray(); - return $row['count']; + return $statement->fetchSingleColumn(); } /** diff --git a/wcfsetup/install/files/lib/system/worker/MailWorker.class.php b/wcfsetup/install/files/lib/system/worker/MailWorker.class.php index d304d4c697..6bf09369d5 100644 --- a/wcfsetup/install/files/lib/system/worker/MailWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/MailWorker.class.php @@ -71,14 +71,13 @@ class MailWorker extends AbstractWorker { } } - $sql = "SELECT COUNT(*) AS count + $sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user user ".$this->conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($this->conditions->getParameters()); - $row = $statement->fetchArray(); - $this->count = $row['count']; + $this->count = $statement->fetchSingleColumn(); } /** diff --git a/wcfsetup/install/files/lib/util/UserUtil.class.php b/wcfsetup/install/files/lib/util/UserUtil.class.php index b272c8ccab..2709f68f23 100644 --- a/wcfsetup/install/files/lib/util/UserUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserUtil.class.php @@ -51,13 +51,13 @@ final class UserUtil { * @return boolean */ public static function isAvailableUsername($name) { - $sql = "SELECT COUNT(username) AS count + $sql = "SELECT COUNT(username) FROM wcf".WCF_N."_user WHERE username = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($name)); - $row = $statement->fetchArray(); - return $row['count'] == 0; + + return $statement->fetchSingleColumn() == 0; } /** @@ -90,13 +90,13 @@ final class UserUtil { * @return boolean */ public static function isAvailableEmail($email) { - $sql = "SELECT COUNT(email) AS count + $sql = "SELECT COUNT(email) FROM wcf".WCF_N."_user WHERE email = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($email)); - $row = $statement->fetchArray(); - return $row['count'] == 0; + + return $statement->fetchSingleColumn() == 0; } /**