Skip to content

Commit

Permalink
feat(user-prefs): renaming to IUserConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 18, 2024
1 parent ea1dd4f commit 97ab26e
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 406 deletions.
4 changes: 2 additions & 2 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'NCU\\Config\\Exceptions\\IncorrectTypeException' => $baseDir . '/lib/unstable/Config/Exceptions/IncorrectTypeException.php',
'NCU\\Config\\Exceptions\\TypeConflictException' => $baseDir . '/lib/unstable/Config/Exceptions/TypeConflictException.php',
'NCU\\Config\\Exceptions\\UnknownKeyException' => $baseDir . '/lib/unstable/Config/Exceptions/UnknownKeyException.php',
'NCU\\Config\\IUserPreferences' => $baseDir . '/lib/unstable/Config/IUserPreferences.php',
'NCU\\Config\\IUserConfig' => $baseDir . '/lib/unstable/Config/IUserConfig.php',
'NCU\\Config\\ValueType' => $baseDir . '/lib/unstable/Config/ValueType.php',
'OCP\\Accounts\\IAccount' => $baseDir . '/lib/public/Accounts/IAccount.php',
'OCP\\Accounts\\IAccountManager' => $baseDir . '/lib/public/Accounts/IAccountManager.php',
Expand Down Expand Up @@ -1123,7 +1123,7 @@
'OC\\Comments\\Manager' => $baseDir . '/lib/private/Comments/Manager.php',
'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php',
'OC\\Config' => $baseDir . '/lib/private/Config.php',
'OC\\Config\\UserPreferences' => $baseDir . '/lib/private/Config/UserPreferences.php',
'OC\\Config\\UserConfig' => $baseDir . '/lib/private/Config/UserConfig.php',
'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php',
'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php',
'OC\\ContactsManager' => $baseDir . '/lib/private/ContactsManager.php',
Expand Down
4 changes: 2 additions & 2 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'NCU\\Config\\Exceptions\\IncorrectTypeException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/IncorrectTypeException.php',
'NCU\\Config\\Exceptions\\TypeConflictException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/TypeConflictException.php',
'NCU\\Config\\Exceptions\\UnknownKeyException' => __DIR__ . '/../../..' . '/lib/unstable/Config/Exceptions/UnknownKeyException.php',
'NCU\\Config\\IUserPreferences' => __DIR__ . '/../../..' . '/lib/unstable/Config/IUserPreferences.php',
'NCU\\Config\\IUserConfig' => __DIR__ . '/../../..' . '/lib/unstable/Config/IUserConfig.php',
'NCU\\Config\\ValueType' => __DIR__ . '/../../..' . '/lib/unstable/Config/ValueType.php',
'OCP\\Accounts\\IAccount' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccount.php',
'OCP\\Accounts\\IAccountManager' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountManager.php',
Expand Down Expand Up @@ -1164,7 +1164,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Comments\\Manager' => __DIR__ . '/../../..' . '/lib/private/Comments/Manager.php',
'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php',
'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php',
'OC\\Config\\UserPreferences' => __DIR__ . '/../../..' . '/lib/private/Config/UserPreferences.php',
'OC\\Config\\UserConfig' => __DIR__ . '/../../..' . '/lib/private/Config/UserConfig.php',
'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php',
'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php',
'OC\\ContactsManager' => __DIR__ . '/../../..' . '/lib/private/ContactsManager.php',
Expand Down
84 changes: 48 additions & 36 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace OC;

