diff options
author | mistic100 <mistic@piwigo.org> | 2013-08-14 21:30:28 +0000 |
---|---|---|
committer | mistic100 <mistic@piwigo.org> | 2013-08-14 21:30:28 +0000 |
commit | 8dc9978c020e3cd00eadfe96925e539a5a9f2e21 (patch) | |
tree | 8d1eef01e59008221b01c685c90e510a63c8cee7 | |
parent | 6eab56e705c34cf2e02b6946f92ddf3e6408ad32 (diff) |
feature:2950 add function request_plugin_update()
git-svn-id: http://piwigo.org/svn/trunk@24160 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/functions_plugins.inc.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php index 7d6da7289..e11e35dc5 100644 --- a/include/functions_plugins.inc.php +++ b/include/functions_plugins.inc.php @@ -252,4 +252,42 @@ function load_plugins() trigger_action('plugins_loaded'); } } + +/* + * 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 |