From 7e57c87d9caa2c1bb0980d0852b4d043f11f07f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Wed, 5 Apr 2017 13:36:06 +0200 Subject: [PATCH] Fixes #5466 Added a conflict system --- include/class_msgPool.inc | 22 ++++++--------------- include/class_pluglist.inc | 21 ++++++++++++++++++-- include/simpleplugin/class_simplePlugin.inc | 17 +++++++++++++--- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/include/class_msgPool.inc b/include/class_msgPool.inc index ce4d2ab05..1150be006 100644 --- a/include/class_msgPool.inc +++ b/include/class_msgPool.inc @@ -604,24 +604,14 @@ class msgPool { * * \param array $depends Contains all the settings disabled */ - public static function featuresDisabled($name, $depends = "") + public static function featuresDisabled($name, array $depends = array(), array $conflicts = array()) { - if (($depends == "") || (is_array($depends) && count($depends) == 0)) { - return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), $name); + if (empty($depends) && empty($conflicts)) { + return sprintf(_('This account has %s settings disabled. You can enable them by clicking below.'), $name); + } elseif (!empty($depends)) { + return sprintf(_('This account has %s settings disabled. To enable them, you\'ll need to add the %s settings first!'), $name, implode(' / ', $depends)); } else { - if (count($depends) == 1) { - if (is_array($depends)) { - $depends = $depends[0]; - } - return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $depends); - } else { - $deps = ""; - foreach ($depends as $dep) { - $deps .= "$dep / "; - } - $deps = preg_replace("/ \/ $/", "", $deps); - return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $deps); - } + return sprintf(_('This account has %s settings disabled. To enable them, you\'ll need to disable the %s settings first!'), $name, implode(' / ', $conflicts)); } } diff --git a/include/class_pluglist.inc b/include/class_pluglist.inc index 8cc9dcc5c..ff2e569bc 100644 --- a/include/class_pluglist.inc +++ b/include/class_pluglist.inc @@ -64,8 +64,9 @@ class pluglist { $classes = get_declared_classes(); $index = 0; - $depends_infos = array(); - $foreign_refs = array(); + $depends_infos = array(); + $conflicts_infos = array(); + $foreign_refs = array(); foreach ($classes as $cname) { $cmethods = get_class_methods($cname); if (in_array_ics('plInfo', $cmethods)) { @@ -86,6 +87,9 @@ class pluglist { if (isset($infos['plDepends'])) { $depends_infos[] = $cname; } + if (isset($infos['plConflicts'])) { + $conflicts_infos[] = $cname; + } if (isset($infos['plForeignKeys'])) { foreach ($infos['plForeignKeys'] as $ofield => &$pfks) { if (!is_array($pfks)) { @@ -153,6 +157,19 @@ class pluglist { } } } + foreach ($conflicts_infos as $cname) { + foreach ($this->info[$cname]['plConflicts'] as $conflict) { + if (isset($this->info[$conflict])) { + if (isset($this->info[$conflict]['plConflicts'])) { + if (!in_array($cname, $this->info[$conflict]['plConflicts'])) { + $this->info[$conflict]['plConflicts'][] = $cname; + } + } else { + $this->info[$conflict]['plConflicts'] = array($cname); + } + } + } + } foreach ($foreign_refs as $cname => $refs) { $this->info[$cname]['plForeignRefs'] = $refs; } diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 2653908ce..7349af7d1 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -683,8 +683,9 @@ class simplePlugin /* Show tab dialog headers */ $plInfo = pluglist::pluginInfos(get_class($this)); if ($this->parent !== NULL) { - $disabled = $this->acl_skip_write(); - $depends = array(); + $disabled = $this->acl_skip_write(); + $depends = array(); + $conflicts = array(); if ($this->is_account) { if (isset($plInfo['plDepending'])) { foreach ($plInfo['plDepending'] as $plugin) { @@ -714,9 +715,19 @@ class simplePlugin } } } + if (isset($plInfo['plConflicts'])) { + foreach ($plInfo['plConflicts'] as $plugin) { + if (isset($this->parent->by_object[$plugin]) && + $this->parent->by_object[$plugin]->is_account) { + $disabled = TRUE; + $conflictPlInfos = pluglist::pluginInfos($plugin); + $conflicts[] = $conflictPlInfos['plShortName']; + } + } + } $this->header = $this->show_header( msgPool::addFeaturesButton($plInfo['plShortName']), - msgPool::featuresDisabled($plInfo['plShortName'], $depends), + msgPool::featuresDisabled($plInfo['plShortName'], $depends, $conflicts), $this->is_account, $disabled, get_class($this).'_modify_state' -- GitLab