Additional accounts storage optimization

This commit is contained in:
RainLoop Team 2014-02-04 19:52:58 +04:00
parent cdd1a8e778
commit 23ddda9194
6 changed files with 93 additions and 53 deletions

View file

@ -221,14 +221,6 @@ AdminApp.prototype.bootstart = function ()
// } // }
kn.startScreens([AdminSettingsScreen]); kn.startScreens([AdminSettingsScreen]);
// if (!Globals.bMobileDevice)
// {
// _.defer(function () {
// Utils.initLayoutResizer('#rl-top-resizer-left', '#rl-top-resizer-right', '#rl-center',
// 120, 300, 200, 600, Enums.ClientSideKeyName.FolderListSize);
// });
// }
} }
else else
{ {

View file

@ -40,7 +40,6 @@ SettingsAccounts.prototype.addNewAccount = function ()
}; };
/** /**
*
* @param {AccountModel} oAccountToRemove * @param {AccountModel} oAccountToRemove
*/ */
SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove) SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove)
@ -59,8 +58,24 @@ SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove)
{ {
this.accounts.remove(fRemoveAccount); this.accounts.remove(fRemoveAccount);
RL.remote().accountDelete(function () { RL.remote().accountDelete(function (sResult, oData) {
RL.accountsAndIdentities();
if (Enums.StorageResultType.Success === sResult && oData &&
oData.Result && oData.Reload)
{
kn.routeOff();
kn.setHash(RL.link().root(), true);
kn.routeOff();
_.defer(function () {
window.location.reload();
});
}
else
{
RL.accountsAndIdentities();
}
}, oAccountToRemove.email); }, oAccountToRemove.email);
} }
} }

View file

