From cf76dd744d3a51b59952e80a7bf21fadcb2e0980 Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Wed, 28 Dec 2016 17:30:33 +0300 Subject: [PATCH] Store plugin initialization status in the database --- src/mibew/libs/classes/Mibew/Plugin/PluginInfo.php | 11 +++++++++++ src/mibew/libs/classes/Mibew/Plugin/PluginManager.php | 11 +++++++++++ src/mibew/libs/classes/Mibew/Plugin/State.php | 10 +++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Plugin/PluginInfo.php b/src/mibew/libs/classes/Mibew/Plugin/PluginInfo.php index ed3299fa..a233cb51 100644 --- a/src/mibew/libs/classes/Mibew/Plugin/PluginInfo.php +++ b/src/mibew/libs/classes/Mibew/Plugin/PluginInfo.php @@ -81,6 +81,7 @@ class PluginInfo $state->version = false; $state->installed = false; $state->enabled = false; + $state->initialized = false; } $this->pluginState = $state; } @@ -209,6 +210,16 @@ class PluginInfo return new $plugin_class($configs); } + /** + * Checks if the plugin is initialized. + * + * @return bool + */ + public function isInitialized() + { + return $this->getState()->initialized; + } + /** * Checks if the plugin is enabled. * diff --git a/src/mibew/libs/classes/Mibew/Plugin/PluginManager.php b/src/mibew/libs/classes/Mibew/Plugin/PluginManager.php index 534619a4..0209c292 100644 --- a/src/mibew/libs/classes/Mibew/Plugin/PluginManager.php +++ b/src/mibew/libs/classes/Mibew/Plugin/PluginManager.php @@ -181,12 +181,22 @@ class PluginManager $this->loadedPlugins[$name] = $instance; $running_queue[$instance->getWeight() . "_" . $offset] = $instance; $offset++; + if (!$plugin_info->isInitialized()) { + $plugin_info->getState()->initialized = true; + $plugin_info->getState()->save(); +# TODO: clear cache + } } else { // The plugin cannot be loaded. Just skip it. trigger_error( "Plugin '{$name}' was not initialized correctly!", E_USER_WARNING ); + if ($plugin_info->isInitialized()) { + $plugin_info->getState()->initialized = false; + $plugin_info->getState()->save(); +# TODO: clear cache + } } } @@ -256,6 +266,7 @@ class PluginManager } $plugin->getState()->enabled = false; + $plugin->getState()->initialized = false; $plugin->getState()->save(); return true; diff --git a/src/mibew/libs/classes/Mibew/Plugin/State.php b/src/mibew/libs/classes/Mibew/Plugin/State.php index 730e80e8..84ed01f5 100644 --- a/src/mibew/libs/classes/Mibew/Plugin/State.php +++ b/src/mibew/libs/classes/Mibew/Plugin/State.php @@ -193,6 +193,7 @@ class State $this->version = null; $this->installed = false; $this->enabled = false; + $this->initialized = false; } /** @@ -205,13 +206,14 @@ class State if (!$this->id) { // This state is new. $db->query( - ("INSERT INTO {plugin} (name, version, installed, enabled) " - . "VALUES (:name, :version, :installed, :enabled)"), + ("INSERT INTO {plugin} (name, version, installed, enabled, initialized) " + . "VALUES (:name, :version, :installed, :enabled, :initialized)"), array( ':name' => $this->pluginName, ':version' => $this->version, ':installed' => (int)$this->installed, ':enabled' => (int)$this->enabled, + ':initialized' => (int)$this->initialized, ) ); $this->id = $db->insertedId(); @@ -219,13 +221,14 @@ class State // Update existing state $db->query( ("UPDATE {plugin} SET name = :name, version = :version, " - . "installed = :installed, enabled = :enabled WHERE id = :id"), + . "installed = :installed, enabled = :enabled, initialized = :initialized WHERE id = :id"), array( ':id' => $this->id, ':name' => $this->pluginName, ':version' => $this->version, ':installed' => (int)$this->installed, ':enabled' => (int)$this->enabled, + ':initialized' => (int)$this->initialized, ) ); } @@ -261,5 +264,6 @@ class State $this->version = $db_fields['version']; $this->enabled = (bool)$db_fields['enabled']; $this->installed = (bool)$db_fields['installed']; + $this->initialized = (bool)$db_fields['initialized']; } }