From 0d4f0ab87182cf2cb588bd3285fe41b46f26ee4d Mon Sep 17 00:00:00 2001
From: Morris Jobke <hey@morrisjobke.de>
Date: Thu, 4 Dec 2014 16:48:07 +0100
Subject: [PATCH] reduce OC_Preferences, OC_Config  and \OCP\Config usage

* files_encryption
* files_versions
* files_trashbin
* tests
* status.php
* core
* server container
---
 apps/files_encryption/hooks/hooks.php   |  2 +-
 apps/files_encryption/lib/util.php      | 20 +++++++++++++++-----
 apps/files_encryption/tests/util.php    |  4 +++-
 apps/files_trashbin/lib/trashbin.php    |  6 ++++--
 apps/files_versions/lib/storage.php     |  7 ++++---
 lib/base.php                            |  2 +-
 lib/private/allconfig.php               |  8 ++++----
 lib/private/ocs/cloud.php               |  2 +-
 lib/private/share/mailnotifications.php |  2 +-
 lib/private/user/session.php            |  6 +++---
 lib/private/user/user.php               |  7 ++++---
 lib/public/config.php                   |  4 ++--
 settings/ajax/lostpassword.php          |  2 +-
 settings/ajax/setlanguage.php           |  2 +-
 settings/ajax/setquota.php              |  2 +-
 settings/personal.php                   | 15 ++++++++-------
 settings/users.php                      |  6 ++++--
 status.php                              |  6 ++++--
 tests/lib/helperstorage.php             |  2 +-
 tests/lib/user/session.php              |  6 +++---
 tests/lib/util.php                      |  8 ++++----
 21 files changed, 70 insertions(+), 49 deletions(-)

diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index a6b7555b376..f26eefa30e2 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -502,7 +502,7 @@ class Hooks {
 	public static function preDisable($params) {
 		if ($params['app'] === 'files_encryption') {
 
-			\OC_Preferences::deleteAppFromAllUsers('files_encryption');
+			\OC::$server->getConfig()->deleteAppFromAllUsers('files_encryption');
 
 			$session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
 			$session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED);
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 42a7e20c87f..2b4a50d6e2b 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -225,7 +225,7 @@ class Util {
 	 */
 	public function recoveryEnabledForUser() {
 
-		$recoveryMode = \OC_Preferences::getValue($this->userId, 'files_encryption', 'recovery_enabled', '0');
+		$recoveryMode = \OC::$server->getConfig()->getUserValue($this->userId, 'files_encryption', 'recovery_enabled', '0');
 
 		return ($recoveryMode === '1') ? true : false;
 
@@ -239,7 +239,12 @@ class Util {
 	public function setRecoveryForUser($enabled) {
 
 		$value = $enabled ? '1' : '0';
-		return \OC_Preferences::setValue($this->userId, 'files_encryption', 'recovery_enabled', $value);
+		try {
+			\OC::$server->getConfig()->setUserValue($this->userId, 'files_encryption', 'recovery_enabled', $value);
+			return true;
+		} catch(\OCP\PreConditionNotMetException $e) {
+			return false;
+		}
 
 	}
 
@@ -1102,7 +1107,12 @@ class Util {
 		// convert to string if preCondition is set
 		$preCondition = ($preCondition === null) ? null : (string)$preCondition;
 
-		return \OC_Preferences::setValue($this->userId, 'files_encryption', 'migration_status', (string)$status, $preCondition);
+		try {
+			\OC::$server->getConfig()->setUserValue($this->userId, 'files_encryption', 'migration_status', (string)$status, $preCondition);
+			return true;
+		} catch(\OCP\PreConditionNotMetException $e) {
+			return false;
+		}
 
 	}
 
@@ -1154,9 +1164,9 @@ class Util {
 
 		$migrationStatus = false;
 		if (\OCP\User::userExists($this->userId)) {
-			$migrationStatus = \OC_Preferences::getValue($this->userId, 'files_encryption', 'migration_status');
+			$migrationStatus = \OC::$server->getConfig()->getUserValue($this->userId, 'files_encryption', 'migration_status', null);
 			if ($migrationStatus === null) {
-				\OC_Preferences::setValue($this->userId, 'files_encryption', 'migration_status', (string)self::MIGRATION_OPEN);
+				\OC::$server->getConfig()->setUserValue($this->userId, 'files_encryption', 'migration_status', (string)self::MIGRATION_OPEN);
 				$migrationStatus = self::MIGRATION_OPEN;
 			}
 		}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 8d9aba423cd..2d58db2128c 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -617,7 +617,9 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
 	 * @return boolean
 	 */
 	private function setMigrationStatus($status, $user) {
-		return \OC_Preferences::setValue($user, 'files_encryption', 'migration_status', (string)$status);
+		\OC::$server->getConfig()->setUserValue($user, 'files_encryption', 'migration_status', (string)$status);
+		// the update will definitely be executed -> return value is always true
+		return true;
 	}
 
 }
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 661fc271dfc..b9d7a4aa6cf 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -621,11 +621,13 @@ class Trashbin {
 	 * @return int available free space for trash bin
 	 */
 	private static function calculateFreeSpace($trashbinSize, $user) {
+		$config = \OC::$server->getConfig();
+
 		$softQuota = true;
-		$quota = \OC_Preferences::getValue($user, 'files', 'quota');
+		$quota = $config->getUserValue($user, 'files', 'quota', null);
 		$view = new \OC\Files\View('/' . $user);
 		if ($quota === null || $quota === 'default') {
-			$quota = \OC::$server->getAppConfig()->getValue('files', 'default_quota');
+			$quota = $config->getAppValue('files', 'default_quota', null);
 		}
 		if ($quota === null || $quota === 'none') {
 			$quota = \OC\Files\Filesystem::free_space('/');
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 82e0ecc3e2f..3d30ada863a 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -479,15 +479,16 @@ class Storage {
 	 * Erase a file's versions which exceed the set quota
 	 */
 	private static function expire($filename, $versionsSize = null, $offset = 0) {
-		if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+		$config = \OC::$server->getConfig();
+		if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
 			list($uid, $filename) = self::getUidAndFilename($filename);
 			$versionsFileview = new \OC\Files\View('/'.$uid.'/files_versions');
 
 			// get available disk space for user
 			$softQuota = true;
-			$quota = \OC_Preferences::getValue($uid, 'files', 'quota');
+			$quota = $config->getUserValue($uid, 'files', 'quota', null);
 			if ( $quota === null || $quota === 'default') {
-				$quota = \OC::$server->getAppConfig()->getValue('files', 'default_quota');
+				$quota = $config->getAppValue('files', 'default_quota', null);
 			}
 			if ( $quota === null || $quota === 'none' ) {
 				$quota = \OC\Files\Filesystem::free_space('/');
diff --git a/lib/base.php b/lib/base.php
index 141657fe095..af2474c7d76 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -236,7 +236,7 @@ class OC {
 			$header = 'Strict-Transport-Security: max-age=31536000';
 
 			// If SSL for subdomains is enabled add "; includeSubDomains" to the header
-			if(\OC::$server->getSystemConfig()->getmValue('forceSSLforSubdomains', false)) {
+			if(\OC::$server->getSystemConfig()->getValue('forceSSLforSubdomains', false)) {
 				$header .= '; includeSubDomains';
 			}
 			header($header);
diff --git a/lib/private/allconfig.php b/lib/private/allconfig.php
index ea919006f96..e20f3698258 100644
--- a/lib/private/allconfig.php
+++ b/lib/private/allconfig.php
@@ -117,7 +117,7 @@ class AllConfig implements \OCP\IConfig {
 	 * @param string $value the value that should be stored
 	 */
 	public function setAppValue($appName, $key, $value) {
-		\OCP\Config::setAppValue($appName, $key, $value);
+		\OC::$server->getAppConfig()->setValue($appName, $key, $value);
 	}
 
 	/**
@@ -129,7 +129,7 @@ class AllConfig implements \OCP\IConfig {
 	 * @return string the saved value
 	 */
 	public function getAppValue($appName, $key, $default = '') {
-		return \OCP\Config::getAppValue($appName, $key, $default);
+		return \OC::$server->getAppConfig()->getValue($appName, $key, $default);
 	}
 
 	/**
@@ -139,7 +139,7 @@ class AllConfig implements \OCP\IConfig {
 	 * @param string $key the key of the value, under which it was saved
 	 */
 	public function deleteAppValue($appName, $key) {
-		\OC_Appconfig::deleteKey($appName, $key);
+		\OC::$server->getAppConfig()->deleteKey($appName, $key);
 	}
 
 	/**
@@ -148,7 +148,7 @@ class AllConfig implements \OCP\IConfig {
 	 * @param string $appName the appName the configs are stored under
 	 */
 	public function deleteAppValues($appName) {
-		\OC_Appconfig::deleteApp($appName);
+		\OC::$server->getAppConfig()->deleteApp($appName);
 	}
 
 
diff --git a/lib/private/ocs/cloud.php b/lib/private/ocs/cloud.php
index 3ced0af8ee1..552aa96a26b 100644
--- a/lib/private/ocs/cloud.php
+++ b/lib/private/ocs/cloud.php
@@ -91,7 +91,7 @@ class OC_OCS_Cloud {
 	}
 
 	public static function getCurrentUser() {
-		$email=OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
+		$email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', '');
 		$data  = array(
 			'id' => OC_User::getUser(),
 			'display-name' => OC_User::getDisplayName(),
diff --git a/lib/private/share/mailnotifications.php b/lib/private/share/mailnotifications.php
index 2f704fb2b3c..342d3d5057a 100644
--- a/lib/private/share/mailnotifications.php
+++ b/lib/private/share/mailnotifications.php
@@ -79,7 +79,7 @@ class MailNotifications {
 
 		foreach ($recipientList as $recipient) {
 			$recipientDisplayName = \OCP\User::getDisplayName($recipient);
-			$to = \OC_Preferences::getValue($recipient, 'settings', 'email', '');
+			$to = \OC::$server->getConfig()->getUserValue($recipient, 'settings', 'email', '');
 
 			if ($to === '') {
 				$noMail[] = $recipientDisplayName;
diff --git a/lib/private/user/session.php b/lib/private/user/session.php
index 94abaca3e76..277aa1a047e 100644
--- a/lib/private/user/session.php
+++ b/lib/private/user/session.php
@@ -211,15 +211,15 @@ class Session implements IUserSession, Emitter {
 		}
 
 		// get stored tokens
-		$tokens = \OC_Preferences::getKeys($uid, 'login_token');
+		$tokens = \OC::$server->getConfig()->getUserKeys($uid, 'login_token');
 		// test cookies token against stored tokens
 		if (!in_array($currentToken, $tokens, true)) {
 			return false;
 		}
 		// replace successfully used token with a new one
-		\OC_Preferences::deleteKey($uid, 'login_token', $currentToken);
+		\OC::$server->getConfig()->deleteUserValue($uid, 'login_token', $currentToken);
 		$newToken = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
-		\OC_Preferences::setValue($uid, 'login_token', $newToken, time());
+		\OC::$server->getConfig()->setUserValue($uid, 'login_token', $newToken, time());
 		$this->setMagicInCookie($user->getUID(), $newToken);
 
 		//login
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index fb66f893c61..00ded84f955 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -68,10 +68,11 @@ class User implements IUser {
 		if ($this->config) {
 			$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
 			$this->enabled = ($enabled === 'true');
+			$this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
 		} else {
 			$this->enabled = true;
+			$this->lastLogin = \OC::$server->getConfig()->getUserValue($uid, 'login', 'lastLogin', 0);
 		}
-		$this->lastLogin = \OC_Preferences::getValue($uid, 'login', 'lastLogin', 0);
 	}
 
 	/**
@@ -140,7 +141,7 @@ class User implements IUser {
 	 */
 	public function updateLastLoginTimestamp() {
 		$this->lastLogin = time();
-		\OC_Preferences::setValue(
+		\OC::$server->getConfig()->setUserValue(
 			$this->uid, 'login', 'lastLogin', $this->lastLogin);
 	}
 
@@ -163,7 +164,7 @@ class User implements IUser {
 				\OC_Group::removeFromGroup($this->uid, $i);
 			}
 			// Delete the user's keys in preferences
-			\OC_Preferences::deleteUser($this->uid);
+			\OC::$server->getConfig()->deleteAllUserValues($this->uid);
 
 			// Delete user files in /data/
 			\OC_Helper::rmdirr(\OC_User::getHome($this->uid));
diff --git a/lib/public/config.php b/lib/public/config.php
index fc4df3f7567..70ff3a3fed0 100644
--- a/lib/public/config.php
+++ b/lib/public/config.php
@@ -96,7 +96,7 @@ class Config {
 	 * not exist the default value will be returned
 	 */
 	public static function getAppValue( $app, $key, $default = null ) {
-		return \OC_Appconfig::getValue( $app, $key, $default );
+		return \OC::$server->getConfig()->getAppValue( $app, $key, $default );
 	}
 
 	/**
@@ -111,7 +111,7 @@ class Config {
 	 */
 	public static function setAppValue( $app, $key, $value ) {
 		try {
-			\OC_Appconfig::setValue( $app, $key, $value );
+			\OC::$server->getConfig()->setAppValue( $app, $key, $value );
 		} catch (\Exception $e) {
 			return false;
 		}
diff --git a/settings/ajax/lostpassword.php b/settings/ajax/lostpassword.php
index 395ba31f92b..b0fb20c4a7e 100644
--- a/settings/ajax/lostpassword.php
+++ b/settings/ajax/lostpassword.php
@@ -8,7 +8,7 @@ $l = \OC::$server->getL10N('settings');
 // Get data
 if( isset( $_POST['email'] ) && OC_Mail::validateAddress($_POST['email']) ) {
 	$email=trim($_POST['email']);
-	OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email);
+	\OC::$server->getConfig()->setUserValue(OC_User::getUser(), 'settings', 'email', $email);
 	OC_JSON::success(array("data" => array( "message" => $l->t("Email saved") )));
 }else{
 	OC_JSON::error(array("data" => array( "message" => $l->t("Invalid email") )));
diff --git a/settings/ajax/setlanguage.php b/settings/ajax/setlanguage.php
index a3988db85bb..a83212927bf 100644
--- a/settings/ajax/setlanguage.php
+++ b/settings/ajax/setlanguage.php
@@ -11,7 +11,7 @@ if( isset( $_POST['lang'] ) ) {
 	$languageCodes=OC_L10N::findAvailableLanguages();
 	$lang=$_POST['lang'];
 	if(array_search($lang, $languageCodes) or $lang === 'en') {
-		OC_Preferences::setValue( OC_User::getUser(), 'core', 'lang', $lang );
+		\OC::$server->getConfig()->setUserValue( OC_User::getUser(), 'core', 'lang', $lang );
 		OC_JSON::success(array("data" => array( "message" => $l->t("Language changed") )));
 	}else{
 		OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") )));
diff --git a/settings/ajax/setquota.php b/settings/ajax/setquota.php
index f19506a0456..64a686e83d7 100644
--- a/settings/ajax/setquota.php
+++ b/settings/ajax/setquota.php
@@ -27,7 +27,7 @@ if($quota !== 'none' and $quota !== 'default') {
 
 // Return Success story
 if($username) {
-	OC_Preferences::setValue($username, 'files', 'quota', $quota);
+	\OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
 }else{//set the default quota when no username is specified
 	if($quota === 'default') {//'default' as default quota makes no sense
 		$quota='none';
diff --git a/settings/personal.php b/settings/personal.php
index bef800ae7f1..f181c9cb2c1 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -9,6 +9,7 @@ OC_Util::checkLoggedIn();
 
 $defaults = new OC_Defaults(); // initialize themable default strings and urls
 $certificateManager = \OC::$server->getCertificateManager();
+$config = \OC::$server->getConfig();
 
 // Highlight navigation entry
 OC_Util::addScript( 'settings', 'personal' );
@@ -16,7 +17,7 @@ OC_Util::addStyle( 'settings', 'settings' );
 \OC_Util::addVendorScript('strengthify/jquery.strengthify');
 \OC_Util::addVendorStyle('strengthify/strengthify');
 \OC_Util::addScript('files', 'jquery.fileupload');
-if (\OC_Config::getValue('enable_avatars', true) === true) {
+if ($config->getSystemValue('enable_avatars', true) === true) {
 	\OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');
 	\OC_Util::addVendorStyle('jcrop/css/jquery.Jcrop');
 }
@@ -26,9 +27,9 @@ OC_App::setActiveNavigationEntry( 'personal' );
 
 $storageInfo=OC_Helper::getStorageInfo('/');
 
-$email=OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
+$email=$config->getUserValue(OC_User::getUser(), 'settings', 'email', '');
 
-$userLang=OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
+$userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
 $languageCodes=OC_L10N::findAvailableLanguages();
 
 //check if encryption was enabled in the past
@@ -74,9 +75,9 @@ usort( $languages, function ($a, $b) {
 
 //links to clients
 $clients = array(
-	'desktop' => OC_Config::getValue('customclient_desktop', $defaults->getSyncClientUrl()),
-	'android' => OC_Config::getValue('customclient_android', $defaults->getAndroidClientUrl()),
-	'ios'     => OC_Config::getValue('customclient_ios', $defaults->getiOSClientUrl())
+	'desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()),
+	'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()),
+	'ios'     => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl())
 );
 
 // Return template
@@ -95,7 +96,7 @@ $tmpl->assign('displayName', OC_User::getDisplayName());
 $tmpl->assign('enableDecryptAll' , $enableDecryptAll);
 $tmpl->assign('backupKeysExists' , $backupKeysExists);
 $tmpl->assign('filesStillEncrypted' , $filesStillEncrypted);
-$tmpl->assign('enableAvatars', \OC_Config::getValue('enable_avatars', true));
+$tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true));
 $tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
 $tmpl->assign('certs', $certificateManager->listCertificates());
 
diff --git a/settings/users.php b/settings/users.php
index 85f160a1552..3da8017b883 100644
--- a/settings/users.php
+++ b/settings/users.php
@@ -21,6 +21,8 @@ $users = array();
 $userManager = \OC_User::getManager();
 $groupManager = \OC_Group::getManager();
 
+$config = \OC::$server->getConfig();
+
 $isAdmin = OC_User::isAdminUser(OC_User::getUser());
 
 $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isAdmin, $groupManager);
@@ -28,7 +30,7 @@ $groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT);
 list($adminGroup, $groups) = $groupsInfo->get();
 
 $recoveryAdminEnabled = OC_App::isEnabled('files_encryption') &&
-					    OC_Appconfig::getValue( 'files_encryption', 'recoveryAdminEnabled' );
+					    $config->getAppValue( 'files_encryption', 'recoveryAdminEnabled', null );
 
 if($isAdmin) {
 	$accessibleUsers = OC_User::getDisplayNames('', 30);
@@ -59,7 +61,7 @@ $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
 
 // load users and quota
 foreach($accessibleUsers as $uid => $displayName) {
-	$quota = OC_Preferences::getValue($uid, 'files', 'quota', 'default');
+	$quota = $config->getUserValue($uid, 'files', 'quota', 'default');
 	$isQuotaUserDefined = array_search($quota, $quotaPreset) === false
 		&& array_search($quota, array('none', 'default')) === false;
 
diff --git a/status.php b/status.php
index db5813814d0..f7bdfe1fd51 100644
--- a/status.php
+++ b/status.php
@@ -25,8 +25,10 @@ try {
 
 	require_once 'lib/base.php';
 
-	$installed = OC_Config::getValue('installed') == 1;
-	$maintenance = OC_Config::getValue('maintenance', false);
+	$systemConfig = \OC::$server->getSystemConfig();
+
+	$installed = $systemConfig->getValue('installed') == 1;
+	$maintenance = $systemConfig->getValue('maintenance', false);
 	$values=array(
 		'installed'=>$installed,
 		'maintenance' => $maintenance,
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php
index 9f3bd8824f7..8b5f41fc94c 100644
--- a/tests/lib/helperstorage.php
+++ b/tests/lib/helperstorage.php
@@ -45,7 +45,7 @@ class Test_Helper_Storage extends \Test\TestCase {
 
 		\OC_User::setUserId('');
 		\OC_User::deleteUser($this->user);
-		\OC_Preferences::deleteUser($this->user);
+		\OC::$server->getConfig()->deleteAllUserValues($this->user);
 
 		parent::tearDown();
 	}
diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php
index 8d9d024197c..aa1ea5841c0 100644
--- a/tests/lib/user/session.php
+++ b/tests/lib/user/session.php
@@ -234,7 +234,7 @@ class Session extends \Test\TestCase {
 
 		//prepare login token
 		$token = 'goodToken';
-		\OC_Preferences::setValue('foo', 'login_token', $token, time());
+		\OC::$server->getConfig()->setUserValue('foo', 'login_token', $token, time());
 
 		$userSession = $this->getMock(
 			'\OC\User\Session',
@@ -282,7 +282,7 @@ class Session extends \Test\TestCase {
 
 		//prepare login token
 		$token = 'goodToken';
-		\OC_Preferences::setValue('foo', 'login_token', $token, time());
+		\OC::$server->getConfig()->setUserValue('foo', 'login_token', $token, time());
 
 		$userSession = new \OC\User\Session($manager, $session);
 		$granted = $userSession->loginWithCookie('foo', 'badToken');
@@ -323,7 +323,7 @@ class Session extends \Test\TestCase {
 
 		//prepare login token
 		$token = 'goodToken';
-		\OC_Preferences::setValue('foo', 'login_token', $token, time());
+		\OC::$server->getConfig()->setUserValue('foo', 'login_token', $token, time());
 
 		$userSession = new \OC\User\Session($manager, $session);
 		$granted = $userSession->loginWithCookie('foo', $token);
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 1ddbd2aba2b..3bb4b47c09c 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -152,7 +152,7 @@ class Test_Util extends \Test\TestCase {
 	function testHomeStorageWrapperWithoutQuota() {
 		$user1 = $this->getUniqueID();
 		\OC_User::createUser($user1, 'test');
-		OC_Preferences::setValue($user1, 'files', 'quota', 'none');
+		\OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', 'none');
 		\OC_User::setUserId($user1);
 
 		\OC_Util::setupFS($user1);
@@ -164,7 +164,7 @@ class Test_Util extends \Test\TestCase {
 		// clean up
 		\OC_User::setUserId('');
 		\OC_User::deleteUser($user1);
-		OC_Preferences::deleteUser($user1);
+		\OC::$server->getConfig()->deleteAllUserValues($user1);
 		\OC_Util::tearDownFS();
 	}
 
@@ -174,7 +174,7 @@ class Test_Util extends \Test\TestCase {
 	function testHomeStorageWrapperWithQuota() {
 		$user1 = $this->getUniqueID();
 		\OC_User::createUser($user1, 'test');
-		OC_Preferences::setValue($user1, 'files', 'quota', '1024');
+		\OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', '1024');
 		\OC_User::setUserId($user1);
 
 		\OC_Util::setupFS($user1);
@@ -191,7 +191,7 @@ class Test_Util extends \Test\TestCase {
 		// clean up
 		\OC_User::setUserId('');
 		\OC_User::deleteUser($user1);
-		OC_Preferences::deleteUser($user1);
+		\OC::$server->getConfig()->deleteAllUserValues($user1);
 		\OC_Util::tearDownFS();
 	}
 
-- 
GitLab