From: Matthias Schmidt Date: Sat, 30 Jul 2016 19:48:47 +0000 (+0200) Subject: Add key property parameter to `PreparedStatament::fetchObjects()` X-Git-Tag: 3.0.0_Beta_1~861 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=624e4faff97971d3a47403be816bdab582352f60;p=GitHub%2FWoltLab%2FWCF.git Add key property parameter to `PreparedStatament::fetchObjects()` --- diff --git a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php index 7e645ae62d..6994066515 100644 --- a/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php +++ b/wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php @@ -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) { 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 d0d2f70474..0bf554cfcd 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -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; 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 1d59e1408f..7bbd03f959 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php @@ -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 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 a9fa773e6a..e86992624f 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php @@ -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(); 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 09105cbaa3..23a3f5559b 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -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'); } /**