mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Improved Settings handling to prevent bugs in outer code
This commit is contained in:
parent
c6aad25581
commit
007e4b25eb
10 changed files with 50 additions and 44 deletions
|
|
@ -192,7 +192,7 @@ trait Folders
|
||||||
|
|
||||||
$oSettingsLocal->SetConf('CheckableFolder', \json_encode(\array_unique($aCheckableFolder)));
|
$oSettingsLocal->SetConf('CheckableFolder', \json_encode(\array_unique($aCheckableFolder)));
|
||||||
|
|
||||||
return $this->DefaultResponse($this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
|
return $this->DefaultResponse($oSettingsLocal->save());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -320,7 +320,7 @@ trait Folders
|
||||||
$oSettingsLocal->SetConf('TrashFolder', $this->GetActionParam('trash', ''));
|
$oSettingsLocal->SetConf('TrashFolder', $this->GetActionParam('trash', ''));
|
||||||
$oSettingsLocal->SetConf('ArchiveFolder', $this->GetActionParam('archive', ''));
|
$oSettingsLocal->SetConf('ArchiveFolder', $this->GetActionParam('archive', ''));
|
||||||
|
|
||||||
return $this->DefaultResponse($this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
|
return $this->DefaultResponse($oSettingsLocal->save());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DoFolderACL() : array
|
public function DoFolderACL() : array
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ trait Themes
|
||||||
|
|
||||||
$oSettings->SetConf('UserBackgroundName', $sName);
|
$oSettings->SetConf('UserBackgroundName', $sName);
|
||||||
$oSettings->SetConf('UserBackgroundHash', $sHash);
|
$oSettings->SetConf('UserBackgroundHash', $sHash);
|
||||||
$this->SettingsProvider()->Save($oAccount, $oSettings);
|
$oSettings->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ trait User
|
||||||
|
|
||||||
if ($sCurrentLanguage !== $sLanguage) {
|
if ($sCurrentLanguage !== $sLanguage) {
|
||||||
$oSettings->SetConf('language', $sLanguage);
|
$oSettings->SetConf('language', $sLanguage);
|
||||||
$this->SettingsProvider()->Save($oAccount, $oSettings);
|
$oSettings->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -219,8 +219,7 @@ trait User
|
||||||
$this->setSettingsFromParams($oSettingsLocal, 'ShowUnreadCount', 'bool');
|
$this->setSettingsFromParams($oSettingsLocal, 'ShowUnreadCount', 'bool');
|
||||||
$this->setSettingsFromParams($oSettingsLocal, 'CheckMailInterval', 'int');
|
$this->setSettingsFromParams($oSettingsLocal, 'CheckMailInterval', 'int');
|
||||||
|
|
||||||
return $this->DefaultResponse($this->SettingsProvider()->Save($oAccount, $oSettings) &&
|
return $this->DefaultResponse($oSettings->save() && $oSettingsLocal->save());
|
||||||
$this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DoQuota() : array
|
public function DoQuota() : array
|
||||||
|
|
@ -263,12 +262,11 @@ trait User
|
||||||
|
|
||||||
public function DoClearUserBackground() : array
|
public function DoClearUserBackground() : array
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken();
|
|
||||||
|
|
||||||
if (!$this->GetCapa(Capa::USER_BACKGROUND)) {
|
if (!$this->GetCapa(Capa::USER_BACKGROUND)) {
|
||||||
return $this->FalseResponse();
|
return $this->FalseResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oAccount = $this->getAccountFromToken();
|
||||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||||
if ($oAccount && $oSettings) {
|
if ($oAccount && $oSettings) {
|
||||||
$this->StorageProvider()->Clear($oAccount,
|
$this->StorageProvider()->Clear($oAccount,
|
||||||
|
|
@ -280,8 +278,7 @@ trait User
|
||||||
$oSettings->SetConf('UserBackgroundHash', '');
|
$oSettings->SetConf('UserBackgroundHash', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse($oAccount && $oSettings ?
|
return $this->DefaultResponse($oAccount && $oSettings ? $oSettings->save() : false);
|
||||||
$this->SettingsProvider()->Save($oAccount, $oSettings) : false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setSettingsFromParams(\RainLoop\Settings $oSettings, string $sConfigName, string $sType = 'string', ?callable $cCallback = null) : void
|
private function setSettingsFromParams(\RainLoop\Settings $oSettings, string $sConfigName, string $sType = 'string', ?callable $cCallback = null) : void
|
||||||
|
|
|
||||||
|
|
@ -419,7 +419,7 @@ class Manager
|
||||||
$aData[$sPluginName] = $aPluginSettings;
|
$aData[$sPluginName] = $aPluginSettings;
|
||||||
$oSettings->SetConf('Plugins',$aData);
|
$oSettings->SetConf('Plugins',$aData);
|
||||||
|
|
||||||
return $this->oActions->SettingsProvider()->Save($oAccount, $oSettings);
|
return $oSettings->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,8 @@ abstract class AbstractProvider
|
||||||
{
|
{
|
||||||
use \MailSo\Log\Inherit;
|
use \MailSo\Log\Inherit;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \RainLoop\Model\Account
|
|
||||||
*/
|
|
||||||
protected $oAccount;
|
|
||||||
|
|
||||||
public function IsActive() : bool
|
public function IsActive() : bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetAccount(\RainLoop\Model\Account $oAccount)
|
|
||||||
{
|
|
||||||
$this->oAccount = $oAccount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,30 @@
|
||||||
|
|
||||||
namespace RainLoop\Providers;
|
namespace RainLoop\Providers;
|
||||||
|
|
||||||
|
use RainLoop\Model\Account;
|
||||||
|
use RainLoop\Providers\Settings\ISettings;
|
||||||
|
|
||||||
class Settings extends \RainLoop\Providers\AbstractProvider
|
class Settings extends \RainLoop\Providers\AbstractProvider
|
||||||
{
|
{
|
||||||
/**
|
private ISettings $oDriver;
|
||||||
* @var \RainLoop\Providers\Settings\ISettings
|
|
||||||
*/
|
|
||||||
private $oDriver;
|
|
||||||
|
|
||||||
public function __construct(\RainLoop\Providers\Settings\ISettings $oDriver)
|
public function __construct(ISettings $oDriver)
|
||||||
{
|
{
|
||||||
$this->oDriver = $oDriver;
|
$this->oDriver = $oDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Load(\RainLoop\Model\Account $oAccount) : \RainLoop\Settings
|
public function Load(Account $oAccount) : \RainLoop\Settings
|
||||||
{
|
{
|
||||||
return new \RainLoop\Settings($this->oDriver->Load($oAccount));
|
return new \RainLoop\Settings($this, $oAccount, $this->oDriver->Load($oAccount));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Save(\RainLoop\Model\Account $oAccount, \RainLoop\Settings $oSettings) : bool
|
public function Save(Account $oAccount, \RainLoop\Settings $oSettings) : bool
|
||||||
{
|
{
|
||||||
return $this->oDriver->Save($oAccount, $oSettings);
|
return $this->oDriver->Save($oAccount, $oSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsActive() : bool
|
public function IsActive() : bool
|
||||||
{
|
{
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\Settings\ISettings;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,26 @@
|
||||||
|
|
||||||
namespace RainLoop\Providers\Settings;
|
namespace RainLoop\Providers\Settings;
|
||||||
|
|
||||||
|
use RainLoop\Model\Account;
|
||||||
|
use RainLoop\Providers\Storage;
|
||||||
|
use RainLoop\Providers\Storage\Enumerations\StorageType;
|
||||||
|
|
||||||
class DefaultSettings implements ISettings
|
class DefaultSettings implements ISettings
|
||||||
{
|
{
|
||||||
const FILE_NAME = 'settings';
|
const FILE_NAME = 'settings';
|
||||||
const FILE_NAME_LOCAL = 'settings_local';
|
const FILE_NAME_LOCAL = 'settings_local';
|
||||||
|
|
||||||
/**
|
private Storage $oStorageProvider;
|
||||||
* @var \RainLoop\Providers\Storage
|
|
||||||
*/
|
|
||||||
private $oStorageProvider;
|
|
||||||
|
|
||||||
public function __construct(\RainLoop\Providers\Storage $oStorageProvider)
|
public function __construct(Storage $oStorageProvider)
|
||||||
{
|
{
|
||||||
$this->oStorageProvider = $oStorageProvider;
|
$this->oStorageProvider = $oStorageProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Load(\RainLoop\Model\Account $oAccount) : array
|
public function Load(Account $oAccount) : array
|
||||||
{
|
{
|
||||||
$sValue = $this->oStorageProvider->Get($oAccount,
|
$sValue = $this->oStorageProvider->Get($oAccount,
|
||||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
StorageType::CONFIG,
|
||||||
$this->oStorageProvider->IsLocal() ?
|
$this->oStorageProvider->IsLocal() ?
|
||||||
self::FILE_NAME_LOCAL :
|
self::FILE_NAME_LOCAL :
|
||||||
self::FILE_NAME
|
self::FILE_NAME
|
||||||
|
|
@ -36,20 +37,20 @@ class DefaultSettings implements ISettings
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Save(\RainLoop\Model\Account $oAccount, \RainLoop\Settings $oSettings) : bool
|
public function Save(Account $oAccount, \RainLoop\Settings $oSettings) : bool
|
||||||
{
|
{
|
||||||
return $this->oStorageProvider->Put($oAccount,
|
return $this->oStorageProvider->Put($oAccount,
|
||||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
StorageType::CONFIG,
|
||||||
$this->oStorageProvider->IsLocal() ?
|
$this->oStorageProvider->IsLocal() ?
|
||||||
self::FILE_NAME_LOCAL :
|
self::FILE_NAME_LOCAL :
|
||||||
self::FILE_NAME,
|
self::FILE_NAME,
|
||||||
\json_encode($oSettings));
|
\json_encode($oSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Delete(\RainLoop\Model\Account $oAccount) : bool
|
public function Delete(Account $oAccount) : bool
|
||||||
{
|
{
|
||||||
return $this->oStorageProvider->Clear($oAccount,
|
return $this->oStorageProvider->Clear($oAccount,
|
||||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
StorageType::CONFIG,
|
||||||
$this->oStorageProvider->IsLocal() ?
|
$this->oStorageProvider->IsLocal() ?
|
||||||
self::FILE_NAME_LOCAL :
|
self::FILE_NAME_LOCAL :
|
||||||
self::FILE_NAME);
|
self::FILE_NAME);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
namespace RainLoop\Providers\Storage\Enumerations;
|
namespace RainLoop\Providers\Storage\Enumerations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 8.1
|
||||||
|
enum StorageType: int {
|
||||||
|
case USER = 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
class StorageType
|
class StorageType
|
||||||
{
|
{
|
||||||
const USER = 1;
|
const USER = 1;
|
||||||
|
|
|
||||||
|
|
@ -588,7 +588,7 @@ class ServiceActions
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bNeedToSettings) {
|
if ($bNeedToSettings) {
|
||||||
$this->SettingsProvider()->Save($oAccount, $oSettings);
|
$oSettings->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,16 @@
|
||||||
|
|
||||||
namespace RainLoop;
|
namespace RainLoop;
|
||||||
|
|
||||||
|
use RainLoop\Model\Account;
|
||||||
|
use RainLoop\Providers\Settings as SettingsProvider;
|
||||||
|
|
||||||
class Settings implements \JsonSerializable
|
class Settings implements \JsonSerializable
|
||||||
{
|
{
|
||||||
protected array $aData = array();
|
protected array $aData;
|
||||||
|
protected Account $oAccount;
|
||||||
|
protected SettingsProvider $oProvider;
|
||||||
|
|
||||||
public function __construct(array $aData)
|
public function __construct(SettingsProvider $oProvider, Account $oAccount, array $aData)
|
||||||
{
|
{
|
||||||
if (isset($aData['SpamFolder']) && !isset($aData['JunkFolder'])) {
|
if (isset($aData['SpamFolder']) && !isset($aData['JunkFolder'])) {
|
||||||
$aData['JunkFolder'] = $aData['SpamFolder'];
|
$aData['JunkFolder'] = $aData['SpamFolder'];
|
||||||
|
|
@ -19,6 +24,13 @@ class Settings implements \JsonSerializable
|
||||||
unset($aData['Language']);
|
unset($aData['Language']);
|
||||||
}
|
}
|
||||||
$this->aData = $aData;
|
$this->aData = $aData;
|
||||||
|
$this->oAccount = $oAccount;
|
||||||
|
$this->oProvider = $oProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() : bool
|
||||||
|
{
|
||||||
|
return $this->oProvider->Save($this->oAccount, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray() : array
|
public function toArray() : array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue