1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

Plugin upgrade SQL execution logic mismatch

This commit is contained in:
secretr
2010-06-23 10:21:21 +00:00
parent 1adf1d6179
commit fe0926b9cf
2 changed files with 766 additions and 804 deletions

View File

@@ -478,9 +478,11 @@ class pluginManager{
if (is_array($upgrade_alter_tables))
{
$result = $plugin->manage_tables('upgrade', $upgrade_alter_tables);
if (!$result)
if (true !== $result)
{
$text .= EPL_ADLAN_9.'<br />';
//$text .= EPL_ADLAN_9.'<br />';
$emessage->addWarning(EPL_ADLAN_9)
->addDebug($result);
}
else
{

View File

@@ -15,8 +15,10 @@
*
*/
if (!defined('e107_INIT')) { exit; }
if (!defined('e107_INIT'))
{
exit;
}
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_plugin.php');
@@ -103,7 +105,6 @@ class e107plugin
var $unInstallOpts;
var $module = array();
function e107plugin()
{
$parsed_plugin = array();
@@ -126,7 +127,6 @@ class e107plugin
return false;
}
/**
* Check for new plugins, create entry in plugin table and remove deleted plugins
*/
@@ -144,6 +144,7 @@ class e107plugin
$pluginDBList = array();
if ($sql->db_Select('plugin', "*")) // Read all the plugin DB info into an array to save lots of accesses
{
while ($row = $sql->db_Fetch(MYSQL_ASSOC))
{
@@ -155,6 +156,7 @@ class e107plugin
$plugList = $fl->get_files(e_PLUGIN, "^plugin\.(php|xml)$", "standard", 1);
foreach ($plugList as $num => $val) // Remove Duplicates caused by having both plugin.php AND plugin.xml.
{
$key = basename($val['path']);
$pluginList[$key] = $val;
@@ -176,8 +178,6 @@ class e107plugin
}
$plug['plug_action'] = 'scan'; // Make sure plugin.php knows what we're up to
if (!$this->parse_plugin($p['path']))
{
//parsing of plugin.php/plugin.xml failed.
@@ -203,7 +203,6 @@ class e107plugin
$pluginDBList[$plugin_path]['plugin_category'] = (varsettrue($plug_info['category'])) ? $plug_info['category'] : "misc";
}
// If plugin not installed, and version number of files changed, update version as well
if (($pluginDBList[$plugin_path]['plugin_installflag'] == 0) && ($pluginDBList[$plugin_path]['plugin_version'] != $plug_info['@attributes']['version']))
{ // Update stored version
@@ -217,6 +216,7 @@ class e107plugin
}
if ($pluginDBList[$plugin_path]['plugin_installflag'] == 0) // Plugin not installed - make sure $pref not set
{
if (isset($p_installed[$plugin_path]))
{
@@ -239,10 +239,12 @@ class e107plugin
if ($plug_info['@attributes']['name'])
{
$_installed = ($plug_info['@attributes']['installRequired'] == 'true' || $plug_info['@attributes']['installRequired'] == 1 ? 0 : 1);
if(e107::getDb()->db_Insert("plugin", "0, '".$tp -> toDB($plug_info['@attributes']['name'], true)."', '".$tp -> toDB($plug_info['@attributes']['version'], true)."', '".$tp -> toDB($plugin_path, true)."', {$_installed}, '{$eplug_addons}', '".$this->manage_category($plug_info['category'])."', '".varset($plug_info['@attributes']['releaseUrl'])."' "))
if (e107::getDb()->db_Insert("plugin", "0, '".$tp->toDB($plug_info['@attributes']['name'], true)."', '".$tp->toDB($plug_info['@attributes']['version'], true)."', '".$tp->toDB($plugin_path, true)."',
{
$_installed}, '
{
$eplug_addons}', '".$this->manage_category($plug_info['category'])."', '".varset($plug_info['@attributes']['releaseUrl'])."' ")){
$mes->add("Added <b>".$plug_info['@attributes']['name']."</b> to the plugin table.", E_MESSAGE_DEBUG);
}
else
@@ -286,7 +288,6 @@ class e107plugin
}
}
function manage_category($cat)
{
if (vartrue($cat) && in_array($cat, $this->accepted_categories))
@@ -318,7 +319,6 @@ class e107plugin
return;
}
if ($function == 'uninstall')
{
if (vartrue($this->unInstallOpts['delete_ipool'], FALSE))
@@ -341,7 +341,10 @@ class e107plugin
{
$sql = e107::getDb();
static $getinfo_results;
if(!is_array($getinfo_results)) { $getinfo_results = array(); }
if (!is_array($getinfo_results))
{
$getinfo_results = array();
}
$id = (int) $id;
if (!isset($getinfo_results[$id]) || $force == true)
@@ -382,7 +385,6 @@ class e107plugin
}
}
function manage_userclass($action, $class_name, $class_description)
{
global $e107;
@@ -428,8 +430,7 @@ class e107plugin
if ($action == 'remove')
{
$classID = $e107->user_class->ucGetClassIDFromName($class_name);
if (($classID !== FALSE)
&& ($e107->user_class->deleteClassAndUsers($classID) === TRUE))
if (($classID !== FALSE) && ($e107->user_class->deleteClassAndUsers($classID) === TRUE))
{
return TRUE;
}
@@ -440,8 +441,6 @@ class e107plugin
}
}
function manage_link($action, $link_url, $link_name, $link_class = 0)
{
@@ -490,8 +489,7 @@ class e107plugin
}
if ($action == 'remove')
{ // Look up by URL if we can - should be more reliable. Otherwise try looking up by name (as previously)
if (($path && $sql->db_Select('links', 'link_id,link_order', "link_url = '{$path}'")) ||
$sql->db_Select('links', 'link_id,link_order', "link_name = '{$link_name}'"))
if (($path && $sql->db_Select('links', 'link_id,link_order', "link_url = '{$path}'")) || $sql->db_Select('links', 'link_id,link_order', "link_name = '{$link_name}'"))
{
$row = $sql->db_Fetch();
$sql->db_Update('links', "link_order = link_order - 1 WHERE link_order > {$row['link_order']}");
@@ -500,16 +498,16 @@ class e107plugin
}
}
// DEPRECATED in 0.8 - See XmlPrefs(); Left for BC.
// Update prefs array according to $action
// $prefType specifies the storage type - may be 'pref', 'listPref' or 'arrayPref'
function manage_prefs($action, $var, $prefType = 'pref', $path = '', $unEscape = FALSE)
{
global $pref;
if (!is_array($var)) return;
if (($prefType == 'arrayPref') && ($path == '')) return;
if (!is_array($var))
return;
if (($prefType == 'arrayPref') && ($path == ''))
return;
foreach ($var as $k => $v)
{
if ($unEscape)
@@ -528,7 +526,8 @@ class e107plugin
case 'update':
case 'refresh':
// Only update if $pref doesn't exist
if (!isset($pref[$k])) $pref[$k] = $v;
if (!isset($pref[$k]))
$pref[$k] = $v;
break;
case 'remove':
@@ -545,16 +544,19 @@ class e107plugin
break;
case 'listPref':
$tmp = array();
if (isset($pref[$k])) $tmp = explode(',',$pref[$k]);
if (isset($pref[$k]))
$tmp = explode(',', $pref[$k]);
switch ($action)
{
case 'add':
case 'update':
case 'refresh':
if (!in_array($v,$tmp)) $tmp[] = $v;
if (!in_array($v, $tmp))
$tmp[] = $v;
break;
case 'remove':
if (($tkey = array_search($v,$tmp)) !== FALSE) unset($tmp[$tkey]);
if (($tkey = array_search($v, $tmp)) !== FALSE)
unset($tmp[$tkey]);
break;
}
$pref[$k] = implode(',', $tmp); // Leaves an empty element if no values - probably acceptable or even preferable
@@ -567,10 +569,12 @@ class e107plugin
break;
case 'update':
case 'refresh':
if (!isset($pref[$k][$path])) $pref[$k][$path] = $v;
if (!isset($pref[$k][$path]))
$pref[$k][$path] = $v;
break;
case 'remove':
if (isset($pref[$k][$path])) unset($pref[$k][$path]); // Leaves an empty element if no values - probably acceptable or even preferable
if (isset($pref[$k][$path]))
unset($pref[$k][$path]); // Leaves an empty element if no values - probably acceptable or even preferable
break;
}
break;
@@ -582,9 +586,6 @@ class e107plugin
// e107::getConfig()->loadData($pref, false)->save(false, true);
}
function manage_comments($action, $comment_id)
{
$sql = e107::getDb();
@@ -603,8 +604,6 @@ class e107plugin
}
}
// Handle table updates - passed an array of actions.
// $var array:
// For 'add' - its a query to create the table
@@ -614,29 +613,31 @@ class e107plugin
function manage_tables($action, $var)
{
$sql = e107::getDB();
if (!is_array($var)) return FALSE; // Return if nothing to do
if (!is_array($var))
return FALSE; // Return if nothing to do
$error = false;
$error_data = array();
switch ($action)
{
case 'add':
foreach ($var as $tab)
{
if (!$sql->db_Query($tab))
if (false === $sql->db_Query($tab))
{
return FALSE;
$error = true;
$error_data[] = $tab;
}
}
return TRUE;
break;
case 'upgrade':
foreach ($var as $tab)
{
if (!$sql->db_Query_all($tab))
if (false === $sql->db_Query_all($tab))
{
return FALSE;
$error = true;
$error_data[] = $tab;
}
}
return TRUE;
break;
case 'remove':
foreach ($var as $tab)
@@ -644,16 +645,17 @@ class e107plugin
$qry = 'DROP TABLE '.MPREFIX.$tab;
if (!$sql->db_Query_all($qry))
{
return $tab;
$error = true;
$error_data[] = $tab;
}
}
return TRUE;
break;
}
return FALSE;
// doesn't exit the loop now, returns true on success
// or error queries (string)
return (!$error ? true : (!empty($$error_data) ? implode('<br />', $error_data) : false));
}
// DEPRECATED for 0.8 xml files - See XmlPrefs();
// Handle prefs from arrays (mostly 0.7 stuff, possibly apart from the special cases)
function manage_plugin_prefs($action, $prefname, $plugin_folder, $varArray = '')
@@ -703,18 +705,13 @@ class e107plugin
}
function manage_search($action, $eplug_folder)
{
global $sysprefs;
$sql = e107::getDb();
$search_prefs = e107::getConfig('search')->getPref();
// $search_prefs = $sysprefs -> getArray('search_prefs');
$default = file_exists(e_PLUGIN.$eplug_folder.'/e_search.php') ? TRUE : FALSE;
$comments = file_exists(e_PLUGIN.$eplug_folder.'/search/search_comments.php') ? TRUE : FALSE;
@@ -723,12 +720,14 @@ class e107plugin
$install_default = $default ? TRUE : FALSE;
$install_comments = $comments ? TRUE : FALSE;
}
else if ($action == 'remove')
else
if ($action == 'remove')
{
$uninstall_default = isset($search_prefs['plug_handlers'][$eplug_folder]) ? TRUE : FALSE;
$uninstall_comments = isset($search_prefs['comments_handlers'][$eplug_folder]) ? TRUE : FALSE;
}
else if ($action == 'upgrade')
else
if ($action == 'upgrade')
{
if (isset($search_prefs['plug_handlers'][$eplug_folder]))
{
@@ -751,7 +750,8 @@ class e107plugin
{
$search_prefs['plug_handlers'][$eplug_folder] = array('class' => 0, 'pre_title' => 1, 'pre_title_alt' => '', 'chars' => 150, 'results' => 10);
}
else if (vartrue($uninstall_default))
else
if (vartrue($uninstall_default))
{
unset($search_prefs['plug_handlers'][$eplug_folder]);
}
@@ -760,7 +760,8 @@ class e107plugin
require_once(e_PLUGIN.$eplug_folder.'/search/search_comments.php');
$search_prefs['comments_handlers'][$eplug_folder] = array('id' => $comments_type_id, 'class' => 0, 'dir' => $eplug_folder);
}
else if (vartrue($uninstall_comments))
else
if (vartrue($uninstall_comments))
{
unset($search_prefs['comments_handlers'][$eplug_folder]);
}
@@ -781,11 +782,13 @@ class e107plugin
{
$install_notify = $e_notify ? TRUE : FALSE;
}
else if ($action == 'remove')
else
if ($action == 'remove')
{
$uninstall_notify = $notify_prefs->isData('plugins/'.$eplug_folder); //isset($notify_prefs['plugins'][$eplug_folder]) ? TRUE : FALSE;
}
else if ($action == 'upgrade')
else
if ($action == 'upgrade')
{
if ($notify_prefs->isData('plugins/'.$eplug_folder))
{
@@ -807,7 +810,8 @@ class e107plugin
//$notify_prefs['event'][$event_id] = array('class' => e_UC_NOBODY, 'email' => '');
}
}
else if (vartrue($uninstall_notify))
else
if (vartrue($uninstall_notify))
{
$notify_prefs->removePref('plugins/'.$eplug_folder);
//unset($notify_prefs['plugins'][$eplug_folder]);
@@ -866,7 +870,6 @@ class e107plugin
$this->plugFolder = $plug['plugin_path'];
$this->unInstallOpts = $options;
$addons = explode(',', $plug['plugin_addons']);
$sql_list = array();
foreach ($addons as $addon)
@@ -883,7 +886,6 @@ class e107plugin
$canContinue = FALSE;
}
if ($canContinue && $this->parse_plugin_xml($plug['plugin_path']))
{
$plug_vars = $this->plug_vars;
@@ -915,12 +917,13 @@ class e107plugin
if ($canContinue)
{
$ret = $this->execute_function($path, $function, 'pre');
if (!is_bool($ret)) $txt .= $ret;
if (!is_bool($ret))
$txt .= $ret;
}
if ($canContinue && count($sql_list)) // TODO - move to it's own function.
{ // Handle tables
{ // Handle tables
require_once(e_HANDLER.'db_table_admin_class.php');
$dbHandler = new db_table_admin;
@@ -934,7 +937,6 @@ class e107plugin
}
// Got the required definition here
foreach ($tableList as $ct)
{ // Process one table at a time (but they could be multi-language)
switch ($function)
@@ -980,18 +982,19 @@ class e107plugin
$this->XmlAdminLinks($function, $plug_vars['adminLinks']);
}
if (varset($plug_vars['siteLinks']))
{
$this->XmlSiteLinks($function, $plug_vars['siteLinks']);
}
if (varset($plug_vars['mainPrefs'])) //Core pref items <mainPrefs>
{
$this->XmlPrefs('core', $function, $plug_vars['mainPrefs']);
}
if (varset($plug_vars['pluginPrefs'])) //Plugin pref items <pluginPrefs>
{
$this->XmlPrefs($plug['plugin_path'], $function, $plug_vars['pluginPrefs']);
}
@@ -1013,7 +1016,6 @@ class e107plugin
$this->manage_icons($this->plugFolder, $function);
//FIXME
//If any commentIDs are configured, we need to remove all comments on uninstall
if ($function == 'uninstall' && isset($plug_vars['commentID']))
@@ -1046,7 +1048,6 @@ class e107plugin
}
e107::getConfig('core')->save();
/* if($function == 'install')
@@ -1058,6 +1059,7 @@ class e107plugin
}*/
if (!$this->execute_function($path, $function, 'post')) // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
{
if ($function == 'install')
{
@@ -1075,10 +1077,6 @@ class e107plugin
}
/**
* Process XML Tag <dependencies> (deprecated 'depend' which is a brand of adult diapers)
* @param array $tag
@@ -1150,12 +1148,6 @@ class e107plugin
return $canContinue;
}
/**
* Process XML Tag <LanguageFiles>
* @param object $function
@@ -1171,6 +1163,7 @@ class e107plugin
$att = $val['@attributes'];
if ($when == 'pre') // just check for install language file BEFORE install.
{
if ($att['type'] == 'install')
{
@@ -1195,11 +1188,8 @@ class e107plugin
}
}
}
}
/**
* Process XML Tag <siteLinks>
* @param string $function install|upgrade|refresh|uninstall
@@ -1224,12 +1214,14 @@ class e107plugin
case 'install':
if (!$remove) // Add any non-deprecated link
{
$status = ($this->manage_link('add', $url, $linkName, $perm)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add("Adding Link: {$linkName} with url [{$url}] and perm {$perm} ", $status);
}
if ($function == 'upgrade' && $remove) //remove inactive links on upgrade
{
$status = ($this->manage_link('remove', $url, $linkName)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add("Removing Link: {$linkName} with url [{$url}]", $status);
@@ -1266,8 +1258,6 @@ class e107plugin
}
}
/**
* Process XML Tag <userClasses>
* @param string $function install|upgrade|refresh|uninstall
@@ -1292,13 +1282,14 @@ class e107plugin
case 'refresh':
if (!$remove) // Add all active userclasses (code checks for already installed)
{
$status = $this->manage_userclass('add', $name, $description) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add('Adding Userclass: '.$name, $status);
}
if ($function == 'upgrade' && $remove) //If upgrading, removing any inactive userclass
{
$status = $this->manage_userclass('remove', $name, $description) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add('Removing Userclass: '.$name, $status);
@@ -1306,7 +1297,6 @@ class e107plugin
break;
case 'uninstall': //If uninstalling, remove all userclasses (active or inactive)
if (varsettrue($this->unInstallOpts['delete_userclasses'], FALSE))
@@ -1324,7 +1314,6 @@ class e107plugin
}
}
/**
* Process XML Tag <extendedFields>
* @param string $function install|upgrade|refresh|uninstall
@@ -1356,13 +1345,13 @@ class e107plugin
}
if ($function == 'upgrade' && $remove) //If upgrading, removing any inactive extended fields
{
$status = $this->manage_extended_field('remove', $name, $source) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add('Removing Extended Field: '.$name.' ... ', $status);
}
break;
case 'uninstall': //If uninstalling, remove all extended fields (active or inactive)
if (varsettrue($this->unInstallOpts['delete_xfields'], FALSE))
@@ -1379,7 +1368,6 @@ class e107plugin
}
}
/**
* Process XML tags <mainPrefs> and <pluginPrefs>
* @param object $mode 'core' or the folder name of the plugin.
@@ -1423,6 +1411,7 @@ class e107plugin
case 'upgrade':
case 'refresh':
if ($remove) // remove active='false' prefs.
{
$config->remove($key, $value);
$mes->add("Removing Pref: ".$key, E_MESSAGE_SUCCESS);
@@ -1440,7 +1429,6 @@ class e107plugin
$mes->add("Removing Pref: ".$key, E_MESSAGE_SUCCESS);
break;
}
}
if ($mode != "core") // Do only one core pref save during install/uninstall etc.
@@ -1448,13 +1436,8 @@ class e107plugin
$config->save();
}
return;
}
/**
*
* @param object $path [unused]
@@ -1512,10 +1495,6 @@ class e107plugin
return FALSE; // IMPORTANT.
}
// DEPRECATED - See XMLPrefs();
function parse_prefs($pref_array, $mode = 'simple')
{
@@ -1601,12 +1580,12 @@ class e107plugin
}*/
if (varset($plug_vars['mainPrefs'])) //Core pref items <mainPrefs>
{
$this->XmlPrefs('core', $function, $plug_vars['mainPrefs']);
$text .= EPL_ADLAN_8.'<br />';
}
if (is_array($eplug_array_pref))
{
foreach ($eplug_array_pref as $key => $val)
@@ -1615,7 +1594,6 @@ class e107plugin
}
}
if (varset($plug_vars['siteLinks']))
{
$this->XmlSiteLinks($function, $plug_vars['siteLinks']);
@@ -1648,7 +1626,6 @@ class e107plugin
return $text;
}
/**
* Installs a plugin by ID
*
@@ -1665,7 +1642,6 @@ class e107plugin
$id = (int) $id;
$plug = $this->getinfo($id);
$plug['plug_action'] = 'install';
if (!vartrue($plug['plugin_installflag']))
@@ -1692,8 +1668,8 @@ class e107plugin
$sql = e107::getDb();
$core = e107::getConfig('core');
foreach ($this->plugin_addons as $var) // clear all existing prefs.
{
$core->update($var.'_list', "");
}
@@ -1803,9 +1779,7 @@ class e107plugin
{
$passfail = '';
$file_text = file_get_contents(e_PLUGIN.$plugin_path."/".$addonPHP);
if ((substr($file_text, 0, 5) != '<'.'?php')
|| ( (substr($file_text, -2, 2) != '?'.'>') && (strrpos($file_text, '?'.'>') !== FALSE) )
)
if ((substr($file_text, 0, 5) != '<'.'?php') || ((substr($file_text, -2, 2) != '?'.'>') && (strrpos($file_text, '?'.'>') !== FALSE)))
{
$passfail = '<b>fail</b>';
}
@@ -1851,7 +1825,8 @@ class e107plugin
if (is_readable(e_PLUGIN.$plugin_path."/".$esql['fname']))
{
$fname = str_replace(".php", "", $esql['fname']);
if (!in_array($fname, $p_addons)) $p_addons[] = $fname; // Probably already found - avoid duplication
if (!in_array($fname, $p_addons))
$p_addons[] = $fname; // Probably already found - avoid duplication
}
}
@@ -1868,9 +1843,7 @@ class e107plugin
if (is_readable(e_PLUGIN.$plugin_path."/".$e_xxx.".php"))
{
$file_text = file_get_contents(e_PLUGIN.$plugin_path."/".$e_xxx.".php");
if ((substr($file_text, 0, 5) != '<'.'?php')
|| ( (substr($file_text, -2, 2) != '?'.'>') && (strrpos($file_text, '?'.'>') !== FALSE) )
)
if ((substr($file_text, 0, 5) != '<'.'?php') || ((substr($file_text, -2, 2) != '?'.'>') && (strrpos($file_text, '?'.'>') !== FALSE)))
{
return 1;
}
@@ -1879,7 +1852,6 @@ class e107plugin
return 2;
}
// Entry point to read plugin configuration data
function parse_plugin($plugName, $force = false)
{
@@ -1904,15 +1876,12 @@ class e107plugin
$this->parsed_plugin[$plugName] = $this->plug_vars;
}
return $ret;
}
// Called to parse the (deprecated) plugin.php file
function parse_plugin_php($plugName)
{
$mes = e107::getMessage();
$tp = e107::getParser();
@@ -1921,7 +1890,6 @@ class e107plugin
//$mes->add("Loading ".e_PLUGIN.$plugName.'/plugin.php', E_MESSAGE_DEBUG);
}
$ret = array();
// $ret['installRequired'] = ($eplug_conffile || is_array($eplug_table_names) || is_array($eplug_prefs) || is_array($eplug_sc) || is_array($eplug_bb) || $eplug_module || $eplug_userclass || $eplug_status || $eplug_latest);
@@ -1981,7 +1949,6 @@ class e107plugin
$ret['userClasses']['class'][0]['@attributes']['description'] = $eplug_userclass_description;
}
// Set this key so we know the vars came from a plugin.php file
$ret['plugin_php'] = true;
$this->plug_vars = $ret;
@@ -1989,8 +1956,6 @@ class e107plugin
return true;
}
// Called to parse the plugin.xml file if it exists
function parse_plugin_xml($plugName)
{
@@ -2002,7 +1967,6 @@ class e107plugin
// $xml->setOptArrayTags('extendedField,userclass,menuLink,commentID'); // always arrays for these tags.
// $xml->setOptStringTags('install,uninstall,upgrade');
$this->plug_vars = $xml->loadXMLfile(e_PLUGIN.$plugName.'/plugin.xml', 'advanced');
if ($this->plug_vars === FALSE)
{
@@ -2045,8 +2009,4 @@ class e107plugin
return TRUE;
}
}
?>