Commit 5b9affbc authored by Cédric Anne's avatar Cédric Anne Committed by Johan Cwiklinski

Force reloading of active plugin list on each request

parent 70a49b7a
......@@ -11,6 +11,12 @@ The present file will list all changes made to the project; according to the
- new display hook `timeline_actions` to add new buttons to timeline forms
#### Deprecated
The following methods have been deprecated:
- `Plugin::hasBeenInit()`
#### Removed
- Drop `CommonITILObject::showSolutions()`.
......
......@@ -37,7 +37,7 @@ Session::checkRight("config", UPDATE);
// This has to be called before search process is called, in order to add
// "new" plugins in DB to be able to display them.
$plugin = new Plugin();
$plugin->checkStates();
$plugin->checkStates(true);
Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "plugin");
......
......@@ -383,8 +383,6 @@ class Application extends BaseApplication {
}
$plugin = new Plugin();
$plugin->init();
$plugins_list = $plugin->getPlugins();
if (count($plugins_list) > 0) {
foreach ($plugins_list as $name) {
......
......@@ -96,9 +96,6 @@ if (!isset($PLUGINS_INCLUDED)) {
$PLUGINS_INCLUDED = 1;
$LOADED_PLUGINS = [];
$plugin = new Plugin();
if (!$plugin->hasBeenInit()) {
$plugin->init();
}
$plugins_list = $plugin->getPlugins();
if (count($plugins_list)) {
......
......@@ -89,35 +89,42 @@ class Plugin extends CommonDBTM {
/**
* Init plugins list reading plugins directory
* Init plugins list.
*
* @return void
**/
function init() {
global $GLPI_CACHE;
global $DB, $GLPI_CACHE;
$GLPI_CACHE->set('plugins', []);
if (!$DB->connected) {
// Cannot init plugins list if DB is not connected
return;
}
$this->checkStates();
$plugins = $this->find(['state' => self::ACTIVATED]);
$GLPI_CACHE->set('plugins_init', true);
$GLPI_CACHE->set('plugins', []);
if (count($plugins)) {
foreach ($plugins as $ID => $plug) {
$this->setLoaded($ID, $plug['directory']);
}
}
}
/**
* Are plugin initialized (Plugin::Init() called)
*
* @return boolean
*
* @deprecated 9.4.1
*/
public static function hasBeenInit() {
Toolbox::deprecated();
global $GLPI_CACHE;
return $GLPI_CACHE->has('plugins_init');
return $GLPI_CACHE->has('plugins');
}
......@@ -226,9 +233,11 @@ class Plugin extends CommonDBTM {
/**
* Check plugins states and detect new plugins.
*
* @param boolean $scan_for_new_plugins
*
* @return void
*/
public function checkStates() {
public function checkStates($scan_for_new_plugins = false) {
$directories = [];
......@@ -238,6 +247,7 @@ class Plugin extends CommonDBTM {
$directories[] = $plugin['directory'];
}
if ($scan_for_new_plugins) {
// Add found directories to the check list
$plugins_directory = GLPI_ROOT."/plugins";
$directory_handle = opendir($plugins_directory);
......@@ -247,6 +257,7 @@ class Plugin extends CommonDBTM {
$directories[] = $filename;
}
}
}
// Prevent duplicated checks
$directories = array_unique($directories);
......@@ -695,9 +706,8 @@ class Plugin extends CommonDBTM {
**/
function isActivated($plugin) {
if ($this->getFromDBbyDir($plugin)) {
return ($this->fields['state'] == self::ACTIVATED);
}
$activePlugins = $this->getPlugins();
return in_array($plugin, $activePlugins);
}
......@@ -708,6 +718,11 @@ class Plugin extends CommonDBTM {
**/
function isInstalled($plugin) {
if ($this->isActivated($plugin)) {
// Prevent call on DB if plugin is activated.
return true;
}
if ($this->getFromDBbyDir($plugin)) {
return (($this->fields['state'] == self::ACTIVATED)
|| ($this->fields['state'] == self::TOBECONFIGURED)
......@@ -1672,10 +1687,13 @@ class Plugin extends CommonDBTM {
*/
public static function getPlugins() {
global $GLPI_CACHE;
if ($GLPI_CACHE && $GLPI_CACHE->has('plugins')) {
return $GLPI_CACHE->get('plugins');
if (!$GLPI_CACHE->has('plugins')) {
$self = new self();
$self->init();
}
return [];
return $GLPI_CACHE->get('plugins');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment