Skip to content

Commit

Permalink
fix psalm
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Sep 2, 2024
1 parent 41ba78f commit 8edb1c1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
17 changes: 15 additions & 2 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 === '') {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 === '') {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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') {
Expand Down
8 changes: 4 additions & 4 deletions lib/private/UserPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/public/IConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '');
Expand Down
2 changes: 1 addition & 1 deletion lib/public/UserPreferences/IUserPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8edb1c1

Please sign in to comment.