diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 403f8b4f68dfd..dfaa1d476bf4f 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 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..868e42c5c1ecc 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 = []; @@ -452,7 +452,7 @@ public function getValueMixed( string $userId, string $app, string $key, - ?string $default = '', + string $default = '', ?bool $lazy = false ): ?string { try { @@ -461,11 +461,6 @@ public function getValueMixed( return $default; } - // in case $default is null we will convert is to string unless key is not known - if ($default === null && !$this->hasKey($userId, $app, $key, $lazy)) { - return null; - } - return $this->getTypedValue( $userId, $app, @@ -1337,7 +1332,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/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