mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 11:49:56 +03:00
feature:2950 add function request_plugin_update()
git-svn-id: http://piwigo.org/svn/trunk@24160 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
6eab56e705
commit
8dc9978c02
1 changed files with 38 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue