diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index a6b7555b37..f26eefa30e 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 42a7e20c87..2b4a50d6e2 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 8d9aba423c..2d58db2128 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 661fc271df..b9d7a4aa6c 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 82e0ecc3e2..3d30ada863 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 141657fe09..af2474c7d7 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 ea919006f9..e20f369825 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 3ced0af8ee..552aa96a26 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 2f704fb2b3..342d3d5057 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 94abaca3e7..277aa1a047 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 fb66f893c6..00ded84f95 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 fc4df3f756..70ff3a3fed 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 395ba31f92..b0fb20c4a7 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 a3988db85b..a83212927b 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 f19506a045..64a686e83d 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 bef800ae7f..f181c9cb2c 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 85f160a155..3da8017b88 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 db5813814d..f7bdfe1fd5 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 9f3bd8824f..8b5f41fc94 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 8d9d024197..aa1ea5841c 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 1ddbd2aba2..3bb4b47c09 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(); }