/** * @param CAccount $oAccount * @param string $sAuthType * @param int $iDataType * @param string $sDataValue * @return bool */ public function UpdateAccount(CAccount &$oAccount, $sAuthType, $iDataType, $sDataValue) { $bResult = false; try { if ($oAccount->Validate()) { $this->oStorage->UpdateAccount($oAccount, $sAuthType, $iDataType, $sDataValue); } $bResult = true; } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }
/** * @param CAccount &$oAccount * @return bool */ public function UpdateAccount(CAccount &$oAccount, $sDefaultIdentity = 0) { $bResult = false; try { if ($oAccount->Validate()) { $oAccount->IncomingMailUseSSL = in_array($oAccount->IncomingMailPort, array(993, 995)); $oAccount->OutgoingMailUseSSL = in_array($oAccount->OutgoingMailPort, array(465)); if (0 < $oAccount->Domain->IdTenant && CApi::GetConf('tenant', false) && null !== $oAccount->GetObsoleteValue('StorageQuota')) { /* @var $oTenantsApi CApiTenantsManager */ $oTenantsApi = CApi::Manager('tenants'); if ($oTenantsApi) { /* @var $oTenant CTenant */ $oTenant = $oTenantsApi->GetTenantById($oAccount->Domain->IdTenant); if (!$oTenant) { throw new CApiManagerException(Errs::TenantsManager_TenantDoesNotExist); } else { $this->validateAccountSubscriptionLimits($oAccount, $oTenant, false); if (0 < $oTenant->QuotaInMB) { $iAccountStorageQuota = $oAccount->GetObsoleteValue('StorageQuota'); $iSize = $oTenantsApi->GetTenantAllocatedSize($oTenant->IdTenant); $iSize -= (int) ($iAccountStorageQuota / 1024); if ((int) ($oAccount->RealQuotaSize() / 1024) + $iSize > $oTenant->QuotaInMB) { throw new CApiManagerException(Errs::TenantsManager_QuotaLimitExided); } } } } } if (trim($oAccount->SocialEmail) !== '') { $oDefaultAccount = $this->GetAccountOnLogin($oAccount->SocialEmail); if ($oDefaultAccount) { throw new CApiManagerException(Errs::UserManager_SocialAccountAlreadyExists); } else { $oSocialAccount = $this->GetAccountBySocialEmail($oAccount->SocialEmail); if ($oSocialAccount && $oAccount->IdAccount !== $oSocialAccount->IdAccount) { throw new CApiManagerException(Errs::UserManager_SocialAccountAlreadyExists); } } } $bUseOnlyHookUpdate = false; CApi::Plugin()->RunHook('api-update-account', array(&$oAccount, &$bUseOnlyHookUpdate)); if (!$bUseOnlyHookUpdate) { if (!$this->oStorage->UpdateAccount($oAccount)) { $this->moveStorageExceptionToManager(); throw new CApiManagerException(Errs::UserManager_AccountUpdateFailed); } } if ($oAccount->IsDefaultAccount && 0 < $oAccount->User->IdHelpdeskUser) { /* @var $oApiHelpdeskManager CApiHelpdeskManager */ $oApiHelpdeskManager = CApi::Manager('helpdesk'); if ($oApiHelpdeskManager) { $oHelpdeskUser = $oApiHelpdeskManager->GetUserById($oAccount->IdTenant, $oAccount->User->IdHelpdeskUser); if ($oHelpdeskUser) { $oHelpdeskUser->MailNotifications = $oAccount->User->AllowHelpdeskNotifications; $oHelpdeskUser->Name = $oAccount->FriendlyName; $oApiHelpdeskManager->UpdateUser($oHelpdeskUser); } } } if ($oAccount->IsDefaultAccount && (null !== $oAccount->GetObsoleteValue('FriendlyName') && $oAccount->GetObsoleteValue('FriendlyName') !== $oAccount->FriendlyName || null !== $oAccount->GetObsoleteValue('HideInGAB') && $oAccount->GetObsoleteValue('HideInGAB') !== $oAccount->HideInGAB)) { /* @var $oApiGContactsManager CApiGcontactsManager */ $oApiGContactsManager = CApi::Manager('gcontacts'); if ($oApiGContactsManager) { $oContact = $oApiGContactsManager->GetContactByTypeId($oAccount, $oAccount->IdUser, true); if ($oContact) { $oContact->FullName = $oAccount->FriendlyName; $oContact->HideInGAB = !!$oAccount->HideInGAB; $oApiGContactsManager->UpdateContact($oContact); } } } if ($sDefaultIdentity) { $this->oStorage->UpdateIdentitiesDefaults(null, $oAccount->IdAccount); //TODO remove this from there } $bResult = true; } } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }