From 25750aa09fcea0411f9338bec1b9aa2038d3ae27 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Fri, 18 Feb 2022 00:34:53 +0100 Subject: [PATCH] IConfig::getUsersForUserValue() -- interprete null value as request to fetch all users with given key set. --- lib/private/AllConfig.php | 17 ++++++++++------- lib/public/IConfig.php | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 40a52b16628b3..beb4db625716e 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -478,22 +478,25 @@ public function getUserValueForUsers($appName, $key, $userIds) { * @param string $value the value to get the user for * @return array of user IDs */ - public function getUsersForUserValue($appName, $key, $value) { + public function getUsersForUserValue($appName, $key, $value = null) { // TODO - FIXME $this->fixDIInit(); $sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' . 'WHERE `appid` = ? AND `configkey` = ? '; - if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') { - //oracle hack: need to explicitly cast CLOB to CHAR for comparison - $sql .= 'AND to_char(`configvalue`) = ?'; + if ($value !== null) { + if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') { + //oracle hack: need to explicitly cast CLOB to CHAR for comparison + $sql .= 'AND to_char(`configvalue`) = ?'; + } else { + $sql .= 'AND `configvalue` = ?'; + } + $result = $this->connection->executeQuery($sql, [$appName, $key, $value]); } else { - $sql .= 'AND `configvalue` = ?'; + $result = $this->connection->executeQuery($sql, [$appName, $key]); } - $result = $this->connection->executeQuery($sql, [$appName, $key, $value]); - $userIDs = []; while ($row = $result->fetch()) { $userIDs[] = $row['userid']; diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php index 6b396624556ca..20f68dfaaae36 100644 --- a/lib/public/IConfig.php +++ b/lib/public/IConfig.php @@ -198,7 +198,7 @@ public function getUserValue($userId, $appName, $key, $default = ''); * * @param string $appName app to get the value for * @param string $key the key to get the value for - * @param array $userIds the user IDs to fetch the values for + * @param null|array $userIds the user IDs to fetch the values for, all users with values if null * @return array Mapped values: userId => value * @since 8.0.0 */ @@ -245,9 +245,9 @@ public function deleteAppFromAllUsers($appName); * * @param string $appName the app to get the user for * @param string $key the key to get the user for - * @param string $value the value to get the user for + * @param null|string $value the value to get the user for, all users with set key if $value is null * @return array of user IDs * @since 8.0.0 */ - public function getUsersForUserValue($appName, $key, $value); + public function getUsersForUserValue($appName, $key, $value = null); }