aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-09-24 17:30:08 +0000
committermistic100 <mistic@piwigo.org>2014-09-24 17:30:08 +0000
commit17a72f2bb20ab7e84829d217345867a0b4fa6687 (patch)
tree8c571455eb5b45bf5c4eaca7d0ba7b42dcbe6391 /admin
parentd74b80bbb7401874ea73f93bf557dc80153fbdb6 (diff)
fix plugins autoupdate: call ##_maintain::update when updating from back-office
git-svn-id: http://piwigo.org/svn/trunk@29773 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/include/plugins.class.php137
1 files changed, 85 insertions, 52 deletions
diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php
index 25030b6a2..8e9c682a7 100644
--- a/admin/include/plugins.class.php
+++ b/admin/include/plugins.class.php
@@ -89,12 +89,14 @@ class plugins
$file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain';
$classname = $plugin_id.'_maintain';
+ // 2.7 pattern (OO only)
if (file_exists($file_to_include.'.class.php'))
{
include_once($file_to_include.'.class.php');
return new $classname($plugin_id);
}
+ // before 2.7 pattern (OO or procedural)
if (file_exists($file_to_include.'.inc.php'))
{
include_once($file_to_include.'.inc.php');
@@ -114,7 +116,7 @@ class plugins
* @param string - plugin id
* @param array - errors
*/
- function perform_action($action, $plugin_id)
+ function perform_action($action, $plugin_id, $options=array())
{
if (isset($this->db_plugins_by_id[$plugin_id]))
{
@@ -145,6 +147,19 @@ INSERT INTO '. PLUGINS_TABLE .' (id,version)
}
break;
+ case 'update':
+ $previous_version = $this->fs_plugins[$plugin_id]['version'];
+ $upgrade_status = $this->extract_plugin_files('upgrade', $options['revision'], $plugin_id);
+
+ if ($upgrade_status === 'ok')
+ {
+ $this->get_fs_plugin($plugin_id); // refresh plugins list
+ $plugin_maintain->update($previous_version, $this->fs_plugins[$plugin_id]['version']);
+ }
+
+ return $upgrade_status;
+ break;
+
case 'activate':
if (!isset($crt_db_plugin))
{
@@ -242,58 +257,9 @@ DELETE FROM '. PLUGINS_TABLE .'
{
if ($file!='.' and $file!='..')
{
- $path = PHPWG_PLUGINS_PATH.$file;
- if (is_dir($path) and !is_link($path)
- and preg_match('/^[a-zA-Z0-9-_]+$/', $file )
- and file_exists($path.'/main.inc.php')
- )
+ if (preg_match('/^[a-zA-Z0-9-_]+$/', $file))
{
- $plugin = array(
- 'name'=>$file,
- 'version'=>'0',
- 'uri'=>'',
- 'description'=>'',
- 'author'=>'',
- );
- $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048);
-
- if (preg_match("|Plugin Name:\\s*(.+)|", $plg_data, $val))
- {
- $plugin['name'] = trim( $val[1] );
- }
- if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val))
- {
- $plugin['version'] = trim($val[1]);
- }
- if (preg_match("|Plugin URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
- {
- $plugin['uri'] = trim($val[1]);
- }
- if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
- {
- $plugin['description'] = trim($desc);
- }
- elseif (preg_match("|Description:\\s*(.+)|", $plg_data, $val))
- {
- $plugin['description'] = trim($val[1]);
- }
- if (preg_match("|Author:\\s*(.+)|", $plg_data, $val))
- {
- $plugin['author'] = trim($val[1]);
- }
- if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
- {
- $plugin['author uri'] = trim($val[1]);
- }
- if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
- {
- list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
- if (is_numeric($extension)) $plugin['extension'] = $extension;
- }
-
- // IMPORTANT SECURITY !
- $plugin = array_map('htmlspecialchars', $plugin);
- $this->fs_plugins[$file] = $plugin;
+ $this->get_fs_plugin($file);
}
}
}
@@ -301,6 +267,73 @@ DELETE FROM '. PLUGINS_TABLE .'
}
/**
+ * Load metadata of a plugin in `fs_plugins` array
+ * @from 2.7
+ * @param $plugin_id
+ * @return false|array
+ */
+ function get_fs_plugin($plugin_id)
+ {
+ $path = PHPWG_PLUGINS_PATH.$plugin_id;
+
+ if (is_dir($path) and !is_link($path)
+ and file_exists($path.'/main.inc.php')
+ )
+ {
+ $plugin = array(
+ 'name'=>$plugin_id,
+ 'version'=>'0',
+ 'uri'=>'',
+ 'description'=>'',
+ 'author'=>'',
+ );
+ $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048);
+
+ if (preg_match("|Plugin Name:\\s*(.+)|", $plg_data, $val))
+ {
+ $plugin['name'] = trim( $val[1] );
+ }
+ if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val))
+ {
+ $plugin['version'] = trim($val[1]);
+ }
+ if (preg_match("|Plugin URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
+ {
+ $plugin['uri'] = trim($val[1]);
+ }
+ if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
+ {
+ $plugin['description'] = trim($desc);
+ }
+ elseif (preg_match("|Description:\\s*(.+)|", $plg_data, $val))
+ {
+ $plugin['description'] = trim($val[1]);
+ }
+ if (preg_match("|Author:\\s*(.+)|", $plg_data, $val))
+ {
+ $plugin['author'] = trim($val[1]);
+ }
+ if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
+ {
+ $plugin['author uri'] = trim($val[1]);
+ }
+ if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
+ {
+ list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
+ if (is_numeric($extension)) $plugin['extension'] = $extension;
+ }
+
+ // IMPORTANT SECURITY !
+ $plugin = array_map('htmlspecialchars', $plugin);
+ $this->fs_plugins[$plugin_id] = $plugin;
+
+ return $plugin;
+ }
+
+ return false;
+ }
+
+ /**
* Sort fs_plugins
*/
function sort_fs_plugins($order='name')