aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/Command/User/Setting.php28
-rw-r--r--core/register_command.php2
-rw-r--r--lib/private/AllConfig.php15
-rw-r--r--lib/public/IConfig.php15
4 files changed, 30 insertions, 30 deletions
diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php
index 04488cdeff1..87fb6905de9 100644
--- a/core/Command/User/Setting.php
+++ b/core/Command/User/Setting.php
@@ -27,7 +27,6 @@ namespace OC\Core\Command\User;
use OC\Core\Command\Base;
use OCP\IConfig;
-use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
@@ -42,19 +41,14 @@ class Setting extends Base {
/** @var IConfig */
protected $config;
- /** @var IDBConnection */
- protected $connection;
-
/**
* @param IUserManager $userManager
* @param IConfig $config
- * @param IDBConnection $connection
*/
- public function __construct(IUserManager $userManager, IConfig $config, IDBConnection $connection) {
+ public function __construct(IUserManager $userManager, IConfig $config) {
parent::__construct();
$this->userManager = $userManager;
$this->config = $config;
- $this->connection = $connection;
}
protected function configure() {
@@ -247,26 +241,18 @@ class Setting extends Base {
}
protected function getUserSettings($uid, $app) {
- $query = $this->connection->getQueryBuilder();
- $query->select('*')
- ->from('preferences')
- ->where($query->expr()->eq('userid', $query->createNamedParameter($uid)));
-
+ $settings = $this->config->getAllUserValues($uid);
if ($app !== '') {
- $query->andWhere($query->expr()->eq('appid', $query->createNamedParameter($app)));
- }
-
- $result = $query->execute();
- $settings = [];
- while ($row = $result->fetch()) {
- $settings[$row['appid']][$row['configkey']] = $row['configvalue'];
+ if (isset($settings[$app])) {
+ $settings = [$app => $settings[$app]];
+ } else {
+ $settings = [];
+ }
}
$user = $this->userManager->get($uid);
$settings['settings']['display_name'] = $user->getDisplayName();
- $result->closeCursor();
-
return $settings;
}
}
diff --git a/core/register_command.php b/core/register_command.php
index 3cff363e46f..c7d3b073b91 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -184,7 +184,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
$application->add(\OC::$server->get(\OC\Core\Command\User\Report::class));
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
- $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
+ $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig()));
$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\Security\ICrypto::class)));
diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php
index ac2f9d7bf45..36eb0bbf6d9 100644
--- a/lib/private/AllConfig.php
+++ b/lib/private/AllConfig.php
@@ -312,14 +312,14 @@ class AllConfig implements \OCP\IConfig {
/**
* Getting a user defined value
*
- * @param string $userId the userId of the user that we want to store the value under
+ * @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
* @param mixed $default the default value to be returned if the value isn't set
* @return string
*/
public function getUserValue($userId, $appName, $key, $default = '') {
- $data = $this->getUserValues($userId);
+ $data = $this->getAllUserValues($userId);
if (isset($data[$appName][$key])) {
return $data[$appName][$key];
} else {
@@ -335,7 +335,7 @@ class AllConfig implements \OCP\IConfig {
* @return string[]
*/
public function getUserKeys($userId, $appName) {
- $data = $this->getUserValues($userId);
+ $data = $this->getAllUserValues($userId);
if (isset($data[$appName])) {
return array_keys($data[$appName]);
} else {
@@ -400,19 +400,20 @@ class AllConfig implements \OCP\IConfig {
/**
* Returns all user configs sorted by app of one user
*
- * @param string $userId the user ID to get the app configs from
+ * @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 ]
* ]
*/
- private function getUserValues($userId) {
+ public function getAllUserValues(?string $userId): array {
if (isset($this->userCache[$userId])) {
return $this->userCache[$userId];
}
if ($userId === null || $userId === '') {
- $this->userCache[$userId] = [];
- return $this->userCache[$userId];
+ $this->userCache[''] = [];
+ return $this->userCache[''];
}
// TODO - FIXME
diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php
index 33b9c97971a..0e7a7523218 100644
--- a/lib/public/IConfig.php
+++ b/lib/public/IConfig.php
@@ -186,7 +186,7 @@ interface IConfig {
/**
* Shortcut for getting a user defined value
*
- * @param string $userId the userId of the user that we want to store the value under
+ * @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
* @param mixed $default the default value to be returned if the value isn't set
@@ -217,6 +217,19 @@ interface IConfig {
public function getUserKeys($userId, $appName);
/**
+ * Get all user configs sorted by app of one user
+ *
+ * @param string $userId the userId of the user that we want to get all values from
+ * @psalm-return array<string, array<string, string>>
+ * @return array[] - 2 dimensional array with the following structure:
+ * [ $appId =>
+ * [ $key => $value ]
+ * ]
+ * @since 24.0.0
+ */
+ public function getAllUserValues(string $userId): array;
+
+ /**
* Delete a user value
*
* @param string $userId the userId of the user that we want to store the value under