@ -1260,12 +1260,12 @@ class Actions
*/ */
public function AuthProcess($oAccount) public function AuthProcess($oAccount)
{ {
$this->SetAuthToken($oAccount);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
$this->SetAuthToken($oAccount);
$aAccounts = $this->GetAccounts($oAccount); $aAccounts = $this->GetAccounts($oAccount);
if (isset($aAccounts[$oAccount->Email()])) if (\is_array($aAccounts) && isset($aAccounts[$oAccount->Email()]))
{ {
$aAccounts[$oAccount->Email()] = $oAccount->GetAuthToken(); $aAccounts[$oAccount->Email()] = $oAccount->GetAuthToken();
$this->SetAccounts($oAccount, $aAccounts); $this->SetAccounts($oAccount, $aAccounts);
@ -1389,15 +1389,23 @@ class Actions
{ {
$sParentEmail = $oAccount->ParentEmailHelper(); $sParentEmail = $oAccount->ParentEmailHelper();
$sAccounts = $this->StorageProvider()->Get(null, if ($this->Config()->Get('webmail', 'allow_additional_accounts', true))
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'Webmail/Accounts/'.$sParentEmail.'/Array', null);
$aAccounts = $sAccounts ? @\unserialize($sAccounts) : array();
if (\is_array($aAccounts) && 0 < \count($aAccounts))
{ {
return $aAccounts; $sAccounts = $this->StorageProvider()->Get(null,
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'Webmail/Accounts/'.$sParentEmail.'/Array', null);
$aAccounts = $sAccounts ? @\unserialize($sAccounts) : array();
if (\is_array($aAccounts) && 0 < \count($aAccounts))
{
if (1 === \count($aAccounts))
{
$this->SetAccounts($oAccount, array());
}
return $aAccounts;
}
} }
$aAccounts = array(); $aAccounts = array();
@ -1459,7 +1467,8 @@ class Actions
public function SetAccounts($oAccount, $aAccounts = array()) public function SetAccounts($oAccount, $aAccounts = array())
{ {
$sParentEmail = $oAccount->ParentEmailHelper(); $sParentEmail = $oAccount->ParentEmailHelper();
if (!\is_array($aAccounts) || 0 === \count($aAccounts)) if (!\is_array($aAccounts) || 0 >= \count($aAccounts) ||
(1 === \count($aAccounts) && !empty($aAccounts[$sParentEmail])))
{ {
$this->StorageProvider()->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, $this->StorageProvider()->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
'Webmail/Accounts/'.$sParentEmail.'/Array'); 'Webmail/Accounts/'.$sParentEmail.'/Array');
@ -1566,7 +1575,7 @@ class Actions
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
$sParentEmail = 0 < \strlen($oAccount->ParentEmail()) ? $oAccount->ParentEmail() : $oAccount->Email(); $sParentEmail = $oAccount->ParentEmailHelper();
$sEmailToDelete = \strtolower(\trim($this->GetActionParam('EmailToDelete', ''))); $sEmailToDelete = \strtolower(\trim($this->GetActionParam('EmailToDelete', '')));
$aAccounts = $this->GetAccounts($oAccount); $aAccounts = $this->GetAccounts($oAccount);
@ -1575,13 +1584,18 @@ class Actions
{ {
unset($aAccounts[$sEmailToDelete]); unset($aAccounts[$sEmailToDelete]);
if (1 === count($aAccounts) && isset($aAccounts[$sParentEmail])) $oAccountToChange = null;
if ($oAccount->Email() === $sEmailToDelete && !empty($aAccounts[$sParentEmail]))
{ {
$aAccounts = array(); $oAccountToChange = $this->GetAccountFromCustomToken($aAccounts[$sParentEmail], false, false);
if ($oAccountToChange)
{
$this->AuthProcess($oAccountToChange);
}
} }
$this->SetAccounts($oAccount, $aAccounts); $this->SetAccounts($oAccount, $aAccounts);
return $this->TrueResponse(__FUNCTION__); return $this->TrueResponse(__FUNCTION__, array('Reload' => !!$oAccountToChange));
} }
return $this->FalseResponse(__FUNCTION__); return $this->FalseResponse(__FUNCTION__);
@ -5933,10 +5947,11 @@ class Actions
/** /**
* @param string $sActionName * @param string $sActionName
* @param mixed $mResult = false * @param mixed $mResult = false
* @param array $aAdditionalParams = array()
* *
* @return array * @return array
*/ */
private function mainDefaultResponse($sActionName, $mResult = false) private function mainDefaultResponse($sActionName, $mResult = false, $aAdditionalParams = array())
{ {
$sActionName = 'Do' === substr($sActionName, 0, 2) ? substr($sActionName, 2) : $sActionName; $sActionName = 'Do' === substr($sActionName, 0, 2) ? substr($sActionName, 2) : $sActionName;
@ -5945,32 +5960,42 @@ class Actions
'Result' => $this->responseObject($mResult, $sActionName) 'Result' => $this->responseObject($mResult, $sActionName)
); );
if (\is_array($aAdditionalParams))
{
foreach ($aAdditionalParams as $sKey => $mValue)
{
$aResult[$sKey] = $mValue;
}
}
return $aResult; return $aResult;
} }
/** /**
* @param string $sActionName * @param string $sActionName
* @param mixed $mResult = false * @param mixed $mResult = false
* @param array $aAdditionalParams = array()
* *
* @return array * @return array
*/ */
public function DefaultResponse($sActionName, $mResult = false) public function DefaultResponse($sActionName, $mResult = false, $aAdditionalParams = array())
{ {
$this->Plugins()->RunHook('main.default-response-date', array($sActionName, &$mResult)); $this->Plugins()->RunHook('main.default-response-data', array($sActionName, &$mResult));
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult); $aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem)); $this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem; return $aResponseItem;
} }
/** /**
* @param string $sActionName * @param string $sActionName
* @param array $aAdditionalParams = array()
* *
* @return array * @return array
*/ */
public function TrueResponse($sActionName) public function TrueResponse($sActionName, $aAdditionalParams = array())
{ {
$mResult = true; $mResult = true;
$this->Plugins()->RunHook('main.default-response-date', array($sActionName, &$mResult)); $this->Plugins()->RunHook('main.default-response-data', array($sActionName, &$mResult));
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult); $aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem)); $this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem; return $aResponseItem;
} }
@ -5986,18 +6011,19 @@ class Actions
{ {
$mResult = false; $mResult = false;
$this->Plugins() $this->Plugins()
->RunHook('main.default-response-date', array($sActionName, &$mResult)) ->RunHook('main.default-response-data', array($sActionName, &$mResult))
->RunHook('main.default-response-error-date', array($sActionName, &$iErrorCode, &$sErrorMessage)) ->RunHook('main.default-response-error-data', array($sActionName, &$iErrorCode, &$sErrorMessage))
; ;
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult); $aAdditionalParams = array();
if (null !== $iErrorCode) if (null !== $iErrorCode)
{ {
$aResponseItem['ErrorCode'] = (int) $iErrorCode; $aAdditionalParams['ErrorCode'] = (int) $iErrorCode;
$aResponseItem['ErrorMessage'] = null === $sErrorMessage ? '' : (string) $sErrorMessage; $aAdditionalParams['ErrorMessage'] = null === $sErrorMessage ? '' : (string) $sErrorMessage;
} }
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem)); $this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem; return $aResponseItem;
} }

View file

@ -7702,14 +7702,6 @@ AdminApp.prototype.bootstart = function ()
// } // }
kn.startScreens([AdminSettingsScreen]); kn.startScreens([AdminSettingsScreen]);
// if (!Globals.bMobileDevice)
// {
// _.defer(function () {
// Utils.initLayoutResizer('#rl-top-resizer-left', '#rl-top-resizer-right', '#rl-center',
// 120, 300, 200, 600, Enums.ClientSideKeyName.FolderListSize);
// });
// }
} }
else else
{ {

View file

@ -12929,7 +12929,6 @@ SettingsAccounts.prototype.addNewAccount = function ()
}; };
/** /**
*
* @param {AccountModel} oAccountToRemove * @param {AccountModel} oAccountToRemove
*/ */
SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove) SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove)
@ -12948,8 +12947,24 @@ SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove)
{ {
this.accounts.remove(fRemoveAccount); this.accounts.remove(fRemoveAccount);
RL.remote().accountDelete(function () { RL.remote().accountDelete(function (sResult, oData) {
RL.accountsAndIdentities();
if (Enums.StorageResultType.Success === sResult && oData &&
oData.Result && oData.Reload)
{
kn.routeOff();
kn.setHash(RL.link().root(), true);
kn.routeOff();
_.defer(function () {
window.location.reload();
});
}
else
{
RL.accountsAndIdentities();
}
}, oAccountToRemove.email); }, oAccountToRemove.email);
} }
} }

File diff suppressed because one or more lines are too long