aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2013-11-08 23:29:38 +0000
committermistic100 <mistic@piwigo.org>2013-11-08 23:29:38 +0000
commit76fc9c27dcc0c9da1b12385027c2cc937f7f969e (patch)
tree2159ef548cade6230b95ab7368843f31265dce60 /include
parent88001efb9042bbe8b1b0c7e9c46ad0f7a0919af5 (diff)
feature 2998: Maintenance class for plugin
git-svn-id: http://piwigo.org/svn/trunk@25406 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions_plugins.inc.php148
1 files changed, 110 insertions, 38 deletions
diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php
index 03dcbf851..62a4796ae 100644
--- a/include/functions_plugins.inc.php
+++ b/include/functions_plugins.inc.php
@@ -31,9 +31,118 @@ string.
*/
define('PHPWG_PLUGINS_PATH', PHPWG_ROOT_PATH.'plugins/');
-
define('EVENT_HANDLER_PRIORITY_NEUTRAL', 50);
+
+/**
+ * class PluginMaintain
+ * used to declare maintenance methods of a plugin
+ */
+abstract class PluginMaintain
+{
+ protected $plugin_id;
+
+ function __construct($id)
+ {
+ $this->plugin_id = $id;
+ }
+
+ abstract function install($plugin_version, &$errors=array());
+ abstract function activate($plugin_version, &$errors=array());
+ abstract function deactivate();
+ abstract function uninstall();
+
+ /*
+ * test if a plugin needs to be updated and call a update function
+ * @param: string $version, version exposed by the plugin
+ * @param: string $on_update, name of a method to call when an update is needed
+ * it receives the previous version as first parameter
+ */
+ function autoUpdate($version, $on_update=null)
+ {
+ global $pwg_loaded_plugins;
+
+ $current_version = $pwg_loaded_plugins[$this->plugin_id]['version'];
+
+ if ( $version == 'auto' or $current_version == 'auto'
+ or version_compare($current_version, $version, '<')
+ )
+ {
+ if (!empty($on_update))
+ {
+ call_user_func(array(&$this, $on_update), $current_version);
+ }
+
+ if ($version != 'auto')
+ {
+ $query = '
+UPDATE '. PLUGINS_TABLE .'
+ SET version = "'. $version .'"
+ WHERE id = "'. $this->plugin_id .'"
+;';
+ pwg_query($query);
+
+ $pwg_loaded_plugins[$this->plugin_id]['version'] = $version;
+ }
+ }
+ }
+}
+
+/**
+ * class ThemeMaintain
+ * used to declare maintenance methods of a theme
+ */
+abstract class ThemeMaintain
+{
+ protected $theme_id;
+
+ function __construct($id)
+ {
+ $this->theme_id = $id;
+ }
+
+ abstract function activate($theme_version, &$errors=array());
+ abstract function deactivate();
+ abstract function delete();
+
+ /*
+ * test if a theme needs to be updated and call a update function
+ * @param: string $version, version exposed by the theme
+ * @param: string $on_update, name of a method to call when an update is needed
+ * it receives the previous version as first parameter
+ */
+ function autoUpdate($version, $on_update=null)
+ {
+ $query = '
+SELECT version
+ FROM '. THEMES_TABLE .'
+ WHERE id = "'. $this->theme_id .'"
+;';
+ list($current_version) = pwg_db_fetch_row(pwg_query($query));
+
+ if ( $version == 'auto' or $current_version == 'auto'
+ or version_compare($current_version, $version, '<')
+ )
+ {
+ if (!empty($on_update))
+ {
+ call_user_func(array(&$this, $on_update), $current_version);
+ }
+
+ if ($version != 'auto')
+ {
+ $query = '
+UPDATE '. THEMES_TABLE .'
+ SET version = "'. $version .'"
+ WHERE id = "'. $this->theme_id .'"
+;';
+ pwg_query($query);
+ }
+ }
+ }
+}
+
+
/* Register a event handler.
* @param string $event the name of the event to listen to
* @param mixed $func the function that will handle the event
@@ -253,41 +362,4 @@ function load_plugins()
}
}
-/*
- * test if a plugin needs to be updated and call a update function
- * @param: string $plugin_id, id of the plugin as seen in PLUGINS_TABLE and $pwg_loaded_plugins
- * @param: string $version, version exposed by the plugin
- * @param: callable $on_update, function to call when and update is needed
- * it receives the previous version as first parameter
- */
-function request_plugin_update($plugin_id, $version, $on_update)
-{
- global $pwg_loaded_plugins;
-
- if (
- $version == 'auto' or
- $pwg_loaded_plugins[$plugin_id]['version'] == 'auto' or
- version_compare($pwg_loaded_plugins[$plugin_id]['version'], $version, '<')
- )
- {
- // call update function
- if (!empty($on_update))
- {
- call_user_func($on_update, $pwg_loaded_plugins[$plugin_id]['version']);
- }
-
- // update plugin version in database
- if ($version != 'auto')
- {
- $query = '
-UPDATE '. PLUGINS_TABLE .'
-SET version = "'. $version .'"
-WHERE id = "'. $plugin_id .'"';
- pwg_query($query);
-
- $pwg_loaded_plugins[$plugin_id]['version'] = $version;
- }
- }
-}
-
?> \ No newline at end of file