From 246500181dbfcdc72a528ad4893e51f295fc3124 Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Mon, 15 Feb 2021 21:36:11 +0530 Subject: [PATCH] core#2309: Validate weight and weight threshold --- CRM/Contact/Form/DedupeRules.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CRM/Contact/Form/DedupeRules.php b/CRM/Contact/Form/DedupeRules.php index 7e4a850c97..c99ea8195e 100644 --- a/CRM/Contact/Form/DedupeRules.php +++ b/CRM/Contact/Form/DedupeRules.php @@ -136,11 +136,15 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { public static function formRule($fields, $files, $self) { $errors = []; $fieldSelected = FALSE; + $actualThreshold = 0; for ($count = 0; $count < self::RULES_COUNT; $count++) { if (!empty($fields["where_$count"]) || (isset($self->_defaults['is_reserved']) && !empty($self->_defaults["where_$count"]))) { $fieldSelected = TRUE; break; } + if (!empty($self->_defaults["weight_$count"])) { + $actualThreshold += $self->_defaults["weight_$count"]; + } } if (empty($fields['threshold'])) { // CRM-20607 - Don't validate the threshold of hard-coded rules @@ -149,6 +153,11 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { $errors['threshold'] = ts('Threshold weight cannot be empty or zero.'); } } + else { + if ($actualThreshold < $fields['threshold']) { + $errors['threshold'] = ts('Total weight must be greater than or equal to the Weight Threshold.'); + } + } if (!$fieldSelected) { $errors['_qf_default'] = ts('Please select at least one field.'); -- 2.25.1