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 ...@@ -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 - new display hook `timeline_actions` to add new buttons to timeline forms
#### Deprecated
The following methods have been deprecated:
- `Plugin::hasBeenInit()`
#### Removed #### Removed
- Drop `CommonITILObject::showSolutions()`. - Drop `CommonITILObject::showSolutions()`.
......
...@@ -37,7 +37,7 @@ Session::checkRight("config", UPDATE); ...@@ -37,7 +37,7 @@ Session::checkRight("config", UPDATE);
// This has to be called before search process is called, in order to add // This has to be called before search process is called, in order to add
// "new" plugins in DB to be able to display them. // "new" plugins in DB to be able to display them.
$plugin = new Plugin(); $plugin = new Plugin();
$plugin->checkStates(); $plugin->checkStates(true);
Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "plugin"); Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "plugin");
......
...@@ -383,8 +383,6 @@ class Application extends BaseApplication { ...@@ -383,8 +383,6 @@ class Application extends BaseApplication {
} }
$plugin = new Plugin(); $plugin = new Plugin();
$plugin->init();
$plugins_list = $plugin->getPlugins(); $plugins_list = $plugin->getPlugins();
if (count($plugins_list) > 0) { if (count($plugins_list) > 0) {
foreach ($plugins_list as $name) { foreach ($plugins_list as $name) {
......
...@@ -96,9 +96,6 @@ if (!isset($PLUGINS_INCLUDED)) { ...@@ -96,9 +96,6 @@ if (!isset($PLUGINS_INCLUDED)) {
$PLUGINS_INCLUDED = 1; $PLUGINS_INCLUDED = 1;
$LOADED_PLUGINS = []; $LOADED_PLUGINS = [];
$plugin = new Plugin(); $plugin = new Plugin();
if (!$plugin->hasBeenInit()) {
$plugin->init();
}
$plugins_list = $plugin->getPlugins(); $plugins_list = $plugin->getPlugins();
if (count($plugins_list)) { if (count($plugins_list)) {
......
...@@ -89,23 +89,25 @@ class Plugin extends CommonDBTM { ...@@ -89,23 +89,25 @@ class Plugin extends CommonDBTM {
/** /**
* Init plugins list reading plugins directory * Init plugins list.
* *
* @return void * @return void
**/ **/
function init() { function init() {
global $GLPI_CACHE; global $DB, $GLPI_CACHE;
$this->checkStates();
$plugins = $this->find(['state' => self::ACTIVATED]);
$GLPI_CACHE->set('plugins_init', true);
$GLPI_CACHE->set('plugins', []); $GLPI_CACHE->set('plugins', []);
if (count($plugins)) { if (!$DB->connected) {
foreach ($plugins as $ID => $plug) { // Cannot init plugins list if DB is not connected
$this->setLoaded($ID, $plug['directory']); return;
} }
$this->checkStates();
$plugins = $this->find(['state' => self::ACTIVATED]);
foreach ($plugins as $ID => $plug) {
$this->setLoaded($ID, $plug['directory']);
} }
} }
...@@ -114,10 +116,15 @@ class Plugin extends CommonDBTM { ...@@ -114,10 +116,15 @@ class Plugin extends CommonDBTM {
* Are plugin initialized (Plugin::Init() called) * Are plugin initialized (Plugin::Init() called)
* *
* @return boolean * @return boolean
*
* @deprecated 9.4.1
*/ */
public static function hasBeenInit() { public static function hasBeenInit() {
Toolbox::deprecated();
global $GLPI_CACHE; global $GLPI_CACHE;
return $GLPI_CACHE->has('plugins_init');
return $GLPI_CACHE->has('plugins');
} }
...@@ -226,9 +233,11 @@ class Plugin extends CommonDBTM { ...@@ -226,9 +233,11 @@ class Plugin extends CommonDBTM {
/** /**
* Check plugins states and detect new plugins. * Check plugins states and detect new plugins.
* *
* @param boolean $scan_for_new_plugins
*
* @return void * @return void
*/ */
public function checkStates() { public function checkStates($scan_for_new_plugins = false) {
$directories = []; $directories = [];
...@@ -238,13 +247,15 @@ class Plugin extends CommonDBTM { ...@@ -238,13 +247,15 @@ class Plugin extends CommonDBTM {
$directories[] = $plugin['directory']; $directories[] = $plugin['directory'];
} }
// Add found directories to the check list if ($scan_for_new_plugins) {
$plugins_directory = GLPI_ROOT."/plugins"; // Add found directories to the check list
$directory_handle = opendir($plugins_directory); $plugins_directory = GLPI_ROOT."/plugins";
while (false !== ($filename = readdir($directory_handle))) { $directory_handle = opendir($plugins_directory);
if (!in_array($filename, ['.svn', '.', '..']) while (false !== ($filename = readdir($directory_handle))) {
&& is_dir($plugins_directory . DIRECTORY_SEPARATOR . $filename)) { if (!in_array($filename, ['.svn', '.', '..'])
$directories[] = $filename; && is_dir($plugins_directory . DIRECTORY_SEPARATOR . $filename)) {
$directories[] = $filename;
}
} }
} }
...@@ -695,9 +706,8 @@ class Plugin extends CommonDBTM { ...@@ -695,9 +706,8 @@ class Plugin extends CommonDBTM {
**/ **/
function isActivated($plugin) { function isActivated($plugin) {
if ($this->getFromDBbyDir($plugin)) { $activePlugins = $this->getPlugins();
return ($this->fields['state'] == self::ACTIVATED); return in_array($plugin, $activePlugins);
}
} }
...@@ -708,6 +718,11 @@ class Plugin extends CommonDBTM { ...@@ -708,6 +718,11 @@ class Plugin extends CommonDBTM {
**/ **/
function isInstalled($plugin) { function isInstalled($plugin) {
if ($this->isActivated($plugin)) {
// Prevent call on DB if plugin is activated.
return true;
}
if ($this->getFromDBbyDir($plugin)) { if ($this->getFromDBbyDir($plugin)) {
return (($this->fields['state'] == self::ACTIVATED) return (($this->fields['state'] == self::ACTIVATED)
|| ($this->fields['state'] == self::TOBECONFIGURED) || ($this->fields['state'] == self::TOBECONFIGURED)
...@@ -1672,10 +1687,13 @@ class Plugin extends CommonDBTM { ...@@ -1672,10 +1687,13 @@ class Plugin extends CommonDBTM {
*/ */
public static function getPlugins() { public static function getPlugins() {
global $GLPI_CACHE; 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