Bugfix: demo plugin broken due to v2.9.6 changes

This commit is contained in:
djmaze 2021-12-15 13:06:30 +01:00
parent 0905787f5f
commit 41a98d68c5
4 changed files with 32 additions and 14 deletions

View file

@ -1,5 +1,7 @@
<?php
use RainLoop\Providers\Storage\Enumerations\StorageType;
class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
{
/**
@ -7,18 +9,36 @@ class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
*/
protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
{
if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
$sEmail = $sSubFolder = '';
if ($mAccount instanceof \RainLoop\Model\MainAccount) {
$sEmail = $mAccount->Email();
if (StorageType::SIGN_ME === $iStorageType) {
$sSubFolder = '/.sign_me';
} else if (StorageType::SESSION === $iStorageType) {
$sSubFolder = '/.sessions';
}
} else if (\is_string($mAccount)) {
$sEmail = $mAccount;
}
if ($sEmail != $this->sDemoEmail) {
return parent::generateFileName($mAccount, $iStorageType, $sKey, $bMkDir, $bForDeleteAction);
}
$sDataPath = "{$this->sDataPath}/demo";
if (\is_dir($sDataPath) && 0 === \random_int(0, 100)) {
\MailSo\Base\Utils::RecRmDir("{$this->sDataPath}/demo");
\MailSo\Base\Utils::RecTimeDirRemove($sDataPath, 3600 * 3); // 3 hours
}
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken());
$sDataPath .= '/' . \RainLoop\Utils::fixName(\RainLoop\Utils::GetConnectionToken()) . $sSubFolder;
\is_dir($sDataPath) || \mkdir($sDataPath, 0700, true);
return $sDataPath . '/' . ($sKey ? \RainLoop\Utils::fixName($sKey) : '');
}
private $sDemoEmail;
public function setDemoEmail(string $sEmail)
{
$this->sDemoEmail = $sEmail;
}
}