From 9587cdcffe117b2e39aa49f5eb14b22219ebd82e Mon Sep 17 00:00:00 2001 From: e107steved Date: Tue, 30 Dec 2008 19:01:17 +0000 Subject: [PATCH] Choices for selective delete when uninstalling plugins --- e107_admin/plugin.php | 101 +++++++++++++++++--- e107_handlers/plugin_class.php | 49 +++++++--- e107_languages/English/admin/lan_plugin.php | 17 ++-- 3 files changed, 135 insertions(+), 32 deletions(-) diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index d6069f8b1..3048c24be 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $ -| $Revision: 1.22 $ -| $Date: 2008-12-10 22:39:43 $ +| $Revision: 1.23 $ +| $Date: 2008-12-30 19:01:09 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -141,12 +141,11 @@ if (isset($_POST['upload'])) if ($action == 'uninstall') { if(!isset($_POST['uninstall_confirm'])) - { - show_uninstall_confirm(); + { // $id is already an integer + show_uninstall_confirm($id); exit; } - $id = intval($id); $plug = $plugin->getinfo($id); $text = ''; //Uninstall Plugin @@ -155,7 +154,12 @@ if ($action == 'uninstall') $_path = e_PLUGIN.$plug['plugin_path'].'/'; if(file_exists($_path.'plugin.xml')) { - $text .= $plugin->manage_plugin_xml($id, 'uninstall'); + $options = array( + 'del_tables' => varset($_POST['delete_tables'],FALSE), + 'del_userclasses' => varset($_POST['delete_userclasses'],FALSE), + 'del_extended' => varset($_POST['delete_xfields'],FALSE) + ); + $text .= $plugin->manage_plugin_xml($id, 'uninstall', $options); } else { @@ -623,12 +627,10 @@ $ns->tablerender(EPL_ADLAN_16, $text); require_once("footer.php"); exit; -function show_uninstall_confirm() +function show_uninstall_confirm($id) { - global $plugin, $tp, $id, $ns; - $id = intval($id); + global $plugin, $tp, $ns; $plug = $plugin->getinfo($id); -// $_path = e_PLUGIN.$plug['plugin_path']; if ($plug['plugin_installflag'] == true ) { @@ -636,6 +638,44 @@ function show_uninstall_confirm() { $plug_vars = $plugin->plug_vars; } + else + { + return FALSE; + } + } + else + { + return FALSE; + } + $userclasses = ''; + $eufields = ''; + if (isset($plug_vars['userclass'])) + { + if (isset($plug_vars['userclass']['@attributes'])) + { + $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; + unset($plug_vars['userclass']['@attributes']); + } + $spacer = ''; + foreach ($plug_vars['userclass'] as $uc) + { + $userclasses .= $spacer.$uc['@attributes']['name'].' - '.$uc['@attributes']['description']; + $spacer = '
'; + } + } + if (isset($plug_vars['extendedField'])) + { + if (isset($plug_vars['extendedField']['@attributes'])) + { + $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; + unset($plug_vars['extendedField']['@attributes']); + } + $spacer = ''; + foreach ($plug_vars['extendedField'] as $eu) + { + $eufields .= $spacer.'plugin_'.$plug_vars['folder'].'_'.$eu['@attributes']['name']; + $spacer = '
'; + } } if(is_writable(e_PLUGIN.$plug['plugin_path'])) @@ -658,6 +698,10 @@ function show_uninstall_confirm() $text = "
+ + + + @@ -666,7 +710,7 @@ function show_uninstall_confirm() - - - + "; + + if ($userclasses) + { + $text .= " + + + "; + } + + if ($eufields) + { + $text .= " + + + "; + } + + $text .=" diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 92274406c..b8f4a7579 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $ -| $Revision: 1.63 $ -| $Date: 2008-12-30 09:44:17 $ +| $Revision: 1.64 $ +| $Date: 2008-12-30 19:01:09 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -340,7 +340,6 @@ class e107plugin if ($action == 'remove') { $classID = $e107->user_class->ucGetClassIDFromName($class_name); - echo "Class ID: {$classID}, name: {$class_name}
"; if (($classID !== FALSE) && ($e107->user_class->deleteClassAndUsers($classID) === TRUE)) { @@ -722,7 +721,11 @@ class e107plugin // 'upgrade' // 'uninstall' // 'refresh' - adds things that are missing, but doesn't change any existing settings - function manage_plugin_xml($id, $function='') + // $options is an array of possible options - ATM used only for uninstall: + // 'del_userclasses' - to delete userclasses created + // 'del_tables' - to delete DB tables + // 'del_extended' - to delete extended fields + function manage_plugin_xml($id, $function='', $options = FALSE) { global $sql, $pref; @@ -877,8 +880,15 @@ class e107plugin case 'refresh' : // Leave things alone break; case 'uninstall' : - $txt .= "Removing table {$ct[1]}
"; - $this->manage_tables('remove', array($ct[1])); // Delete the table + if (varsettrue($options['del_tables'], FALSE)) + { + $txt .= "Removing table {$ct[1]}
"; + $this->manage_tables('remove', array($ct[1])); // Delete the table + } + else + { + $txt .= "Table {$ct[1]} left in place
"; + } break; } } @@ -1008,8 +1018,15 @@ class e107plugin //If uninstalling, remove all userclasses (active or inactive) case 'uninstall': - $txt .= 'Removing userclass '.$attrib['name'].'
'; - $this->manage_userclass('remove', $attrib['name'], $attrib['description']); + if (varsettrue($options['del_userclasses'], FALSE)) + { + $txt .= 'Removing userclass '.$attrib['name'].'
'; + $this->manage_userclass('remove', $attrib['name'], $attrib['description']); + } + else + { + $txt .= 'userclass '.$attrib['name'].' left in place
'; + } break; } } @@ -1049,11 +1066,17 @@ class e107plugin //If uninstalling, remove all extended fields (active or inactive) case 'uninstall': - $txt .= 'Removing extended field: '.$attrib['name'].' ... '; - $result = $this->manage_extended_field('remove', $attrib['name'], $source); - $txt .= ($result ? LAN_DELETED : LAN_DELETED_FAILED).'
'; - - break; + if (varsettrue($options['del_extended'], FALSE)) + { + $txt .= 'Removing extended field: '.$attrib['name'].' ... '; + $result = $this->manage_extended_field('remove', $attrib['name'], $source); + $txt .= ($result ? LAN_DELETED : LAN_DELETED_FAILED).'
'; + } + else + { + $txt .= 'Extended field: '.$attrib['name'].' left in place
'; + } + break; } } } diff --git a/e107_languages/English/admin/lan_plugin.php b/e107_languages/English/admin/lan_plugin.php index 185eb2c64..a33be0640 100644 --- a/e107_languages/English/admin/lan_plugin.php +++ b/e107_languages/English/admin/lan_plugin.php @@ -4,8 +4,8 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_plugin.php,v $ -| $Revision: 1.7 $ -| $Date: 2008-11-23 20:47:55 $ +| $Revision: 1.8 $ +| $Date: 2008-12-30 19:01:17 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -74,7 +74,7 @@ define("EPL_UPGRADE", "Upgrade"); define("EPL_ADLAN_50", "Comments successfully deleted"); define("EPL_ADLAN_53", "Directory not writable"); -define("EPL_ADLAN_54", "Please select the option for uninstalling the plugin:"); +define("EPL_ADLAN_54", "Please select the options for uninstalling the plugin:"); define("EPL_ADLAN_55", "Uninstall plugin"); define("EPL_ADLAN_57", "Delete plugin tables"); @@ -94,9 +94,14 @@ define ('EPL_ADLAN_74','Newer PHP version required: '); define ('EPL_ADLAN_75','Newer MySQL version required: '); define ('EPL_ADLAN_76','Error in plugin.xml'); define ('EPL_ADLAN_77','Cannot find plugin.xml'); -define ('EPL_ADLAN_78',''); -define ('EPL_ADLAN_79',''); -define ('EPL_ADLAN_80',''); +define ('EPL_ADLAN_78','Delete User Classes created by plugin:'); +define ('EPL_ADLAN_79','Only delete these if you have not used them for other purposes.'); +define ('EPL_ADLAN_80','Delete extended user fields created by plugin:'); +define ('EPL_ADLAN_81',''); +define ('EPL_ADLAN_82',''); +define ('EPL_ADLAN_83',''); +define ('EPL_ADLAN_84',''); +define ('EPL_ADLAN_85',''); define('LAN_UPGRADE_SUCCESSFUL', 'Upgrade Successful');
".EPL_ADLAN_54." ".$tp->toHtml($plug_vars['name'], "", "defs,emotes_off, no_make_clickable")."
".LAN_YES."
+ ".EPL_ADLAN_57."
".EPL_ADLAN_58."
@@ -675,8 +719,39 @@ function show_uninstall_confirm()
+ ".EPL_ADLAN_78."
".$userclasses."
".EPL_ADLAN_79."
+
+ +
+ ".EPL_ADLAN_80."
".$eufields."
".EPL_ADLAN_79."
+
+ +
".EPL_ADLAN_59."
".EPL_ADLAN_60."
{$del_text}