Move TemproryApcStorage to demo-account plugin

This commit is contained in:
djmaze 2021-10-25 09:45:22 +02:00
parent 3945ab1349
commit 57dd0f7e2c
2 changed files with 15 additions and 31 deletions

View file

@ -37,8 +37,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
*/ */
public function FilterAppData($bAdmin, &$aResult) public function FilterAppData($bAdmin, &$aResult)
{ {
if (!$bAdmin && \is_array($aResult) && isset($aResult['Auth']) && !$aResult['Auth']) if (!$bAdmin && \is_array($aResult) && isset($aResult['Auth']) && !$aResult['Auth']) {
{
$aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $aResult['DevEmail']); $aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $aResult['DevEmail']);
$aResult['DevPassword'] = APP_DUMMY; $aResult['DevPassword'] = APP_DUMMY;
} }
@ -49,12 +48,11 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
*/ */
public function FilterActionParams($sMethodName, &$aActionParams) public function FilterActionParams($sMethodName, &$aActionParams)
{ {
if ('DoLogin' === $sMethodName && isset($aActionParams['Email']) && isset($aActionParams['Password'])) if ('DoLogin' === $sMethodName
{ && isset($aActionParams['Email'])
if ($this->Config()->Get('plugin', 'email') === $aActionParams['Email']) && isset($aActionParams['Password'])
{ && $this->Config()->Get('plugin', 'email') === $aActionParams['Email']) {
$aActionParams['Password'] = $this->Config()->Get('plugin', 'password'); $aActionParams['Password'] = $this->Config()->Get('plugin', 'password');
}
} }
} }
@ -70,17 +68,14 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
public function JsonActionPreCall($sAction) public function JsonActionPreCall($sAction)
{ {
if ('AccountSetup' === $sAction && if ('AccountSetup' === $sAction && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) {
$this->isDemoAccount($this->Manager()->Actions()->GetAccount()))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError);
} }
} }
public function FilterSendMessage($oMessage) public function FilterSendMessage($oMessage)
{ {
if ($oMessage && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) if ($oMessage && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) {
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError);
} }
} }
@ -91,21 +86,12 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
*/ */
public function MainFabrica($sName, &$oDriver) public function MainFabrica($sName, &$oDriver)
{ {
switch ($sName) if (('storage' === $sName || 'storage-local' === $sName) && \function_exists('apcu_store')) {
{ $oAccount = $this->Manager()->Actions()->GetAccount();
case 'storage': if ($this->isDemoAccount($oAccount)) {
case 'storage-local': require_once __DIR__ . '/storage.php';
if (\class_exists('\\RainLoop\\Providers\\Storage\\TemproryApcStorage') && $oDriver = new \DemoStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
\function_exists('apc_store')) }
{
$oAccount = $this->Manager()->Actions()->GetAccount();
if ($this->isDemoAccount($oAccount))
{
$oDriver = new \RainLoop\Providers\Storage\TemproryApcStorage(APP_PRIVATE_DATA.'storage',
$sName === 'storage-local');
}
}
break;
} }
} }
} }

View file

@ -1,8 +1,6 @@
<?php <?php
namespace RainLoop\Providers\Storage; class DemoStorage extends \RainLoop\Providers\Storage\FileStorage
class TemproryApcStorage extends \RainLoop\Providers\Storage\FileStorage
{ {
/** /**
* @param \RainLoop\Model\Account|string|null $oAccount * @param \RainLoop\Model\Account|string|null $oAccount