From 069e301351310d60457d55c84ae4c5478e5c998f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 17 Jul 2016 20:17:51 +0200 Subject: [PATCH] Use `\PDOStatement::fetchAll()` --- .../install/files/lib/data/poll/PollAction.class.php | 8 ++------ .../files/lib/page/AbstractArticlePage.class.php | 10 ++-------- .../lib/system/acl/simple/SimpleAclHandler.class.php | 10 ++-------- .../system/cache/builder/RoutingCacheBuilder.class.php | 5 +---- .../files/lib/system/importer/SmileyImporter.class.php | 2 +- .../package/PackageInstallationNodeBuilder.class.php | 6 +----- .../package/PackageUninstallationNodeBuilder.class.php | 5 +---- .../system/package/PackageUpdateDispatcher.class.php | 5 +---- .../plugin/LanguagePackageInstallationPlugin.class.php | 5 +---- .../plugin/SQLPackageInstallationPlugin.class.php | 5 +---- .../files/lib/system/poll/PollManager.class.php | 1 + 11 files changed, 14 insertions(+), 48 deletions(-) diff --git a/wcfsetup/install/files/lib/data/poll/PollAction.class.php b/wcfsetup/install/files/lib/data/poll/PollAction.class.php index cd2710b175..f95edfe459 100644 --- a/wcfsetup/install/files/lib/data/poll/PollAction.class.php +++ b/wcfsetup/install/files/lib/data/poll/PollAction.class.php @@ -173,12 +173,8 @@ class PollAction extends AbstractDatabaseObjectAction implements IGroupedUserLis $poll->pollID, WCF::getUser()->userID ]); - $alreadyVoted = false; - $optionIDs = []; - while ($row = $statement->fetchArray()) { - $alreadyVoted = true; - $optionIDs[] = $row['optionID']; - } + $optionIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + $alreadyVoted = !empty($optionIDs); // calculate the difference foreach ($this->parameters['optionIDs'] as $index => $optionID) { diff --git a/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php index 8c4c5daf2d..dcf2274184 100644 --- a/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractArticlePage.class.php @@ -132,10 +132,7 @@ abstract class AbstractArticlePage extends AbstractPage { ORDER BY count DESC"; $statement = WCF::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES); $statement->execute($conditionBuilder->getParameters()); - $articleContentIDs = []; - while ($row = $statement->fetchArray()) { - $articleContentIDs[] = $row['objectID']; - } + $articleContentIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); if (!empty($articleContentIDs)) { $conditionBuilder = new PreparedStatementConditionBuilder(); @@ -145,10 +142,7 @@ abstract class AbstractArticlePage extends AbstractPage { " . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); - $articleIDs = []; - while ($row = $statement->fetchArray()) { - $articleIDs[] = $row['articleID']; - } + $articleIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); $this->relatedArticles = new AccessibleArticleList(); $this->relatedArticles->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]); diff --git a/wcfsetup/install/files/lib/system/acl/simple/SimpleAclHandler.class.php b/wcfsetup/install/files/lib/system/acl/simple/SimpleAclHandler.class.php index 65b59ac6ad..b7f76f8fe3 100644 --- a/wcfsetup/install/files/lib/system/acl/simple/SimpleAclHandler.class.php +++ b/wcfsetup/install/files/lib/system/acl/simple/SimpleAclHandler.class.php @@ -73,10 +73,7 @@ class SimpleAclHandler extends SingletonFactory { $objectTypeID, $objectID ]); - $userIDs = []; - while ($row = $statement->fetchArray()) { - $userIDs[] = $row['userID']; - } + $userIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); $sql = "SELECT groupID FROM wcf".WCF_N."_acl_simple_to_group @@ -87,10 +84,7 @@ class SimpleAclHandler extends SingletonFactory { $objectTypeID, $objectID ]); - $groupIDs = []; - while ($row = $statement->fetchArray()) { - $groupIDs[] = $row['groupID']; - } + $groupIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); if (!empty($userIDs) || !empty($groupIDs)) { $data['allowAll'] = false; diff --git a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php index 7f11a6f2f0..0190ec0d9a 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php @@ -111,10 +111,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder { AND controllerCustomURL <> ''"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - $rows = []; - while ($row = $statement->fetchArray()) { - $rows[] = $row; - } + $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); // fetch content pages using the common page controller $sql = "SELECT page_content.customURL AS controllerCustomURL, page_content.pageID, page_content.languageID, page.applicationPackageID diff --git a/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php b/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php index 03e00c8af4..b0680e489f 100644 --- a/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php @@ -40,7 +40,7 @@ class SmileyImporter extends AbstractImporter { $known = explode("\n", $row['aliases']); } $known[] = $row['smileyCode']; - + foreach ($known as $smileyCode) { $this->knownCodes[mb_strtolower($smileyCode)] = $row['smileyID']; } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php index 3e505d96dc..7325c5e93a 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php @@ -189,12 +189,8 @@ class PackageInstallationNodeBuilder { $this->installation->queue->processNo, $node ]); - $data = []; - while ($row = $statement->fetchArray()) { - $data[] = $row; - } - return $data; + return $statement->fetchAll(\PDO::FETCH_ASSOC); } /** diff --git a/wcfsetup/install/files/lib/system/package/PackageUninstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageUninstallationNodeBuilder.class.php index 9e7785b781..d7c89590d9 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUninstallationNodeBuilder.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUninstallationNodeBuilder.class.php @@ -35,16 +35,13 @@ class PackageUninstallationNodeBuilder extends PackageInstallationNodeBuilder { } // fetch ordered pips - $pips = []; $sql = "SELECT pluginName, className, CASE pluginName WHEN 'packageinstallationplugin' THEN 1 WHEN 'file' THEN 2 ELSE 0 END AS pluginOrder FROM wcf".WCF_N."_package_installation_plugin ORDER BY pluginOrder, priority"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - while ($row = $statement->fetchArray()) { - $pips[] = $row; - } + $pips = $statement->fetchAll(\PDO::FETCH_ASSOC); // insert pips $sql = "INSERT INTO wcf".WCF_N."_package_installation_node diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index b001f94466..c3ebaaa378 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -672,7 +672,6 @@ class PackageUpdateDispatcher extends SingletonFactory { } // get versions - $versions = []; $sql = "SELECT puv.*, pu.*, pus.loginUsername, pus.loginPassword FROM wcf".WCF_N."_package_update_version puv LEFT JOIN wcf".WCF_N."_package_update pu @@ -688,9 +687,7 @@ class PackageUpdateDispatcher extends SingletonFactory { $version, 0 ]); - while ($row = $statement->fetchArray()) { - $versions[] = $row; - } + $versions = $statement->fetchAll(\PDO::FETCH_ASSOC); if (empty($versions)) { throw new SystemException("Cannot find package '".$package."' in version '".$version."'"); diff --git a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php index 982e5412ae..e1f35452ce 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php @@ -67,15 +67,12 @@ class LanguagePackageInstallationPlugin extends AbstractXMLPackageInstallationPl } // get installed languages - $installedLanguages = []; $sql = "SELECT * FROM wcf".WCF_N."_language ORDER BY isDefault DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - while ($row = $statement->fetchArray()) { - $installedLanguages[] = $row; - } + $installedLanguages = $statement->fetchAll(\PDO::FETCH_ASSOC); // install language foreach ($installedLanguages as $installedLanguage) { diff --git a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php index 55d1d41670..6c1872afb0 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php @@ -89,10 +89,7 @@ class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin { ORDER BY sqlIndex DESC, sqlColumn DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->installation->getPackageID()]); - $entries = []; - while ($row = $statement->fetchArray()) { - $entries[] = $row; - } + $entries = $statement->fetchAll(\PDO::FETCH_ASSOC); // get all tablenames from database $existingTableNames = WCF::getDB()->getEditor()->getTableNames(); diff --git a/wcfsetup/install/files/lib/system/poll/PollManager.class.php b/wcfsetup/install/files/lib/system/poll/PollManager.class.php index b9290aca6c..2e8ad2cce6 100644 --- a/wcfsetup/install/files/lib/system/poll/PollManager.class.php +++ b/wcfsetup/install/files/lib/system/poll/PollManager.class.php @@ -145,6 +145,7 @@ class PollManager extends SingletonFactory { ORDER BY showOrder ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->poll->pollID]); + // TODO?: $this->pollOptions = $statement->fetchAll(\PDO::FETCH_ASSOC); while ($row = $statement->fetchArray()) { $this->pollOptions[] = $row; } -- 2.20.1