aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/include/plugins.class.php157
-rw-r--r--include/functions_plugins.inc.php73
-rw-r--r--include/ws_functions/pwg.extensions.php2
3 files changed, 138 insertions, 94 deletions
diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php
index 25030b6a2..71093a6c1 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,14 +116,17 @@ 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]))
{
$crt_db_plugin = $this->db_plugins_by_id[$plugin_id];
}
- $plugin_maintain = self::build_maintain_class($plugin_id);
+ if ($action !== 'update')
+ { // wait for files to be updated
+ $plugin_maintain = self::build_maintain_class($plugin_id);
+ }
$errors = array();
@@ -145,6 +150,31 @@ INSERT INTO '. PLUGINS_TABLE .' (id,version)
}
break;
+ case 'update':
+ $previous_version = $this->fs_plugins[$plugin_id]['version'];
+ $errors[0] = $this->extract_plugin_files('upgrade', $options['revision'], $plugin_id);
+
+ if ($errors[0] === 'ok')
+ {
+ $this->get_fs_plugin($plugin_id); // refresh plugins list
+ $new_version = $this->fs_plugins[$plugin_id]['version'];
+
+ $plugin_maintain = self::build_maintain_class($plugin_id);
+ $plugin_maintain->update($previous_version, $new_version, $errors);
+
+ if ($new_version != 'auto')
+ {
+ $query = '
+UPDATE '. PLUGINS_TABLE .'
+ SET version=\''. $new_version .'\'
+ WHERE id=\''. $plugin_id .'\'
+;';
+ pwg_query($query);
+ }
+ }
+
+ break;
+
case 'activate':
if (!isset($crt_db_plugin))
{
@@ -166,8 +196,7 @@ INSERT INTO '. PLUGINS_TABLE .' (id,version)
{
$query = '
UPDATE '. PLUGINS_TABLE .'
- SET state=\'active\',
- version=\''. $this->fs_plugins[$plugin_id]['version'] .'\'
+ SET state=\'active\'
WHERE id=\''. $plugin_id .'\'
;';
pwg_query($query);
@@ -242,58 +271,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 +281,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')
diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php
index 5790eccf7..8700a599f 100644
--- a/include/functions_plugins.inc.php
+++ b/include/functions_plugins.inc.php
@@ -376,59 +376,56 @@ function load_plugin($plugin)
*/
function autoupdate_plugin(&$plugin)
{
- $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php';
+ // try to find the filesystem version in lines 2 to 10 of main.inc.php
+ $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r');
+ $fs_version = null;
+ $i = -1;
- // autoupdate is applicable only to plugins with 2.7 architecture
- if (file_exists($maintain_file))
+ while (($line = fgets($fh))!==false && $fs_version==null && $i<10)
{
- // try to find the filesystem version in lines 2 to 10 of main.inc.php
- $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r');
- $fs_version = null;
- $i = -1;
+ $i++;
+ if ($i < 2) continue; // first lines are typically "<?php" and "/*"
- while (($line = fgets($fh))!==false && $fs_version==null && $i<10)
+ if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches))
{
- $i++;
- if ($i < 2) continue; // first lines are typically "<?php" and "/*"
-
- if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches))
- {
- $fs_version = $matches[1];
- }
+ $fs_version = $matches[1];
}
+ }
- fclose($fh);
+ fclose($fh);
- if ($fs_version != null)
- {
- global $pwg_loaded_plugins, $page;
+ // if version is auto (dev) or superior
+ if ($fs_version != null && (
+ $fs_version == 'auto' || $plugin['version'] == 'auto' ||
+ safe_version_compare($plugin['version'], $fs_version, '<')
+ )
+ ) {
+ $plugin['version'] = $fs_version;
- // if version is auto (dev) or superior
- if (
- $fs_version == 'auto' or $plugin['version'] == 'auto'
- or safe_version_compare($plugin['version'], $fs_version, '<')
- )
- {
- // call update method
- include_once($maintain_file);
+ $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php';
- $classname = $plugin['id'].'_maintain';
- $plugin_maintain = new $classname($plugin['id']);
- $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']);
+ // autoupdate is applicable only to plugins with 2.7 architecture
+ if (file_exists($maintain_file))
+ {
+ global $page;
- $plugin['version'] = $fs_version;
+ // call update method
+ include_once($maintain_file);
- // update database (only on production)
- if ($plugin['version'] != 'auto')
- {
- $query = '
+ $classname = $plugin['id'].'_maintain';
+ $plugin_maintain = new $classname($plugin['id']);
+ $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']);
+ }
+
+ // update database (only on production)
+ if ($plugin['version'] != 'auto')
+ {
+ $query = '
UPDATE '. PLUGINS_TABLE .'
SET version = "'. $plugin['version'] .'"
WHERE id = "'. $plugin['id'] .'"
;';
- pwg_query($query);
- }
- }
+ pwg_query($query);
}
}
}
diff --git a/include/ws_functions/pwg.extensions.php b/include/ws_functions/pwg.extensions.php
index 8a308ff3d..6ed2803bc 100644
--- a/include/ws_functions/pwg.extensions.php
+++ b/include/ws_functions/pwg.extensions.php
@@ -188,7 +188,7 @@ function ws_extensions_update($params, $service)
);
}
- $upgrade_status = $extension->extract_plugin_files('upgrade', $revision, $extension_id);
+ list($upgrade_status) = $extension->perform_action('update', $extension_id, array('revision'=>$revision));
$extension_name = $extension->fs_plugins[$extension_id]['name'];
if (isset($params['reactivate']))