$config = \OC::$server->getConfig();
$softQuota = true;
- $quota = $config->getUserValue($user, 'files', 'quota', null);
+ $quota = \OC::$server->getUserManager()->get($user)->getQuota();
$view = new \OC\Files\View('/' . $user);
- if ($quota === null || $quota === 'default') {
- $quota = $config->getAppValue('files', 'default_quota', null);
- }
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
$versionsFileview = new \OC\Files\View('/'.$uid.'/files_versions');
// get available disk space for user
+ $user = \OC::$server->getUserManager()->get($uid);
$softQuota = true;
- $quota = $config->getUserValue($uid, 'files', 'quota', null);
- if ( $quota === null || $quota === 'default') {
- $quota = $config->getAppValue('files', 'default_quota', null);
- }
+ $quota = $user->getQuota();
if ( $quota === null || $quota === 'none' ) {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
$quota = \OCP\Util::humanFileSize($quota);
}
}
- $this->config->setUserValue($targetUserId, 'files', 'quota', $quota);
+ $targetUser->setQuota($quota);
break;
case 'password':
$targetUser->setPassword($parameters['_put']['value']);
}
}
if(!is_null($quota)) {
- $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
+ $user = $this->userManager->get($this->uid)->setQuota($quota);
}
}
$userSession->listen('\OC\User', 'logout', function () {
\OC_Hook::emit('OC_User', 'logout', array());
});
- $userSession->listen('\OC\User', 'changeUser', function ($user) {
+ $userSession->listen('\OC\User', 'changeUser', function ($user, $feature) {
/** @var $user \OC\User\User */
- \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user));
+ \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature));
});
return $userSession;
});
namespace OC\User;
use OC\Hooks\Emitter;
+use OC_Helper;
use OCP\IAvatarManager;
use OCP\IImage;
use OCP\IURLGenerator;
$result = $this->backend->setDisplayName($this->uid, $displayName);
if ($result) {
$this->displayName = $displayName;
- $this->triggerChange();
+ $this->triggerChange('displayName');
}
return $result !== false;
} else {
} else {
$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
}
- $this->triggerChange();
+ $this->triggerChange('eMailAddress');
}
/**
return $this->config->getUserValue($this->uid, 'settings', 'email', null);
}
+ /**
+ * get the users' quota
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getQuota() {
+ $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
+ if($quota === 'default') {
+ $quota = $this->config->getAppValue('files', 'default_quota', 'none');
+ }
+ return $quota;
+ }
+
+ /**
+ * set the users' quota
+ *
+ * @param string $quota
+ * @return void
+ * @since 9.0.0
+ */
+ public function setQuota($quota) {
+ if($quota !== 'none' and $quota !== 'default') {
+ $quota= OC_Helper::computerFileSize($quota);
+ $quota=OC_Helper::humanFileSize($quota);
+ }
+ $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
+ $this->triggerChange('quota');
+ }
+
/**
* get the avatar image if it exists
*
return $url;
}
- public function triggerChange() {
+ public function triggerChange($feature) {
if ($this->emitter) {
- $this->emitter->emit('\OC\User', 'changeUser', array($this));
+ $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature));
}
}
* @return int Quota bytes
*/
public static function getUserQuota($user) {
- $config = \OC::$server->getConfig();
- $userQuota = $config->getUserValue($user, 'files', 'quota', 'default');
- if ($userQuota === 'default') {
- $userQuota = $config->getAppValue('files', 'default_quota', 'none');
- }
+ $userQuota = \OC::$server->getUserManager()->get($user)->getQuota();
if($userQuota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
}else{
* @since 9.0.0
*/
public function setEMailAddress($mailAddress);
+
+ /**
+ * get the users' quota
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getQuota();
+
+ /**
+ * set the users' quota
+ *
+ * @param string $quota
+ * @return void
+ * @since 9.0.0
+ */
+ public function setQuota($quota);
}
// Return Success story
if($username) {
- \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
+ $targetUserObject->setQuota($quota);
}else{//set the default quota when no username is specified
if($quota === 'default') {//'default' as default quota makes no sense
$quota='none';
'displayname' => $user->getDisplayName(),
'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
'subadmin' => $subAdminGroups,
- 'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'),
+ 'quota' => $user->getQuota(),
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin() * 1000,
'backend' => $user->getBackendClassName(),