Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,23 +11,34 @@
|
||||
namespace IPS\Data\Store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Data\Cache;
|
||||
use IPS\Data\Cache\None;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Db\Exception;
|
||||
use IPS\Session\Front;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database Storage Class
|
||||
*/
|
||||
class _Database extends \IPS\Data\Store
|
||||
class Database extends Store
|
||||
{
|
||||
/**
|
||||
* Server supports this method?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supported()
|
||||
public static function supported(): bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -35,17 +46,17 @@ class _Database extends \IPS\Data\Store
|
||||
/**
|
||||
* @brief Always needed Store keys
|
||||
*/
|
||||
public $initLoad = array( 'cacheKeys', 'settings', 'storageConfigurations', 'themes', 'languages', 'groups', 'applications', 'modules', 'widgets', 'furl', 'javascript_map', 'metaTags', 'bannedIpAddresses', 'license_data', 'furl_configuration', 'rssFeeds', 'frontNavigation', 'globalStreamIds', 'profileSteps' );
|
||||
public array $initLoad = array( 'cacheKeys', 'settings', 'storageConfigurations', 'themes', 'languages', 'groups', 'applications', 'modules', 'widgets', 'furl', 'javascript_map', 'metaTags', 'bannedIpAddresses', 'license_data', 'furl_configuration', 'rssFeeds', 'frontNavigation', 'globalStreamIds', 'profileSteps' );
|
||||
|
||||
/**
|
||||
* @brief Have we done the intitial load?
|
||||
*/
|
||||
protected $doneInitLoad = FALSE;
|
||||
protected bool $doneInitLoad = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Cache
|
||||
*/
|
||||
protected static $cache = array();
|
||||
protected static array $cache = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -56,7 +67,7 @@ class _Database extends \IPS\Data\Store
|
||||
public function __construct()
|
||||
{
|
||||
/* When caching is enabled, we only need cacheKeys, the rest will come from the cache */
|
||||
if ( !\IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None )
|
||||
if ( !Cache::i() instanceof None )
|
||||
{
|
||||
$this->initLoad = array( 'cacheKeys' );
|
||||
}
|
||||
@@ -70,13 +81,16 @@ class _Database extends \IPS\Data\Store
|
||||
$this->initLoad[] = 'acpNotifications';
|
||||
$this->initLoad[] = 'emoticons';
|
||||
|
||||
if ( \IPS\Session\Front::loggedIn() )
|
||||
{
|
||||
$this->initLoad[] = 'administrators';
|
||||
$this->initLoad[] = 'moderators';
|
||||
$this->initLoad[] = 'group_promotions';
|
||||
$this->initLoad[] = 'promoters';
|
||||
}
|
||||
$this->initLoad[] = 'administrators';
|
||||
$this->initLoad[] = 'moderators';
|
||||
$this->initLoad[] = 'group_promotions';
|
||||
$this->initLoad[] = 'promoters';
|
||||
|
||||
/* things from other apps */
|
||||
$this->initLoad[] = 'nexusPackagesWithReviews';
|
||||
$this->initLoad[] = 'cms_menu';
|
||||
$this->initLoad[] = 'cms_databases';
|
||||
$this->initLoad[] = 'pages_page_urls';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +101,9 @@ class _Database extends \IPS\Data\Store
|
||||
* @param array $keys Keys
|
||||
* @return void
|
||||
*/
|
||||
public function loadIntoMemory( array $keys )
|
||||
public function loadIntoMemory( array $keys ) : void
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_store', \IPS\Db::i()->in( 'store_key', $keys ) ) as $row )
|
||||
foreach ( Db::i()->select( '*', 'core_store', Db::i()->in( 'store_key', $keys ) ) as $row )
|
||||
{
|
||||
static::$cache[ $row['store_key'] ] = $row['store_value'];
|
||||
}
|
||||
@@ -98,12 +112,12 @@ class _Database extends \IPS\Data\Store
|
||||
/**
|
||||
* Abstract Method: Get
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $key Key
|
||||
* @return string Value from the datastore
|
||||
*/
|
||||
public function get( $key )
|
||||
public function get( string $key ) : string
|
||||
{
|
||||
if ( !$this->doneInitLoad and \in_array( $key, $this->initLoad ) )
|
||||
if ( !$this->doneInitLoad and in_array( $key, $this->initLoad ) )
|
||||
{
|
||||
$this->loadIntoMemory( $this->initLoad );
|
||||
$this->doneInitLoad = TRUE;
|
||||
@@ -113,11 +127,11 @@ class _Database extends \IPS\Data\Store
|
||||
{
|
||||
try
|
||||
{
|
||||
static::$cache[ $key ] = \IPS\Db::i()->select( 'store_value', 'core_store', array( 'store_key=?', $key ) )->first();
|
||||
static::$cache[ $key ] = Db::i()->select( 'store_value', 'core_store', array( 'store_key=?', $key ) )->first();
|
||||
}
|
||||
catch ( \IPS\Db\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
throw new \UnderflowException;
|
||||
throw new UnderflowException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +141,13 @@ class _Database extends \IPS\Data\Store
|
||||
/**
|
||||
* Abstract Method: Set
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @param string $key Key
|
||||
* @param string $value Value
|
||||
* @return bool
|
||||
*/
|
||||
public function set( $key, $value )
|
||||
public function set( string $key, string $value ): bool
|
||||
{
|
||||
\IPS\Db::i()->replace( 'core_store', array(
|
||||
Db::i()->replace( 'core_store', array(
|
||||
'store_key' => $key,
|
||||
'store_value' => $value
|
||||
) );
|
||||
@@ -146,10 +160,10 @@ class _Database extends \IPS\Data\Store
|
||||
/**
|
||||
* Abstract Method: Exists?
|
||||
*
|
||||
* @param string $key Key
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists( $key )
|
||||
public function exists( string $key ): bool
|
||||
{
|
||||
if ( isset( static::$cache[ $key ] ) )
|
||||
{
|
||||
@@ -162,7 +176,7 @@ class _Database extends \IPS\Data\Store
|
||||
$this->get( $key );
|
||||
return TRUE;
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
catch ( UnderflowException $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -175,31 +189,31 @@ class _Database extends \IPS\Data\Store
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete( $key )
|
||||
public function delete( string $key ): bool
|
||||
{
|
||||
if( isset( static::$cache[ $key ] ) )
|
||||
{
|
||||
unset( static::$cache[ $key ] );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_store', array( 'store_key=?', $key ) );
|
||||
Db::i()->delete( 'core_store', array( 'store_key=?', $key ) );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract Method: Clear All Caches
|
||||
*
|
||||
* @param NULL|string $exclude Key to exclude (keep)
|
||||
* @param string|null $exclude Key to exclude (keep)
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll( $exclude=NULL )
|
||||
public function clearAll( string $exclude=NULL ) : void
|
||||
{
|
||||
$where = array();
|
||||
if( $exclude !== NULL )
|
||||
{
|
||||
$where[] = array( 'store_key != ?', $exclude );
|
||||
}
|
||||
\IPS\Db::i()->delete( 'core_store', $where );
|
||||
Db::i()->delete( 'core_store', $where );
|
||||
|
||||
foreach( static::$cache as $key => $value )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user