From e6101f17a75123765f42a763991768f21447cba9 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 18 Sep 2016 09:58:32 +1000 Subject: [PATCH] CRM-19380 allow for multiple from email addresses but only one per domain --- CRM/Admin/Form/Options.php | 4 +++- CRM/Core/OptionValue.php | 7 ++++++- CRM/Utils/Rule.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 5a595e47d4..67718e52f3 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -177,10 +177,12 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { 'addressee', )) && !$isReserved ) { + $domainSepcificOptionGroups = array('from_email_address'); + $domainSpecific = in_array($this->_gName, $domainSepcificOptionGroups) ? TRUE : FALSE; $this->addRule('label', ts('This Label already exists in the database for this option group. Please select a different Value.'), 'optionExists', - array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label') + array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $domainSpecific) ); } diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index df4a386029..be150369f8 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -258,15 +258,20 @@ class CRM_Core_OptionValue { * @param int $optionGroupID * @param string $fieldName * The name of the field in the DAO. + * @param bool $domainSpecific * * @return bool * true if object exists */ - public static function optionExists($value, $daoName, $daoID, $optionGroupID, $fieldName = 'name') { + public static function optionExists($value, $daoName, $daoID, $optionGroupID, $fieldName = 'name', $domainSpecific) { $object = new $daoName(); $object->$fieldName = $value; $object->option_group_id = $optionGroupID; + if ($domainSpecific) { + $object->domain_id = CRM_Core_Config::domainID(); + } + if ($object->find(TRUE)) { return ($daoID && $object->id == $daoID) ? TRUE : FALSE; } diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index 43b0e3d580..87caefd1a1 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -715,7 +715,7 @@ class CRM_Utils_Rule { * @return bool */ public static function optionExists($value, $options) { - return CRM_Core_OptionValue::optionExists($value, $options[0], $options[1], $options[2], CRM_Utils_Array::value(3, $options, 'name')); + return CRM_Core_OptionValue::optionExists($value, $options[0], $options[1], $options[2], CRM_Utils_Array::value(3, $options, 'name'), CRM_Utils_Array::value(4, $options, FALSE)); } /** -- 2.25.1