use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\IUserPreferences;
use NCU\Config\IUserConfig;
use NCU\Config\ValueType;
use OC\Config\UserPreferences;
use OC\Config\UserConfig;
use OCP\Cache\CappedMemoryCache;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -230,20 +230,20 @@ public function deleteAppValues($appName) {
*
* @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
* @see IUserPreferences::getValueString
* @see IUserPreferences::getValueInt
* @see IUserPreferences::getValueFloat
* @see IUserPreferences::getValueArray
* @see IUserPreferences::getValueBool
* @deprecated 31.0.0 - use {@see IUserConfig} directly
* @see IUserConfig::getValueString
* @see IUserConfig::getValueInt
* @see IUserConfig::getValueFloat
* @see IUserConfig::getValueArray
* @see IUserConfig::getValueBool
*/
public function setUserValue($userId, $appName, $key, $value, $preCondition = null) {
if (!is_int($value) && !is_float($value) && !is_string($value)) {
throw new \UnexpectedValueException('Only integers, floats and strings are allowed as value');
}

/** @var UserPreferences $userPreferences */
$userPreferences = \OCP\Server::get(IUserPreferences::class);
/** @var UserConfig $userPreferences */
$userPreferences = \OCP\Server::get(IUserConfig::class);
if ($preCondition !== null) {
try {
if ($userPreferences->getValueMixed($userId, $appName, $key) !== (string)$preCondition) {
Expand All @@ -265,19 +265,19 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu
* @param mixed $default the default value to be returned if the value isn't set
*
* @return string
* @deprecated 31.0.0 - use {@see IUserPreferences} directly
* @see IUserPreferences::getValueString
* @see IUserPreferences::getValueInt
* @see IUserPreferences::getValueFloat
* @see IUserPreferences::getValueArray
* @see IUserPreferences::getValueBool
* @deprecated 31.0.0 - use {@see IUserConfig} directly
* @see IUserConfig::getValueString
* @see IUserConfig::getValueInt
* @see IUserConfig::getValueFloat
* @see IUserConfig::getValueArray
* @see IUserConfig::getValueBool
*/
public function getUserValue($userId, $appName, $key, $default = '') {
if ($userId === null || $userId === '') {
return $default;
}
/** @var UserPreferences $userPreferences */
$userPreferences = \OCP\Server::get(IUserPreferences::class);
/** @var UserConfig $userPreferences */
$userPreferences = \OCP\Server::get(IUserConfig::class);
// because $default can be null ...
if (!$userPreferences->hasKey($userId, $appName, $key)) {
return $default;
Expand All @@ -290,11 +290,12 @@ 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::getKeys} directly
* @deprecated 31.0.0 - use {@see IUserConfig::getKeys} directly
*/
public function getUserKeys($userId, $appName) {
return \OCP\Server::get(IUserPreferences::class)->getKeys($userId, $appName);
return \OCP\Server::get(IUserConfig::class)->getKeys($userId, $appName);
}

/**
Expand All @@ -303,52 +304,56 @@ 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::deletePreference} directly
*
* @deprecated 31.0.0 - use {@see IUserConfig::deleteUserConfig} directly
*/
public function deleteUserValue($userId, $appName, $key) {
\OCP\Server::get(IUserPreferences::class)->deletePreference($userId, $appName, $key);
\OCP\Server::get(IUserConfig::class)->deleteUserConfig($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::deleteAllPreferences} directly
*
* @deprecated 31.0.0 - use {@see IUserConfig::deleteAllUserConfig} directly
*/
public function deleteAllUserValues($userId) {
if ($userId === null) {
return;
}
\OCP\Server::get(IUserPreferences::class)->deleteAllPreferences($userId);
\OCP\Server::get(IUserConfig::class)->deleteAllUserConfig($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::deleteApp} directly
*
* @deprecated 31.0.0 - use {@see IUserConfig::deleteApp} directly
*/
public function deleteAppFromAllUsers($appName) {
\OCP\Server::get(IUserPreferences::class)->deleteApp($appName);
\OCP\Server::get(IUserConfig::class)->deleteApp($appName);
}

/**
* Returns all user configs sorted by app of one user
*
* @param ?string $userId the user ID to get the app configs from
*
* @psalm-return array<string, array<string, string>>
* @return array[] - 2 dimensional array with the following structure:
* [ $appId =>
* [ $key => $value ]
* ]
* @deprecated 31.0.0 - use {@see IUserPreferences::getAllValues} directly
* @deprecated 31.0.0 - use {@see IUserConfig::getAllValues} directly
*/
public function getAllUserValues(?string $userId): array {
if ($userId === null || $userId === '') {
return [];
}

$values = \OCP\Server::get(IUserPreferences::class)->getAllValues($userId);
$values = \OCP\Server::get(IUserConfig::class)->getAllValues($userId);
$result = [];
foreach ($values as $app => $list) {
foreach ($list as $key => $value) {
Expand All @@ -364,11 +369,12 @@ public function getAllUserValues(?string $userId): array {
* @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
*
* @return array Mapped values: userId => value
* @deprecated 31.0.0 - use {@see IUserPreferences::getValuesByUsers} directly
* @deprecated 31.0.0 - use {@see IUserConfig::getValuesByUsers} directly
*/
public function getUserValueForUsers($appName, $key, $userIds) {
return \OCP\Server::get(IUserPreferences::class)->getValuesByUsers($appName, $key, ValueType::MIXED, $userIds);
return \OCP\Server::get(IUserConfig::class)->getValuesByUsers($appName, $key, ValueType::MIXED, $userIds);
}

/**
Expand All @@ -377,11 +383,14 @@ public function getUserValueForUsers($appName, $key, $userIds) {
* @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
* @return array<string> of user IDs
* @deprecated 31.0.0 - use {@see IUserPreferences::searchUsersByValueString} directly
*
* @return list<string> of user IDs
* @deprecated 31.0.0 - use {@see IUserConfig::searchUsersByValueString} directly
*/
public function getUsersForUserValue($appName, $key, $value) {
return iterator_to_array(\OCP\Server::get(IUserPreferences::class)->searchUsersByValueString($appName, $key, $value));
/** @var list<string> $result */
$result = iterator_to_array(\OCP\Server::get(IUserConfig::class)->searchUsersByValueString($appName, $key, $value));
return $result;
}

/**
Expand All @@ -390,15 +399,18 @@ public function getUsersForUserValue($appName, $key, $value) {
* @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
* @return array<string> of user IDs
* @deprecated 31.0.0 - use {@see IUserPreferences::searchUsersByValueString} directly
*
* @return list<string> of user IDs
* @deprecated 31.0.0 - use {@see IUserConfig::searchUsersByValueString} directly
*/
public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
if ($appName === 'settings' && $key === 'email') {
return $this->getUsersForUserValue($appName, $key, strtolower($value));
}

return iterator_to_array(\OCP\Server::get(IUserPreferences::class)->searchUsersByValueString($appName, $key, $value, true));
/** @var list<string> $result */
$result = iterator_to_array(\OCP\Server::get(IUserConfig::class)->searchUsersByValueString($appName, $key, $value, true));
return $result;
}

public function getSystemConfig() {
Expand Down
Loading

0 comments on commit 97ab26e

Please sign in to comment.