Skip to content

Commit

Permalink
Fixed E_NOTICE in plugin install/uninstall process
Browse files Browse the repository at this point in the history
- FIX: e107::coreLan() now loads the lan_admin.php file if the $admin argument is true
- FIX: Variable scope of $eplug_folder in e107plugin::uninstall()
- FIX: isset() check order in pluginsTest::makePluginReport()
- FIX: class2.php: Missing ADMINPERMS constant in CLI mode
  • Loading branch information
Deltik committed Jan 17, 2020
1 parent bfad3f7 commit 62a547a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 121 deletions.
7 changes: 1 addition & 6 deletions class2.php
Original file line number Diff line number Diff line change
Expand Up @@ -1417,12 +1417,6 @@ function systemTimeZoneIsValid($zone = '')
// ----------------------------------------------------------------------------
$sql->db_Mark_Time('Find/Load Theme');

if(e_ADMIN_AREA) // Load admin phrases ASAP
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}


if(!defined('THEME'))
{

Expand Down Expand Up @@ -2032,6 +2026,7 @@ function init_session()
define('USERNAME', 'e107-cli');
define('USERTHEME', false);
define('ADMIN', true);
define('ADMINPERMS', false);
define('GUEST', false);
define('USERCLASS', '');
define('USEREMAIL', '');
Expand Down
5 changes: 5 additions & 0 deletions e107_handlers/e107_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,11 @@ public static function includeLan($path, $force = false)
*/
public static function coreLan($fname, $admin = false)
{
if ($admin)
{
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php');
}

$cstring = 'corelan/'.e_LANGUAGE.'_'.$fname.($admin ? '_admin' : '_front');
if(self::getRegistry($cstring)) return;

Expand Down
224 changes: 111 additions & 113 deletions e107_handlers/plugin_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4311,7 +4311,6 @@ function install($id, $options = array())
}



public function uninstall($id, $options = array())
{
$pref = e107::getPref();
Expand All @@ -4322,12 +4321,12 @@ public function uninstall($id, $options = array())
$sql = e107::getDb();
$plug = e107plugin::getPluginRecord($id);

$this->log("Uninstalling :".$plug['plugin_path']." with options: ".print_r($options, true));
$this->log("Uninstalling :" . $plug['plugin_path'] . " with options: " . print_r($options, true));

$this->log("e107plugin::getPluginRecord() returned: ".print_r($plug, true));
$this->log("e107plugin::getPluginRecord() returned: " . print_r($plug, true));

// Check if plugin is being used by another plugin before uninstalling it.
if(isset($plug['plugin_path']))
if (isset($plug['plugin_path']))
{
if ($this->isUsedByAnotherPlugin($plug['plugin_path']))
{
Expand All @@ -4336,146 +4335,145 @@ public function uninstall($id, $options = array())
}
}

$text = '';
//Uninstall Plugin
if ($plug['plugin_installflag'] == true )
{
$this->log("plugin_installflag = true, proceeding to uninstall");
$text = '';
//Uninstall Plugin
$eplug_folder = $plug['plugin_path'];
if ($plug['plugin_installflag'] == true)
{
$this->log("plugin_installflag = true, proceeding to uninstall");

$eplug_folder = $plug['plugin_path'];
$_path = e_PLUGIN.$plug['plugin_path'].'/';
$_path = e_PLUGIN . $plug['plugin_path'] . '/';

if(file_exists($_path.'plugin.xml'))
if (file_exists($_path . 'plugin.xml'))
{
unset($_POST['uninstall_confirm']);
$this->install_plugin_xml($plug, 'uninstall', $options); //$_POST must be used.
}
else
{ // Deprecated - plugin uses plugin.php
$eplug_table_names = null;
$eplug_prefs = null;
$eplug_comment_ids = null;
$eplug_array_pref = null;
$eplug_menu_name = null;
$eplug_link = null;
$eplug_link_url = null;
$eplug_link_name = null;
$eplug_userclass = null;
$eplug_version = null;

include(e_PLUGIN . $plug['plugin_path'] . '/plugin.php');

$func = $eplug_folder . '_uninstall';
if (function_exists($func))
{
unset($_POST['uninstall_confirm']);
$this->install_plugin_xml($plug, 'uninstall', $options); //$_POST must be used.
$text .= call_user_func($func);
}
else
{ // Deprecated - plugin uses plugin.php
$eplug_table_names = null;
$eplug_prefs = null;
$eplug_comment_ids= null;
$eplug_array_pref= null;
$eplug_menu_name = null;
$eplug_link = null;
$eplug_link_url = null;
$eplug_link_name = null;
$eplug_userclass = null;
$eplug_version = null;

include(e_PLUGIN.$plug['plugin_path'].'/plugin.php');

$func = $eplug_folder.'_uninstall';
if (function_exists($func))
{
$text .= call_user_func($func);
}

if(!empty($options['delete_tables']))
{
if (!empty($options['delete_tables']))
{

if (is_array($eplug_table_names))
if (is_array($eplug_table_names))
{
$result = $this->manage_tables('remove', $eplug_table_names);
if ($result !== TRUE)
{
$result = $this->manage_tables('remove', $eplug_table_names);
if ($result !== TRUE)
{
$text .= EPL_ADLAN_27.' <b>'.MPREFIX.$result.'</b> - '.EPL_ADLAN_30.'<br />';
$this->log("Unable to delete table."); // No LANS
}
else
{
$text .= EPL_ADLAN_28."<br />";
$this->log("Deleting tables."); // NO LANS
}
$text .= EPL_ADLAN_27 . ' <b>' . MPREFIX . $result . '</b> - ' . EPL_ADLAN_30 . '<br />';
$this->log("Unable to delete table."); // No LANS
}
}
else
{
$text .= EPL_ADLAN_49."<br />";
$this->log("Tables left intact by request."); // No LANS
}

if (is_array($eplug_prefs))
{
$this->manage_prefs('remove', $eplug_prefs);
$text .= EPL_ADLAN_29."<br />";
}

if (is_array($eplug_comment_ids))
{
$text .= ($this->manage_comments('remove', $eplug_comment_ids)) ? EPL_ADLAN_50."<br />" : "";
}

if (is_array($eplug_array_pref))
{
foreach($eplug_array_pref as $key => $val)
else
{
$this->manage_plugin_prefs('remove', $key, $eplug_folder, $val);
$text .= EPL_ADLAN_28 . "<br />";
$this->log("Deleting tables."); // NO LANS
}
}
/*
if ($eplug_menu_name)
{
$sql->delete('menus', "menu_name='{$eplug_menu_name}' ");
}*/
$folderFiles = scandir(e_PLUGIN.$plug['plugin_path']);
$this->XmlMenus($eplug_folder,'uninstall',$folderFiles);

if ($eplug_link)
{
$this->manage_link('remove', $eplug_link_url, $eplug_link_name);
}

if ($eplug_userclass)
{
$this->manage_userclass('remove', $eplug_userclass);
}
}
else
{
$text .= EPL_ADLAN_49 . "<br />";
$this->log("Tables left intact by request."); // No LANS
}

$sql->update('plugin', "plugin_installflag=0, plugin_version='{$eplug_version}' WHERE plugin_path='{$eplug_folder}' ");
$this->manage_search('remove', $eplug_folder);
if (is_array($eplug_prefs))
{
$this->manage_prefs('remove', $eplug_prefs);
$text .= EPL_ADLAN_29 . "<br />";
}

$this->manage_notify('remove', $eplug_folder);
if (is_array($eplug_comment_ids))
{
$text .= ($this->manage_comments('remove', $eplug_comment_ids)) ? EPL_ADLAN_50 . "<br />" : "";
}

// it's done inside install_plugin_xml(), required only here
if (isset($pref['plug_installed'][$plug['plugin_path']]))
if (is_array($eplug_array_pref))
{
foreach ($eplug_array_pref as $key => $val)
{
unset($pref['plug_installed'][$plug['plugin_path']]);
$this->manage_plugin_prefs('remove', $key, $eplug_folder, $val);
}
e107::getConfig('core')->setPref($pref);
$this->rebuildUrlConfig();
e107::getConfig('core')->save(false,true,false);
}
/*
if ($eplug_menu_name)
{
$sql->delete('menus', "menu_name='{$eplug_menu_name}' ");
}*/
$folderFiles = scandir(e_PLUGIN . $plug['plugin_path']);
$this->XmlMenus($eplug_folder, 'uninstall', $folderFiles);

if ($eplug_link)
{
$this->manage_link('remove', $eplug_link_url, $eplug_link_name);
}

$logInfo = deftrue($plug['plugin_name'],$plug['plugin_name']). " v".$plug['plugin_version']." ({e_PLUGIN}".$plug['plugin_path'].")";
e107::getLog()->add('PLUGMAN_03', $logInfo, E_LOG_INFORMATIVE, '');
}
else
{
$this->log("plugin_installflag = false, uninstall skipped.");
}
if ($eplug_userclass)
{
$this->manage_userclass('remove', $eplug_userclass);
}

if(!empty($options['delete_files']) && ($plug['plugin_installflag'] == true))
{
if(!empty($eplug_folder))
$sql->update('plugin', "plugin_installflag=0, plugin_version='{$eplug_version}' WHERE plugin_path='{$eplug_folder}' ");
$this->manage_search('remove', $eplug_folder);

$this->manage_notify('remove', $eplug_folder);

// it's done inside install_plugin_xml(), required only here
if (isset($pref['plug_installed'][$plug['plugin_path']]))
{
$result = e107::getFile()->rmtree(e_PLUGIN.$eplug_folder);
e107::getDb()->delete('plugin', "plugin_path='".$eplug_folder."'");
$text .= ($result ? '<br />'.EPL_ADLAN_86.e_PLUGIN.$eplug_folder : '<br />'.EPL_ADLAN_87.'<br />'.EPL_ADLAN_31.' <b>'.e_PLUGIN.$eplug_folder.'</b> '.EPL_ADLAN_32);
unset($pref['plug_installed'][$plug['plugin_path']]);
}
e107::getConfig('core')->setPref($pref);
$this->rebuildUrlConfig();
e107::getConfig('core')->save(false, true, false);
}
else

$logInfo = deftrue($plug['plugin_name'], $plug['plugin_name']) . " v" . $plug['plugin_version'] . " ({e_PLUGIN}" . $plug['plugin_path'] . ")";
e107::getLog()->add('PLUGMAN_03', $logInfo, E_LOG_INFORMATIVE, '');
}
else
{
$this->log("plugin_installflag = false, uninstall skipped.");
}

if (!empty($options['delete_files']) && ($plug['plugin_installflag'] == true))
{
if (!empty($eplug_folder))
{
$text .= '<br />'.EPL_ADLAN_31.' <b>'.e_PLUGIN.$eplug_folder.'</b> '.EPL_ADLAN_32;
$result = e107::getFile()->rmtree(e_PLUGIN . $eplug_folder);
e107::getDb()->delete('plugin', "plugin_path='" . $eplug_folder . "'");
$text .= ($result ? '<br />' . EPL_ADLAN_86 . e_PLUGIN . $eplug_folder : '<br />' . EPL_ADLAN_87 . '<br />' . EPL_ADLAN_31 . ' <b>' . e_PLUGIN . $eplug_folder . '</b> ' . EPL_ADLAN_32);
}
}
else
{
$text .= '<br />' . EPL_ADLAN_31 . ' <b>' . e_PLUGIN . $eplug_folder . '</b> ' . EPL_ADLAN_32;
}

e107::getPlug()->clearCache()->buildAddonPrefLists();

// $this->save_addon_prefs('update');
// $this->save_addon_prefs('update');

$this->log("Uninstall completed");



return $text;
}

Expand Down
4 changes: 2 additions & 2 deletions e107_tests/tests/unit/pluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ private function makePluginReport($pluginDir)
$debug_text .= "---- Pref: plug_installed (version)\n\n";
$pref = e107::getConfig('core',true,true)->get('plug_installed');

$debug_text .= print_r($pref[$pluginDir],true);

$installedPref = isset($pref[$pluginDir]) ? $pref[$pluginDir] : false;

$debug_text .= print_r($installedPref,true);

$debug_text .= "\n\n---- Plugin Prefs: \n\n";
$pluginPref = e107::pref($pluginDir);
$debug_text .= print_r($pluginPref,true);
Expand Down

0 comments on commit 62a547a

Please sign in to comment.