mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-08-10 02:33:02 +02:00
feature 2998: Maintenance class for plugin
git-svn-id: http://piwigo.org/svn/trunk@25406 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user