Use `\PDOStatement::fetchAll()`
authorMatthias Schmidt <gravatronics@live.com>
Sun, 17 Jul 2016 18:17:51 +0000 (20:17 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 17 Jul 2016 18:17:54 +0000 (20:17 +0200)
wcfsetup/install/files/lib/data/poll/PollAction.class.php
wcfsetup/install/files/lib/page/AbstractArticlePage.class.php
wcfsetup/install/files/lib/system/acl/simple/SimpleAclHandler.class.php
wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php
wcfsetup/install/files/lib/system/importer/SmileyImporter.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php
wcfsetup/install/files/lib/system/package/PackageUninstallationNodeBuilder.class.php
wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php
wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/poll/PollManager.class.php

index cd2710b175cd16209fa5eebddf5197f34a148c39..f95edfe45980be18a9df4484e89a5005341bc938 100644 (file)
@@ -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) {
index 8c4c5daf2d30041f32cf94238c0fe5cb7c635ede..dcf22741845aebb7de61f5e64907efa46938807c 100644 (file)
@@ -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]);
index 65b59ac6ad02aee595321c9227dc8ebd876454fd..b7f76f8fe3db85ad7ea5d7cf8592bbb58230ec9c 100644 (file)
@@ -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;
index 7f11a6f2f0c08f2aab2888058754becb34c1ddad..0190ec0d9ade49183be35014298b9e0708c587c2 100644 (file)
@@ -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
index 03e00c8af40b3bfe6a59322eec016181984c1ac2..b0680e489fa8fee1d9b01648d391812f5ac30a19 100644 (file)
@@ -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'];
                        }
index 3e505d96dc795992d5a5b2f0c3b5c59ce2d0907f..7325c5e93abc77c9b0843073c5eb0ffec30c37ad 100644 (file)
@@ -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);
        }
        
        /**
index 9e7785b7816cfbb6455654d1c1f768da024a2210..d7c89590d954629cb1adc94bf8c84b2e2fd6044c 100644 (file)
@@ -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
index b001f944664a61ed34b20ca05f1364f2cc3b2beb..c3ebaaa378a3fff0893e35d2f98d905e7caf8067 100644 (file)
@@ -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."'");
index 982e5412ae1804b0e1253bd9bfff736246f7cd34..e1f35452ceb0eb0d8940aa256bf667cfd04137bc 100644 (file)
@@ -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) {
index 55d1d41670bc093a61c046a5fcf1717ccdc3c4f7..6c1872afb0cd5c5d2047cec65964a05f2f93dfb7 100644 (file)
@@ -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();
index b9290aca6cf59dc5e10c504233687e5ac27a1a6b..2e8ad2cce6ff512758f104d8523c80ce0a1bb06b 100644 (file)
@@ -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;
                        }