diff --git a/CHANGELOG.md b/CHANGELOG.md index 8935ec493d0f1f4f52e28a16b477e945d3add727..f9a40aed8c5be11b518aa0139a37c77068d4e0a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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()`. diff --git a/front/plugin.php b/front/plugin.php index 16059f2941d471a01a14bcfe3dafce85114b6741..65566bedfd0977a46ca96e15a5301082e416025d 100644 --- a/front/plugin.php +++ b/front/plugin.php @@ -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"); diff --git a/inc/console/application.class.php b/inc/console/application.class.php index a5a128c220bc4b715ca667181924c6503d1b8afa..063bca107bc791b6f332d59e4a74aea3b26a751e 100644 --- a/inc/console/application.class.php +++ b/inc/console/application.class.php @@ -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) { diff --git a/inc/includes.php b/inc/includes.php index 206da5a6a27713dc987b12b17afa3c667448bddf..657b7b4844ff5500e971b004001219f0551b4a98 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -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)) { diff --git a/inc/plugin.class.php b/inc/plugin.class.php index c9515f9207c4cbd97c9e468e891ec0370d6ad62d..1176d3de789e89b54deb5f85a1c70abd6a9ae47b 100644 --- a/inc/plugin.class.php +++ b/inc/plugin.class.php @@ -89,23 +89,25 @@ class Plugin extends CommonDBTM { /** - * Init plugins list reading plugins directory + * Init plugins list. * * @return void **/ function init() { - global $GLPI_CACHE; - - $this->checkStates(); - $plugins = $this->find(['state' => self::ACTIVATED]); + global $DB, $GLPI_CACHE; - $GLPI_CACHE->set('plugins_init', true); $GLPI_CACHE->set('plugins', []); - if (count($plugins)) { - foreach ($plugins as $ID => $plug) { - $this->setLoaded($ID, $plug['directory']); - } + if (!$DB->connected) { + // Cannot init plugins list if DB is not connected + 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 { * 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,13 +247,15 @@ class Plugin extends CommonDBTM { $directories[] = $plugin['directory']; } - // Add found directories to the check list - $plugins_directory = GLPI_ROOT."/plugins"; - $directory_handle = opendir($plugins_directory); - while (false !== ($filename = readdir($directory_handle))) { - if (!in_array($filename, ['.svn', '.', '..']) - && is_dir($plugins_directory . DIRECTORY_SEPARATOR . $filename)) { - $directories[] = $filename; + if ($scan_for_new_plugins) { + // Add found directories to the check list + $plugins_directory = GLPI_ROOT."/plugins"; + $directory_handle = opendir($plugins_directory); + while (false !== ($filename = readdir($directory_handle))) { + if (!in_array($filename, ['.svn', '.', '..']) + && is_dir($plugins_directory . DIRECTORY_SEPARATOR . $filename)) { + $directories[] = $filename; + } } } @@ -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'); } /**