From 8edb1c18f0a7e165fe18e377099d03f4dd3df4da Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 2 Sep 2024 01:10:51 -0100 Subject: [PATCH] fix psalm Signed-off-by: Maxence Lange --- lib/private/AllConfig.php | 17 +++++++++++++++-- lib/private/UserPreferences.php | 8 ++++---- lib/public/IConfig.php | 2 +- lib/public/UserPreferences/IUserPreferences.php | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 403f8b4f68dfd..d300ef31fa367 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -227,6 +227,7 @@ public function deleteAppValues($appName) { * @param string $preCondition only update if the config value was previously the value passed as $preCondition * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met * @throws \UnexpectedValueException when trying to store an unexpected value + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function setUserValue($userId, $appName, $key, $value, $preCondition = null) { if (!is_int($value) && !is_float($value) && !is_string($value)) { @@ -253,7 +254,8 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu * @param string $appName the appName that we stored the value under * @param string $key the key under which the value is being stored * @param mixed $default the default value to be returned if the value isn't set - * @return string|null + * @return null|string + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getUserValue($userId, $appName, $key, $default = '') { if ($userId === null || $userId === '') { @@ -268,6 +270,7 @@ public function getUserValue($userId, $appName, $key, $default = '') { * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we stored the value under * @return string[] + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getUserKeys($userId, $appName) { return \OC::$server->get(UserPreferences::class)->getKeys($userId, $appName); @@ -279,6 +282,7 @@ public function getUserKeys($userId, $appName) { * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we stored the value under * @param string $key the key under which the value is being stored + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function deleteUserValue($userId, $appName, $key) { \OC::$server->get(UserPreferences::class)->deletePreference($userId, $appName, $key); @@ -288,15 +292,20 @@ public function deleteUserValue($userId, $appName, $key) { * Delete all user values * * @param string $userId the userId of the user that we want to remove all values from + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function deleteAllUserValues($userId) { - \OC::$server->get(UserPreferences::class)->dropUserPreferences($userId); + if ($userId === null) { + return; + } + \OC::$server->get(UserPreferences::class)->deleteAllPreferences($userId); } /** * Delete all user related values of one app * * @param string $appName the appName of the app that we want to remove all values from + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function deleteAppFromAllUsers($appName) { \OC::$server->get(UserPreferences::class)->deleteApp($appName); @@ -311,6 +320,7 @@ public function deleteAppFromAllUsers($appName) { * [ $appId => * [ $key => $value ] * ] + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getAllUserValues(?string $userId): array { if ($userId === null || $userId === '') { @@ -334,6 +344,7 @@ public function getAllUserValues(?string $userId): array { * @param string $key the key to get the value for * @param array $userIds the user IDs to fetch the values for * @return array Mapped values: userId => value + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getUserValueForUsers($appName, $key, $userIds) { return \OC::$server->get(UserPreferences::class)->searchValuesByUsers($appName, $key, ValueType::MIXED, $userIds); @@ -346,6 +357,7 @@ public function getUserValueForUsers($appName, $key, $userIds) { * @param string $key the key to get the user for * @param string $value the value to get the user for * @return array of user IDs + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getUsersForUserValue($appName, $key, $value) { return \OC::$server->get(UserPreferences::class)->searchUsersByValueString($appName, $key, $value); @@ -358,6 +370,7 @@ public function getUsersForUserValue($appName, $key, $value) { * @param string $key the key to get the user for * @param string $value the value to get the user for * @return array of user IDs + * @deprecated 31.0.0 - use {@see IUserPreferences} directly */ public function getUsersForUserValueCaseInsensitive($appName, $key, $value) { if ($appName === 'settings' && $key === 'email') { diff --git a/lib/private/UserPreferences.php b/lib/private/UserPreferences.php index 943a1143fd407..29bf5a1469ccf 100644 --- a/lib/private/UserPreferences.php +++ b/lib/private/UserPreferences.php @@ -386,7 +386,9 @@ public function searchUsersByValueString(string $app, string $key, string|array $qb->select('userid'); $qb->where($qb->expr()->eq('appid', $qb->createNamedParameter($app))); $qb->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key))); - if (is_string($value)) { + if (is_array($value)) { + $qb->andWhere($qb->expr()->in('configvalue', $qb->createNamedParameter($value, IQueryBuilder::PARAM_STR_ARRAY))); + } else { if ($caseInsensitive) { $configValueColumn = ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) ? $qb->expr()->castColumn('configvalue', IQueryBuilder::PARAM_STR) : 'configvalue'; $qb->andWhere($qb->expr()->eq( @@ -396,8 +398,6 @@ public function searchUsersByValueString(string $app, string $key, string|array } else { $qb->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($value))); } - } else { - $qb->andWhere($qb->expr()->in('configvalue', $qb->createNamedParameter($value, IQueryBuilder::PARAM_STR_ARRAY))); } $userIds = []; @@ -1337,7 +1337,7 @@ public function deleteApp(string $app): void { $this->clearCacheAll(); } - public function dropUserPreferences(string $userId): void { + public function deleteAllPreferences(string $userId): void { $this->assertParams($userId, '', allowEmptyApp: true); $qb = $this->connection->getQueryBuilder(); $qb->delete('preferences') diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php index b322267736e7b..808b3d852d70b 100644 --- a/lib/public/IConfig.php +++ b/lib/public/IConfig.php @@ -174,7 +174,7 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu * @param string $appName the appName that we stored the value under * @param string $key the key under which the value is being stored * @param mixed $default the default value to be returned if the value isn't set - * @return string + * @return null|string * @since 6.0.0 - parameter $default was added in 7.0.0 */ public function getUserValue($userId, $appName, $key, $default = ''); diff --git a/lib/public/UserPreferences/IUserPreferences.php b/lib/public/UserPreferences/IUserPreferences.php index e48facdd5ab70..edf99230ccb88 100644 --- a/lib/public/UserPreferences/IUserPreferences.php +++ b/lib/public/UserPreferences/IUserPreferences.php @@ -519,7 +519,7 @@ public function deleteApp(string $app): void; * @param string $userId id of the user * @since 31.0.0 */ - public function dropUserPreferences(string $userId): void; + public function deleteAllPreferences(string $userId): void; /** * Clear the cache for a single user