Improved demo mode plugin

This commit is contained in:
djmaze 2021-11-08 17:40:21 +01:00
parent 2f97d4bafb
commit 70f9f0bd76
4 changed files with 14 additions and 52 deletions

View file

@ -86,7 +86,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
*/
public function MainFabrica($sName, &$oDriver)
{
if (('storage' === $sName || 'storage-local' === $sName) && \function_exists('apcu_store')) {
if ('storage' === $sName || 'storage-local' === $sName) {
$oAccount = $this->Manager()->Actions()->GetAccount();
if ($this->isDemoAccount($oAccount)) {
require_once __DIR__ . '/storage.php';

View file

@ -2,56 +2,18 @@
class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
{
/**
* @param \RainLoop\Model\Account|string|null $oAccount
*/
public function Put($oAccount, int $iStorageType, string $sKey, string $sValue) : bool
{
return !!\apcu_store($this->generateFileName($oAccount, $iStorageType, $sKey, true), $sValue);
}
/**
* @param \RainLoop\Model\Account|string|null $oAccount
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($oAccount, int $iStorageType, string $sKey, $mDefault = false)
{
$bValue = false;
$mValue = \apcu_fetch($this->generateFileName($oAccount, $iStorageType, $sKey), $bValue);
if (!$bValue)
{
$mValue = $mDefault;
}
return $mValue;
}
/**
* @param \RainLoop\Model\Account|string|null $oAccount
*/
public function Clear($oAccount, int $iStorageType, string $sKey) : bool
{
\apcu_delete($this->generateFileName($oAccount, $iStorageType, $sKey));
return true;
}
/**
* @param \RainLoop\Model\Account|string $oAccount
*/
public function DeleteStorage($oAccount) : bool
{
return !!$oAccount;
}
/**
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false, bool $bForDeleteAction = false) : string
{
$sFileName = parent::generateFileName($mAccount, $iStorageType, $sKey, false, false);
return $sFileName.'/'.\RainLoop\Utils::GetConnectionToken().'/';
if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
return parent::generateFileName($mAccount, $iStorageType, $sKey, $bMkDir, $bForDeleteAction);
}
return $this->sDataPath
.'/demo'
.'/'.static::fixName(\RainLoop\Utils::GetConnectionToken())
.'/'.($sKey ? static::fixName($sKey) : '');
}
}