mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Delete old domain setup files on save
This commit is contained in:
parent
4fd2f63c07
commit
b89f91f08a
1 changed files with 17 additions and 21 deletions
|
|
@ -90,15 +90,16 @@ class DefaultDomain implements DomainInterface
|
||||||
$aDomain = \json_decode(\file_get_contents($sRealFileBase.'.json'), true) ?: array();
|
$aDomain = \json_decode(\file_get_contents($sRealFileBase.'.json'), true) ?: array();
|
||||||
return \RainLoop\Model\Domain::fromArray($sName, $aDomain);
|
return \RainLoop\Model\Domain::fromArray($sName, $aDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\file_exists($sRealFileBase.'.ini')) {
|
if (\file_exists($sRealFileBase.'.ini')) {
|
||||||
$aDomain = \parse_ini_file($sRealFileBase.'.ini') ?: array();
|
$aDomain = \parse_ini_file($sRealFileBase.'.ini') ?: array();
|
||||||
return \RainLoop\Model\Domain::fromIniArray($sName, $aDomain);
|
return \RainLoop\Model\Domain::fromIniArray($sName, $aDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bCheckAliases && \file_exists($sRealFileBase.'.alias')) {
|
if ($bCheckAliases && \file_exists($sRealFileBase.'.alias')) {
|
||||||
$sAlias = \trim(\file_get_contents($sRealFileBase.'.alias'));
|
$sTarget = \trim(\file_get_contents($sRealFileBase.'.alias'));
|
||||||
if (!empty($sAlias)) {
|
if (!empty($sTarget)) {
|
||||||
$oDomain = $this->Load($sAlias, false, false, false);
|
$oDomain = $this->Load($sTarget, false, false, false);
|
||||||
$oDomain && $oDomain->SetAliasName($sName);
|
$oDomain && $oDomain->SetAliasName($sName);
|
||||||
return $oDomain;
|
return $oDomain;
|
||||||
}
|
}
|
||||||
|
|
@ -120,17 +121,19 @@ class DefaultDomain implements DomainInterface
|
||||||
|
|
||||||
public function Save(\RainLoop\Model\Domain $oDomain) : bool
|
public function Save(\RainLoop\Model\Domain $oDomain) : bool
|
||||||
{
|
{
|
||||||
|
$this->Delete($oDomain->Name());
|
||||||
$sRealFileName = static::encodeFileName($oDomain->Name());
|
$sRealFileName = static::encodeFileName($oDomain->Name());
|
||||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.json', \json_encode($oDomain, \JSON_PRETTY_PRINT));
|
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.json', \json_encode($oDomain, \JSON_PRETTY_PRINT));
|
||||||
$this->oCacher && $this->oCacher->Delete(static::CACHE_KEY);
|
$this->oCacher && $this->oCacher->Delete(static::CACHE_KEY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SaveAlias(string $sName, string $sAlias) : bool
|
public function SaveAlias(string $sName, string $sTarget) : bool
|
||||||
{
|
{
|
||||||
$sAlias = \strtolower(\idn_to_ascii($sAlias));
|
// $this->Delete($sName);
|
||||||
|
$sTarget = \strtolower(\idn_to_ascii($sTarget));
|
||||||
$sRealFileName = static::encodeFileName($sName);
|
$sRealFileName = static::encodeFileName($sName);
|
||||||
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sTarget);
|
||||||
$this->oCacher && $this->oCacher->Delete(static::CACHE_KEY);
|
$this->oCacher && $this->oCacher->Delete(static::CACHE_KEY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -169,21 +172,14 @@ class DefaultDomain implements DomainInterface
|
||||||
|
|
||||||
public function Delete(string $sName) : bool
|
public function Delete(string $sName) : bool
|
||||||
{
|
{
|
||||||
$bResult = 0 < \strlen($sName);
|
$bResult = true;
|
||||||
if ($bResult) {
|
if (\strlen($sName)) {
|
||||||
$sRealFileName = static::encodeFileName($sName);
|
$sRealFileName = $this->sDomainPath . '/' . static::encodeFileName($sName);
|
||||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.json')) {
|
$bResult =
|
||||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.json');
|
(!\file_exists($sRealFileName.'.json') || \unlink($sRealFileName.'.json'))
|
||||||
}
|
&& (!\file_exists($sRealFileName.'.ini') || \unlink($sRealFileName.'.ini'))
|
||||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini')) {
|
&& (!\file_exists($sRealFileName.'.alias') || \unlink($sRealFileName.'.alias'));
|
||||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
$this->Disable($sName, !$bResult);
|
||||||
}
|
|
||||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias')) {
|
|
||||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
|
|
||||||
}
|
|
||||||
if ($bResult) {
|
|
||||||
$this->Disable($sName, false);
|
|
||||||
}
|
|
||||||
if ($this->oCacher) {
|
if ($this->oCacher) {
|
||||||
$this->oCacher->Delete(static::CACHE_KEY);
|
$this->oCacher->Delete(static::CACHE_KEY);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue