Commit 9b30eb1f authored by Cédric Anne's avatar Cédric Anne Committed by Johan Cwiklinski

Move cache configuration from DB to local config file

* Cache configuration is now handled in DI container parameters.
* `GLPI_CONFIG_DIR . '/parameters.yaml'` will be loaded, if existing, during container build.
* Legacy cache config existing in DB will be migrated into the new local config file during migration from 9.4 to 10.0.
* `global $GLPI_CACHE` has been dropped.
* All tests are now ran using apcu cache adapter.
* A unique cache id is now set on installation.
parent 817d3370
......@@ -104,6 +104,7 @@ commands:
mysql -h 127.0.0.1 -u root -e 'create database glpitest;'
bin/console glpi:database:install --config-dir=./tests --no-interaction --db-name=glpitest --db-host=127.0.0.1 --db-user=root
bin/console glpi:database:update --config-dir=./tests --no-interaction |grep -q "No migration needed." || (echo "glpi:database:update command FAILED" && exit 1)
cp tests/circleci.parameters.yaml tests/parameters.yaml
- run:
name: Unit tests
command: php vendor/bin/atoum -p 'php -d memory_limit=512M' --debug --force-terminal --use-dot-report --configurations tests/telemetry.php --bootstrap-file tests/bootstrap.php --no-code-coverage -d tests/units
......
......@@ -2,6 +2,7 @@
/config/db.yaml
/config/config_path.php
/config/local_define.php
/config/parameters.yaml
/tests/config_db*
/tests/db.yaml
/plugins/
......@@ -18,6 +19,7 @@
/vendor/
phpunit.xml
/tests/code-coverage/
/tests/files/
/config/based_config.php
/config/config.php
/config/define.php
......
......@@ -11,6 +11,7 @@ before_script:
- sed -e '/"php":/d' -i composer.json
- rm -f composer.lock
- composer install --optimize-autoloader
- cp tests/travis.parameters.yaml tests/parameters.yaml
- mysql -u root -e 'create database glpitest;'
- bin/console glpi:database:install --config-dir=./tests --no-interaction --db-name=glpitest --db-user=root
- ./tests/LDAP/ldap_fixtures.sh > /dev/null
......
This diff is collapsed.
......@@ -52,7 +52,8 @@ if (!empty($_GET['reset_opcache'])) {
}
if (!empty($_GET['reset_cache'])) {
$config->checkGlobal(UPDATE);
if ($GLPI_CACHE->clear()) {
$appCache = Toolbox::getAppCache();
if ($appCache->clear()) {
Session::addMessageAfterRedirect(__('Cache reset successful'));
}
Html::redirect(Toolbox::getItemTypeFormURL('Config'));
......
......@@ -43,6 +43,17 @@ abstract class CommonTreeDropdown extends CommonDropdown {
public $can_be_translated = false;
/**
* @var \Psr\SimpleCache\CacheInterface
*/
protected $cache;
public function __construct() {
global $CONTAINER;
$this->cache = $CONTAINER->get('application_cache');
parent::__construct();
}
function getAdditionalFields() {
......@@ -175,8 +186,6 @@ abstract class CommonTreeDropdown extends CommonDropdown {
function prepareInputForUpdate($input) {
global $GLPI_CACHE;
if (isset($input[$this->getForeignKeyField()])) {
// Can't move a parent under a child
if (in_array($input[$this->getForeignKeyField()],
......@@ -187,8 +196,8 @@ abstract class CommonTreeDropdown extends CommonDropdown {
if ($input[$this->getForeignKeyField()] != $this->fields[$this->getForeignKeyField()]) {
$input["ancestors_cache"] = '';
$ckey = $this->getTable() . '_ancestors_cache_' . $this->getID();
if ($GLPI_CACHE->has($ckey)) {
$GLPI_CACHE->delete($ckey);
if ($this->cache->has($ckey)) {
$this->cache->delete($ckey);
}
return $this->adaptTreeFieldsFromUpdateOrAdd($input);
}
......@@ -208,13 +217,13 @@ abstract class CommonTreeDropdown extends CommonDropdown {
* @param $changeParent
**/
function regenerateTreeUnderID($ID, $updateName, $changeParent) {
global $DB, $GLPI_CACHE;
global $DB;
//drop from sons cache when needed
if ($changeParent) {
$ckey = $this->getTable() . '_ancestors_cache_' . $ID;
if ($GLPI_CACHE->has($ckey)) {
$GLPI_CACHE->delete($ckey);
if ($this->cache->has($ckey)) {
$this->cache->delete($ckey);
}
}
......@@ -282,7 +291,7 @@ abstract class CommonTreeDropdown extends CommonDropdown {
* @return void
*/
protected function cleanParentsSons($id = null, $cache = true) {
global $DB, $GLPI_CACHE;
global $DB;
if ($id === null) {
$id = $this->getID();
......@@ -308,11 +317,11 @@ abstract class CommonTreeDropdown extends CommonDropdown {
if ($cache) {
foreach ($ancestors as $ancestor) {
$ckey = $this->getTable() . '_sons_cache_' . $ancestor;
if ($GLPI_CACHE->has($ckey)) {
$sons = $GLPI_CACHE->get($ckey);
if ($this->cache->has($ckey)) {
$sons = $this->cache->get($ckey);
if (isset($sons[$this->getID()])) {
unset($sons[$this->getID()]);
$GLPI_CACHE->set($ckey, $sons);
$this->cache->set($ckey, $sons);
}
}
}
......@@ -326,17 +335,15 @@ abstract class CommonTreeDropdown extends CommonDropdown {
* @return void
*/
protected function addSonInParents() {
global $GLPI_CACHE;
//add sons cache when needed
$ancestors = getAncestorsOf($this->getTable(), $this->getID());
foreach ($ancestors as $ancestor) {
$ckey = $this->getTable() . '_sons_cache_' . $ancestor;
if ($GLPI_CACHE->has($ckey)) {
$sons = $GLPI_CACHE->get($ckey);
if ($this->cache->has($ckey)) {
$sons = $this->cache->get($ckey);
if (!isset($sons[$this->getID()])) {
$sons[$this->getID()] = (string)$this->getID();
$GLPI_CACHE->set($ckey, $sons);
$this->cache->set($ckey, $sons);
}
}
}
......
......@@ -31,12 +31,11 @@
*/
use Glpi\Exception\PasswordTooWeakException;
use Glpi\Cache\SimpleCache;
use Zend\Cache\Storage\AvailableSpaceCapableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Cache\Storage\FlushableInterface;
use PHPMailer\PHPMailer\PHPMailer;
use Symfony\Component\Yaml\Yaml;
use Zend\Cache\Storage\AvailableSpaceCapableInterface;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
......@@ -1515,7 +1514,9 @@ class Config extends CommonDBTM {
* @since 9.1
**/
function showPerformanceInformations() {
$GLPI_CACHE = self::getCache('cache_db', 'core', false);
global $CONTAINER;
$cache_storage = $CONTAINER->get('application_cache_storage');
if (!Config::canUpdate()) {
return false;
......@@ -1596,7 +1597,7 @@ class Config extends CommonDBTM {
}
echo "<tr><th colspan='4'>" . __('User data cache') . "</th></tr>";
$ext = strtolower(get_class($GLPI_CACHE));
$ext = strtolower(get_class($cache_storage));
$ext = substr($ext, strrpos($ext, '\\')+1);
if (in_array($ext, ['apcu', 'memcache', 'memcached', 'wincache', 'redis'])) {
$msg = sprintf(__s('The "%s" cache extension is installed'), $ext);
......@@ -1608,9 +1609,9 @@ class Config extends CommonDBTM {
<td></td>
<td class='icons_block'><i class='fa fa-check-circle ok' title='$msg'></i><span class='sr-only'>$msg</span></td></tr>";
if ($ext != 'filesystem' && $GLPI_CACHE instanceof AvailableSpaceCapableInterface && $GLPI_CACHE instanceof TotalSpaceCapableInterface) {
$free = $GLPI_CACHE->getAvailableSpace();
$max = $GLPI_CACHE->getTotalSpace();
if ($ext != 'filesystem' && $cache_storage instanceof AvailableSpaceCapableInterface && $cache_storage instanceof TotalSpaceCapableInterface) {
$free = $cache_storage->getAvailableSpace();
$max = $cache_storage->getTotalSpace();
$used = $max - $free;
$rate = round(100.0 * $used / $max);
$max = Toolbox::getSize($max);
......@@ -1629,7 +1630,7 @@ class Config extends CommonDBTM {
echo "</td><td class='icons_block'><i title='$msg' class='fa fa-$class'></td></tr>";
}
if ($GLPI_CACHE instanceof FlushableInterface) {
if ($cache_storage instanceof FlushableInterface) {
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
echo "<tr><td></td><td colspan='3'>";
echo "<a class='vsubmit' href='config.form.php?reset_cache=1'>";
......@@ -1943,6 +1944,8 @@ class Config extends CommonDBTM {
'check' => 'Symfony\\Component\\DependencyInjection\\Container' ],
[ 'name' => 'symfony/event-dispatcher',
'check' => 'Symfony\\Component\\EventDispatcher\\EventDispatcher' ],
[ 'name' => 'symfony/property-access',
'check' => 'Symfony\Component\PropertyAccess\\PropertyAccessor' ],
[ 'name' => 'symfony/yaml',
'check' => 'Symfony\\Component\\Yaml\\Yaml' ],
[ 'name' => 'doctrine/annotations',
......@@ -2924,153 +2927,6 @@ class Config extends CommonDBTM {
return $msg;
}
/**
* Get a cache adapter from configuration
*
* @param string $optname name of the configuration field
* @param string $context name of the configuration context (default 'core')
* @param boolean $psr16 Whether to return a PSR16 compliant obkect or not (since ZendTranslator is NOT PSR16 compliant).
*
* @return Glpi\Cache\SimpleCache|Zend\Cache\Storage\StorageInterface object
*/
public static function getCache($optname, $context = 'core', $psr16 = true) {
global $DB;
/* Tested configuration values
*
* - {"adapter":"apcu"}
* - {"adapter":"redis","options":{"server":{"host":"127.0.0.1"}},"plugins":["serializer"]}
* - {"adapter":"filesystem"}
* - {"adapter":"filesystem","options":{"cache_dir":"_cache_trans"},"plugins":["serializer"]}
* - {"adapter":"dba"}
* - {"adapter":"dba","options":{"pathname":"trans.db","handler":"flatfile"},"plugins":["serializer"]}
* - {"adapter":"memcache","options":{"servers":["127.0.0.1"]}}
* - {"adapter":"memcached","options":{"servers":["127.0.0.1"]}}
* - {"adapter":"wincache"}
*
*/
// Read configuration
$conf = [];
if ($DB
&& $DB->isConnected()
&& $DB->fieldExists(self::getTable(), 'context')
) {
$conf = self::getConfigurationValues($context, [$optname]);
}
// Adapter default options
$opt = [];
if (isset($conf[$optname])) {
$opt = json_decode($conf[$optname], true);
Toolbox::logDebug("CACHE CONFIG $optname", $opt);
}
//use memory adapter when called from tests
if (defined('TU_USER')) {
$opt['adapter'] = 'memory';
}
//force FS adapter for translations for tests
if (defined('TU_USER') && $optname == 'cache_trans') {
$opt['adapter'] = 'filesystem';
}
if (!isset($opt['options']['namespace'])) {
$namespace = "glpi_${optname}_" . GLPI_VERSION;
if ($DB) {
$namespace .= md5($DB->getDsn(null));
}
$opt['options']['namespace'] = $namespace;
}
if (!isset($opt['adapter'])) {
if (function_exists('apcu_fetch')) {
$opt['adapter'] = (version_compare(PHP_VERSION, '7.0.0') >= 0) ? 'apcu' : 'apc';
} else if (function_exists('wincache_ucache_add')) {
$opt['adapter'] = 'wincache';
} else {
$opt['adapter'] = 'filesystem';
}
}
// Adapter specific options
$ser = false;
switch ($opt['adapter']) {
case 'filesystem':
if (!isset($opt['options']['cache_dir'])) {
$opt['options']['cache_dir'] = $optname;
}
// Make configured directory relative to GLPI cache directory
$opt['options']['cache_dir'] = GLPI_CACHE_DIR . '/' . $opt['options']['cache_dir'];
if (!is_dir($opt['options']['cache_dir'])) {
mkdir($opt['options']['cache_dir']);
}
$ser = true;
break;
case 'dba':
if (!isset($opt['options']['pathname'])) {
$opt['options']['pathname'] = "$optname.data";
}
// Make configured path relative to GLPI cache directory
$opt['options']['pathname'] = GLPI_CACHE_DIR . '/' . $opt['options']['pathname'];
$ser = true;
break;
case 'redis':
$ser = true;
break;
}
// Some know plugins require data serialization
if ($ser && !isset($opt['plugins'])) {
$opt['plugins'] = ['serializer'];
}
// Create adapter
try {
$storage = Zend\Cache\StorageFactory::factory($opt);
} catch (Exception $e) {
//fallback to another cache system
$fallback = false;
if ($opt['adapter'] != 'filesystem') {
$opt = [
'adapter' => 'filesystem',
'options' => [
'cache_dir' => GLPI_CACHE_DIR . '/' . $optname
],
'plugins' => ['serializer']
];
if (!is_dir($opt['options']['cache_dir'])) {
mkdir($opt['options']['cache_dir']);
}
try {
$storage = Zend\Cache\StorageFactory::factory($opt);
$fallback = true;
} catch (Exception $e1) {
Toolbox::logError($e1->getMessage());
if (isset($_SESSION['glpi_use_mode'])
&& Session::DEBUG_MODE == $_SESSION['glpi_use_mode']) {
//preivous attempt has faled as well.
Toolbox::logDebug($e->getMessage());
}
}
}
if ($fallback === false) {
$opt = ['adapter' => 'memory'];
$storage = Zend\Cache\StorageFactory::factory($opt);
}
if (isset($_SESSION['glpi_use_mode'])
&& Session::DEBUG_MODE == $_SESSION['glpi_use_mode']) {
Toolbox::logDebug($e->getMessage());
}
}
if ($psr16) {
return new SimpleCache($storage);
} else {
return $storage;
}
}
/**
* Get available palettes
*
......
......@@ -41,7 +41,6 @@ include_once (GLPI_ROOT."/inc/based_config.php");
include_once (GLPI_ROOT."/inc/define.php");
include_once (GLPI_ROOT."/inc/dbconnection.class.php");
//init cache
Session::setPath();
Session::start();
......
......@@ -36,6 +36,7 @@ if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
use Glpi\Application\LocalConfigurationManager;
use Glpi\Console\Command\ForceNoPluginsOptionCommandInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
......@@ -45,6 +46,8 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Yaml\Yaml;
use Config;
use DBConnection;
use PDO;
......@@ -101,6 +104,13 @@ class InstallCommand extends Command implements ForceNoPluginsOptionCommandInter
*/
const ERROR_DB_SELECT_FAILED = 7;
/**
* Error code returned when failing to save local configuration file.
*
* @var integer
*/
const ERROR_LOCAL_CONFIG_FILE_NOT_SAVED = 8;
protected function configure() {
parent::configure();
......@@ -336,6 +346,23 @@ class InstallCommand extends Command implements ForceNoPluginsOptionCommandInter
return self::ERROR_SCHEMA_CREATION_FAILED;
}
try {
$localConfigManager = new LocalConfigurationManager(
GLPI_CONFIG_DIR,
new PropertyAccessor(),
new Yaml()
);
$localConfigManager->setParameterValue('[cache_uniq_id]', uniqid());
} catch (\Exception $e) {
$message = sprintf(
__('Local configuration file saving failed with message "(%s)\n%s".'),
$e->getMessage(),
$e->getTraceAsString()
);
$output->writeln('<error>' . $message . '</error>', OutputInterface::VERBOSITY_QUIET);
return self::ERROR_LOCAL_CONFIG_FILE_NOT_SAVED;
}
$output->writeln('<info>' . __('Installation done.') . '</info>');
return 0; // Success
......
......@@ -670,13 +670,14 @@ final class DbUtils {
* @return array of IDs of the sons
*/
public function getSonsOf($table, $IDf) {
global $DB, $GLPI_CACHE;
global $DB;
$appCache = Toolbox::getAppCache();
$ckey = $table . '_sons_cache_' . $IDf;
$sons = false;
if ($GLPI_CACHE->has($ckey)) {
$sons = $GLPI_CACHE->get($ckey);
if ($appCache->has($ckey)) {
$sons = $appCache->get($ckey);
if ($sons !== null) {
return $sons;
}
......@@ -759,7 +760,7 @@ final class DbUtils {
}
}
$GLPI_CACHE->set($ckey, $sons);
$appCache->set($ckey, $sons);
return $sons;
}
......@@ -773,8 +774,9 @@ final class DbUtils {
* @return array of IDs of the ancestors
*/
public function getAncestorsOf($table, $items_id) {
global $DB, $GLPI_CACHE;
global $DB;
$appCache = Toolbox::getAppCache();
$ckey = $table . '_ancestors_cache_';
if (is_array($items_id)) {
$ckey .= md5(implode('|', $items_id));
......@@ -783,8 +785,8 @@ final class DbUtils {
}
$ancestors = [];
if ($GLPI_CACHE->has($ckey)) {
$ancestors = $GLPI_CACHE->get($ckey);
if ($appCache->has($ckey)) {
$ancestors = $appCache->get($ckey);
if ($ancestors !== null) {
return $ancestors;
}
......@@ -870,7 +872,7 @@ final class DbUtils {
}
}
$GLPI_CACHE->set($ckey, $ancestors);
$appCache->set($ckey, $ancestors);
return $ancestors;
}
......
......@@ -106,6 +106,18 @@ class Entity extends CommonTreeDropdown {
'max_closedate', 'tickettemplates_id']];
/**
* @var \Psr\SimpleCache\CacheInterface
*/
protected $cache;
public function __construct() {
global $CONTAINER;
$this->cache = $CONTAINER->get('application_cache');
parent::__construct();
}
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
......@@ -121,8 +133,6 @@ class Entity extends CommonTreeDropdown {
* @since 0.84
**/
function pre_deleteItem() {
global $GLPI_CACHE;
// Security do not delete root entity
if ($this->input['id'] == 0) {
return false;
......@@ -131,8 +141,8 @@ class Entity extends CommonTreeDropdown {
//Cleaning sons calls getAncestorsOf and thus... Re-create cache. Call it before clean.
$this->cleanParentsSons();
$ckey = $this->getTable() . '_ancestors_cache_' . $this->getID();
if ($GLPI_CACHE->has($ckey)) {
$GLPI_CACHE->delete($ckey);
if ($this->cache->has($ckey)) {
$this->cache->delete($ckey);
}
return true;
}
......
......@@ -723,8 +723,9 @@ class Html {
* @return void
**/
static function displayDebugInfos($with_session = true, $ajax = false) {
global $CFG_GLPI, $DEBUG_SQL, $SQL_TOTAL_REQUEST, $SQL_TOTAL_TIMER, $DEBUG_AUTOLOAD;
$GLPI_CACHE = Config::getCache('cache_db', 'core', false);
global $CFG_GLPI, $CONTAINER, $DEBUG_SQL, $SQL_TOTAL_REQUEST, $SQL_TOTAL_TIMER, $DEBUG_AUTOLOAD;
$cache_storage = $CONTAINER->get('application_cache_storage');
// Only for debug mode so not need to be translated
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { // mode debug
......@@ -751,7 +752,7 @@ class Html {
echo "<li><a href='#debugsession$rand'>SESSION VARIABLE</a></li>";
}
echo "<li><a href='#debugserver$rand'>SERVER VARIABLE</a></li>";
if ($GLPI_CACHE instanceof Zend\Cache\Storage\IterableInterface) {
if ($cache_storage instanceof Zend\Cache\Storage\IterableInterface) {
echo "<li><a href='#debugcache$rand'>CACHE VARIABLE</a></li>";
}
}
......@@ -798,12 +799,12 @@ class Html {
self::printCleanArray($_SERVER, 0, true);
echo "</div>";
if ($GLPI_CACHE instanceof Zend\Cache\Storage\IterableInterface) {
if ($cache_storage instanceof Zend\Cache\Storage\IterableInterface) {
echo "<div id='debugcache$rand'>";
$cache_keys = $GLPI_CACHE->getIterator();
$cache_keys = $cache_storage->getIterator();
$cache_contents = [];
foreach ($cache_keys as $cache_key) {
$cache_contents[$cache_key] = $GLPI_CACHE->getItem($cache_key);
$cache_contents[$cache_key] = $cache_storage->getItem($cache_key);
}
self::printCleanArray($cache_contents, 0, true);
echo "</div>";
......@@ -6618,8 +6619,9 @@ class Html {
* @return string
*/
public static function compileScss($args) {
global $CFG_GLPI, $GLPI_CACHE;
global $CFG_GLPI;
$appCache = Toolbox::getAppCache();
$ckey = isset($args['v']) ? $args['v'] : GLPI_SCHEMA_VERSION;
$is_debug = $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE;
$files = [];
......@@ -6692,18 +6694,18 @@ class Html {
$hashfile = self::getScssFileHash($path);
//check if files has changed
if ($GLPI_CACHE->has($fckey)) {
$hash = $GLPI_CACHE->get($fckey);
if ($appCache->has($fckey)) {
$hash = $appCache->get($fckey);
if ($hashfile != $hash) {
//file has changed
Toolbox::logDebug("$file has changed, reloading");
$args['reload'] = true;
$GLPI_CACHE->set($fckey, $hashfile);
$appCache->set($fckey, $hashfile);
}
} else {
Toolbox::logDebug("$file is new, loading");
$GLPI_CACHE->set($fckey, $hashfile);
$appCache->set($fckey, $hashfile);
}
} else {
Toolbox::logWarning('Requested file ' . $path . ' does not exists.');
......@@ -6727,12 +6729,12 @@ class Html {
}
);
if ($GLPI_CACHE->has($ckey) && !isset($args['reload']) && !isset($args['nocache'])) {
$css = $GLPI_CACHE->get($ckey);
if ($appCache->has($ckey) && !isset($args['reload']) && !isset($args['nocache'])) {
$css = $appCache->get($ckey);
} else {
$css = $scss->compile($import);
if (!isset($args['nocache'])) {
$GLPI_CACHE->set($ckey, $css);
$appCache->set($ckey, $css);
}
}
......
......@@ -409,12 +409,11 @@ class Item_Devices extends CommonDBRelation {
* @return array of Item_Device*
**/
static function getItemAffinities($itemtype) {
global $GLPI_CACHE;
if (!$GLPI_CACHE->has('item_device_affinities')) {
$GLPI_CACHE->set('item_device_affinities', ['' => static::getDeviceTypes()]);
$appCache = Toolbox::getAppCache();
if (!$appCache->has('item_device_affinities')) {
$appCache->set('item_device_affinities', ['' => static::getDeviceTypes()]);
}
$items_affinities = $GLPI_CACHE->get('item_device_affinities');
$items_affinities = $appCache->get('item_device_affinities');
if (!isset($items_affinities[$itemtype])) {
$afffinities = [];
......@@ -424,7 +423,7 @@ class Item_Devices extends CommonDBRelation {
}
}
$items_affinities[$itemtype] = $afffinities;
$GLPI_CACHE->set('item_device_affinities', $items_affinities);
$appCache->set('item_device_affinities', $items_affinities);
}
return $items_affinities[$itemtype];
......
......@@ -692,7 +692,7 @@ class Migration {
* @return void
**/
function executeMigration() {
global $DB, $GLPI_CACHE;
global $DB;
foreach ($this->queries[self::PRE_QUERY] as $query) {
$DB->rawQueryOrDie($query['query'], $query['message'], $query['params']);
......
......@@ -94,7 +94,7 @@ class Plugin extends CommonDBTM {
* @return void
**/
function init() {
global $DB, $GLPI_CACHE;
global $DB;
if (!$DB->isConnected() || !$DB->tableExists(self::getTable())) {
return;
......@@ -103,8 +103,9 @@ class Plugin extends CommonDBTM {
$this->checkStates();
$plugins = $this->find(['state' => self::ACTIVATED]);
$GLPI_CACHE->set('plugins_init', true);
$GLPI_CACHE->set('plugins', []);
$appCache = Toolbox::getAppCache();
$appCache->set('plugins_init', true);
$appCache->set('plugins', []);
if (count($plugins)) {
foreach ($plugins as $ID => $plug) {
......@@ -120,8 +121,8 @@ class Plugin extends CommonDBTM {
* @return boolean
*/
public static function hasBeenInit() {
global $GLPI_CACHE;
return $GLPI_CACHE->has('plugins_init');
$appCache = Toolbox::getAppCache();
return $appCache->has('plugins_init');
}
......@@ -656,7 +657,7 @@ class Plugin extends CommonDBTM {
* unactivate all activated plugins for update process
**/
function unactivateAll() {
global $DB, $GLPI_CACHE;
global $DB;
$DB->update(
$this->getTable(), [
......@@ -666,7 +667,8 @@ class Plugin extends CommonDBTM {
]
);
$GLPI_CACHE->set('plugins', []);
$appCache = Toolbox::getAppCache();
$appCache->set('plugins', []);
// reset menu
if (isset($_SESSION['glpimenu'])) {
......@@ -1658,9 +1660,9 @@ class Plugin extends CommonDBTM {
* @return array
*/
public static function getPlugins() {
global $GLPI_CACHE;
if ($GLPI_CACHE->has('plugins')) {
return $GLPI_CACHE->get('plugins');
$appCache = Toolbox::getAppCache();
if ($appCache->has('plugins')) {
return $appCache->get('plugins');
}
return [];
}
......@@ -1689,10 +1691,10 @@ class Plugin extends CommonDBTM {
* @return void
*/
public static function setLoaded($id, $name) {
global $GLPI_CACHE;
$plugins = $GLPI_CACHE->get('plugins');
$appCache = Toolbox::getAppCache();
$plugins = $appCache->get('plugins');
$plugins[$id] = $name;
$GLPI_CACHE->set('plugins', $plugins);