diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-11-20 22:02:26 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-11-20 22:02:26 +0100 |
commit | 593ef76e36a0167e87e30072730f8b6d91bb228e (patch) | |
tree | b87ce9683930d53e48e3d7f4296f0bcebdd44312 | |
parent | 78d9d4911224e4e3809f8a84085dcccbd41e33cb (diff) | |
download | nextcloud-server-593ef76e36a0167e87e30072730f8b6d91bb228e.tar.gz nextcloud-server-593ef76e36a0167e87e30072730f8b6d91bb228e.zip |
Revert "drop OC_Preferences::getUsers and getApps"
This reverts commit 09fd34eed908203674721af86ce889bfd0a0ef8d.
-rw-r--r-- | lib/private/legacy/preferences.php | 22 | ||||
-rw-r--r-- | lib/private/preferences.php | 32 | ||||
-rw-r--r-- | tests/lib/preferences-singleton.php | 28 |
3 files changed, 82 insertions, 0 deletions
diff --git a/lib/private/legacy/preferences.php b/lib/private/legacy/preferences.php index 4f88b60f245..4b68b0e69aa 100644 --- a/lib/private/legacy/preferences.php +++ b/lib/private/legacy/preferences.php @@ -28,6 +28,28 @@ OC_Preferences::$object = new \OC\Preferences(OC_DB::getConnection()); */ class OC_Preferences{ public static $object; + /** + * Get all users using the preferences + * @return array an array of user ids + * + * This function returns a list of all users that have at least one entry + * in the preferences table. + */ + public static function getUsers() { + return self::$object->getUsers(); + } + + /** + * Get all apps of a user + * @param string $user user + * @return integer[] with app ids + * + * This function returns a list of all apps of the user that have at least + * one entry in the preferences table. + */ + public static function getApps( $user ) { + return self::$object->getApps( $user ); + } /** * Get the available keys for an app diff --git a/lib/private/preferences.php b/lib/private/preferences.php index 58f75419497..cdaa207449d 100644 --- a/lib/private/preferences.php +++ b/lib/private/preferences.php @@ -68,6 +68,25 @@ class Preferences { } /** + * Get all users using the preferences + * @return array an array of user ids + * + * This function returns a list of all users that have at least one entry + * in the preferences table. + */ + public function getUsers() { + $query = 'SELECT DISTINCT `userid` FROM `*PREFIX*preferences`'; + $result = $this->conn->executeQuery($query); + + $users = array(); + while ($userid = $result->fetchColumn()) { + $users[] = $userid; + } + + return $users; + } + + /** * @param string $user * @return array[] */ @@ -90,6 +109,19 @@ class Preferences { } /** + * Get all apps of an user + * @param string $user user + * @return integer[] with app ids + * + * This function returns a list of all apps of the user that have at least + * one entry in the preferences table. + */ + public function getApps($user) { + $data = $this->getUserValues($user); + return array_keys($data); + } + + /** * Get the available keys for an app * @param string $user user * @param string $app the app we are looking for diff --git a/tests/lib/preferences-singleton.php b/tests/lib/preferences-singleton.php index 2bea889da9b..01e15acdfe1 100644 --- a/tests/lib/preferences-singleton.php +++ b/tests/lib/preferences-singleton.php @@ -40,6 +40,34 @@ class Test_Preferences extends \Test\TestCase { parent::tearDownAfterClass(); } + public function testGetUsers() { + $query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`'); + $result = $query->execute(); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['userid']; + } + + sort($expected); + $users = \OC_Preferences::getUsers(); + sort($users); + $this->assertEquals($expected, $users); + } + + public function testGetApps() { + $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?'); + $result = $query->execute(array('Someuser')); + $expected = array(); + while ($row = $result->fetchRow()) { + $expected[] = $row['appid']; + } + + sort($expected); + $apps = \OC_Preferences::getApps('Someuser'); + sort($apps); + $this->assertEquals($expected, $apps); + } + public function testGetKeys() { $query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'); $result = $query->execute(array('Someuser', 'getkeysapp')); |