Add key property parameter to `PreparedStatament::fetchObjects()`
authorMatthias Schmidt <gravatronics@live.com>
Sat, 30 Jul 2016 19:48:47 +0000 (21:48 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 30 Jul 2016 19:48:47 +0000 (21:48 +0200)
wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php
wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php
wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index 7e645ae62d238d44a6fca4a014463462d763a011..69940665158c50f24f0505a7f60a263d487ea2d1 100644 (file)
@@ -369,10 +369,9 @@ class PackageUpdateAction extends AbstractDatabaseObjectAction {
                        ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditions->getParameters());
-               $updateVersions = [];
-               while ($updateVersion = $statement->fetchObject(PackageUpdateVersion::class)) {
-                       $updateVersions[$updateVersion->packageUpdateVersionID] = $updateVersion;
-               }
+               
+               /** @var PackageUpdateVersion[] $updateVersions */
+               $updateVersions = $statement->fetchObjects(PackageUpdateVersion::class, 'packageUpdateVersionID');
                
                // assign versions
                foreach ($packageUpdates as $packageUpdateID => $packageUpdate) {
index d0d2f70474ba421b34036d3f174e4488673a415a..0bf554cfcd90dc5b6998edd22129589bf7263c83 100644 (file)
@@ -173,13 +173,19 @@ class PreparedStatement {
        /**
         * Fetches the all rows from a result set into database objects.
         * 
-        * @param       string                  $className
+        * @param       string          $className
+        * @param       string|null     $keyProperty
         * @return      DatabaseObject[]
         */
-       public function fetchObjects($className) {
+       public function fetchObjects($className, $keyProperty = null) {
                $objects = [];
                while ($object = $this->fetchObject($className)) {
-                       $objects[] = $object;
+                       if ($keyProperty === null) {
+                               $objects[] = $object;
+                       }
+                       else {
+                               $objects[$object->$keyProperty] = $object;
+                       }
                }
                
                return $objects;
index 1d59e1408f9bf333656b4fd5261b5965cb6a52a8..7bbd03f959d0a7654cc2132b275fd9e9c8942aa4 100644 (file)
@@ -319,12 +319,9 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                        ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditions->getParameters());
-               $boxes = [];
                
-               /** @var Box $box */
-               while ($box = $statement->fetchObject(Box::class)) {
-                       $boxes[$box->identifier] = $box;
-               }
+               /** @var Box[] $boxes */
+               $boxes = $statement->fetchObjects(Box::class, 'identifier');
                
                // save visibility exceptions
                $sql = "DELETE FROM     wcf".WCF_N."_box_to_page
index a9fa773e6a468c9a52eed13fd0960c86d7c92c0c..e86992624f62c2ab7a594e2c1f4d15dfc249cdd0 100644 (file)
@@ -199,12 +199,9 @@ class MenuPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                        ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditions->getParameters());
-               $boxes = [];
                
-               /** @var Box $box */
-               while ($box = $statement->fetchObject(Box::class)) {
-                       $boxes[$box->identifier] = $box;
-               }
+               /** @var Box[] $boxes */
+               $boxes = $statement->fetchObjects(Box::class, 'identifier');
                
                // fetch all menus relevant
                $menuList = new MenuList();
index 09105cbaa3a32d967249170833c0290594bcd9b1..23a3f5559bc719dc4675a6652ee24440ecc47b73 100644 (file)
@@ -373,12 +373,7 @@ class UserNotificationHandler extends SingletonFactory {
                $statement = WCF::getDB()->prepareStatement($sql, $limit, $offset);
                $statement->execute($conditions->getParameters());
                
-               $notifications = [];
-               while ($notification = $statement->fetchObject(UserNotification::class)) {
-                       $notifications[$notification->notificationID] = $notification;
-               }
-               
-               return $notifications;
+               return $statement->fetchObjects(UserNotification::class, 'notificationID');
        }
        
        /**