1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-18 05:09:05 +01:00

Merge pull request #1735 from lonalore/master

Plugin installation dependency fixes.
This commit is contained in:
Cameron 2016-06-29 14:42:38 -07:00 committed by GitHub
commit d601dd5243
5 changed files with 187 additions and 63 deletions

View File

@ -734,6 +734,17 @@ class pluginManager{
}
$plug = $plugin->getinfo($this->id);
// Check if plugin is being used by another plugin before uninstalling it.
if(isset($plug['plugin_path']))
{
if ($plugin->isUsedByAnotherPlugin($plug['plugin_path']))
{
$this->action = 'installed'; // Render plugin list.
return;
}
}
$text = '';
//Uninstall Plugin
if ($plug['plugin_installflag'] == TRUE )

View File

@ -1707,13 +1707,19 @@ class e107
* - 'load': Loads a library.
* @param string $library
* The name of the library to detect/load.
* @param string $variant
* (Optional for 'load') The name of the variant to load. Note that only one variant of a library can be loaded
* within a single request. The variant that has been passed first is used; different variant names in subsequent
* calls are ignored.
*
* @return array|boolean
* - In case of 'detect': An associative array containing registered information for the library specified by
* $name, or FALSE if the library $name is not registered.
* - In case of 'load': An associative array of the library information.
* - In case of 'info': An associative array containing registered information for all libraries, the registered
* information for the library specified by $name, or FALSE if the library $name is not registered.
*/
public static function library($action = '', $library = null)
public static function library($action = '', $library = null, $variant = null)
{
$libraryHandler = e107::getLibrary();
@ -1724,7 +1730,7 @@ class e107
break;
case 'load':
return $libraryHandler->load($library);
return $libraryHandler->load($library, $variant);
break;
case 'info':

View File

@ -1489,7 +1489,7 @@ class e107plugin
$this->XmlLanguageFiles($function, varset($plug_vars['languageFiles']), 'pre'); // First of all, see if there's a language file specific to install
// Next most important, if installing or upgrading, check that any dependencies are met
if ($canContinue && ($function != 'uninstall') && isset($plug_vars['dependencies']))
if($canContinue && ($function != 'uninstall') && isset($plug_vars['dependencies']))
{
$canContinue = $this->XmlDependencies($plug_vars['dependencies']);
}
@ -1793,77 +1793,176 @@ class e107plugin
}
/**
* Process XML Tag <dependencies> (deprecated 'depend' which is a brand of adult diapers)
* @param array $tag
* @return boolean
*/
function XmlDependencies($tag)
{
$canContinue = TRUE;
$mes = e107::getMessage();
$error = array();
foreach ($tag as $dt => $dv)
/**
* Check if plugin is being used by another plugin before uninstalling it.
*
* @param array $plugin
* Plugin name.
*
* @return boolean
* TRUE if plugin is used, otherwise FALSE.
*/
function isUsedByAnotherPlugin($plugin)
{
$db = e107::getDb();
$tp = e107::getParser();
$mes = e107::getMessage();
$xml = e107::getXml();
$pluginIsUsed = false;
$enPlugs = array();
$usedBy = array();
// Get list of enabled plugins.
$db->select("plugin", "*", "plugin_id !='' order by plugin_path ASC");
while($row = $db->fetch())
{
if (isset($dv['@attributes']) && isset($dv['@attributes']['name']))
if($row['plugin_installflag'] == 1)
{
// echo "Check {$dt} dependency: {$dv['@attributes']['name']} version {$dv['@attributes']['min_version']}<br />";
switch ($dt)
$enPlugs[] = $row['plugin_path'];
}
}
foreach($enPlugs as $enPlug)
{
if(!file_exists(e_PLUGIN . $enPlug . '/plugin.xml'))
{
continue;
}
$plugInfo = $xml->loadXMLfile(e_PLUGIN . $enPlug . '/plugin.xml', 'advanced');
if($plugInfo === false)
{
continue;
}
if (!isset($plugInfo['dependencies']))
{
continue;
}
// FIXME too many nested foreach, need refactoring.
foreach($plugInfo['dependencies'] as $dt => $da)
{
foreach($da as $dv)
{
case 'plugin':
if (!isset($pref['plug_installed'][$dv['@attributes']['name']]))
{ // Plugin not installed
$canContinue = FALSE;
$error[] = EPL_ADLAN_70.$dv['@attributes']['name'];
}
elseif (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], $pref['plug_installed'][$dv['@attributes']['name']], '<=') === FALSE))
if(isset($dv['@attributes']) && isset($dv['@attributes']['name']))
{
switch($dt)
{
$error[] = EPL_ADLAN_71.$dv['@attributes']['name'].EPL_ADLAN_72.$dv['@attributes']['min_version'];
$canContinue = FALSE;
case 'plugin':
if ($dv['@attributes']['name'] == $plugin)
{
$usedBy[] = $enPlug;
}
break;
}
break;
case 'extension':
if (!extension_loaded($dv['@attributes']['name']))
{
$canContinue = FALSE;
$error[] = EPL_ADLAN_73.$dv['@attributes']['name'];
}
elseif (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion($dv['@attributes']['name']), '<=') === FALSE))
{
$error[] = EPL_ADLAN_71.$dv['@attributes']['name'].EPL_ADLAN_72.$dv['@attributes']['min_version'];
$canContinue = FALSE;
}
break;
case 'php': // all should be lowercase
if (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion(), '<=') === FALSE))
{
$error[] = EPL_ADLAN_74.$dv['@attributes']['min_version'];
$canContinue = FALSE;
}
break;
case 'mysql': // all should be lowercase
if (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], e107::getDb()->mySqlServerInfo(), '<=') === FALSE))
{
$error[] = EPL_ADLAN_75.$dv['@attributes']['min_version'];
$canContinue = FALSE;
}
break;
default:
echo "Unknown dependency: {$dt}<br />";
}
}
}
}
if (count($error))
if(count($usedBy))
{
$text = '<b>'.LAN_INSTALL_FAIL.'</b><br />'.implode('<br />', $error);
$pluginIsUsed = true;
$text = '<b>' . LAN_UNINSTALL_FAIL . '</b><br />';
$text .= $tp->lanVars(LAN_PLUGIN_IS_USED, array('x' => $plugin), true) . ' ';
$text .= implode(', ', $usedBy);
$mes->addError($text);
}
return $pluginIsUsed;
}
/**
* Process XML Tag <dependencies> (deprecated 'depend' which is a brand of adult diapers)
*
* @param array $tags
* Tags (in <dependencies> tag) from XML file.
*
* @return boolean
*/
function XmlDependencies($tags)
{
$db = e107::getDb();
$mes = e107::getMessage();
$canContinue = true;
$enabledPlugins = array();
$error = array();
// Get list of enabled plugins.
$db->select("plugin", "*", "plugin_id !='' order by plugin_path ASC");
while($row = $db->fetch())
{
if($row['plugin_installflag'] == 1)
{
$enabledPlugins[$row['plugin_path']] = $row['plugin_version'];
}
}
// FIXME too many nested foreach, need refactoring.
foreach($tags as $dt => $da)
{
foreach($da as $dv)
{
if(isset($dv['@attributes']) && isset($dv['@attributes']['name']))
{
switch($dt)
{
case 'plugin':
if(!isset($enabledPlugins[$dv['@attributes']['name']]))
{ // Plugin not installed
$canContinue = false;
$error[] = EPL_ADLAN_70 . $dv['@attributes']['name'];
}
elseif(isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], $enabledPlugins[$dv['@attributes']['name']], '<=') === false))
{
$error[] = EPL_ADLAN_71 . $dv['@attributes']['name'] . EPL_ADLAN_72 . $dv['@attributes']['min_version'];
$canContinue = false;
}
break;
case 'extension':
if(!extension_loaded($dv['@attributes']['name']))
{
$canContinue = false;
$error[] = EPL_ADLAN_73 . $dv['@attributes']['name'];
}
elseif(isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion($dv['@attributes']['name']), '<=') === false))
{
$error[] = EPL_ADLAN_71 . $dv['@attributes']['name'] . EPL_ADLAN_72 . $dv['@attributes']['min_version'];
$canContinue = false;
}
break;
case 'php': // all should be lowercase
if(isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion(), '<=') === false))
{
$error[] = EPL_ADLAN_74 . $dv['@attributes']['min_version'];
$canContinue = false;
}
break;
case 'mysql': // all should be lowercase
if(isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], $db->mySqlServerInfo(), '<=') === false)
)
{
$error[] = EPL_ADLAN_75 . $dv['@attributes']['min_version'];
$canContinue = false;
}
break;
default:
// TODO lan
echo "Unknown dependency: {$dt}<br />";
}
}
}
}
if(count($error))
{
$text = '<b>' . LAN_INSTALL_FAIL . '</b><br />' . implode('<br />', $error);
$mes->addError($text);
}

View File

@ -272,5 +272,7 @@ define ('EPL_ADLAN_229',"Refresh");
define('LAN_UPGRADE_SUCCESSFUL', "Upgrade successful");
define('LAN_INSTALL_SUCCESSFUL', "Installation successful");
define('LAN_INSTALL_FAIL', "Installation failed!");
define('LAN_UNINSTALL_FAIL', "Unable to uninstall!");
define('LAN_PLUGIN_IS_USED', "[x] plugin is used by:");
?>

View File

@ -531,6 +531,8 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
// Command to provide the jQuery css() function.
case 'css':
$(command.target).css(command.arguments);
// Attach all registered behaviors to the new content.
e107.attachBehaviors();
break;
// Command to set the settings that will be used for other commands in this response.
@ -544,12 +546,16 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}};
// Command to attach data using jQuery's data API.
case 'data':
$(command.target).data(command.name, command.value);
// Attach all registered behaviors to the new content.
e107.attachBehaviors();
break;
// Command to apply a jQuery method.
case 'invoke':
var $element = $(command.target);
$element[command.method].apply($element, command.arguments);
// Attach all registered behaviors to the new content.
e107.attachBehaviors();
break;
}
});