CRM-20907 Ensure that contact_type is valid in deduperules
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 19 Sep 2017 01:16:16 +0000 (11:16 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 19 Sep 2017 01:16:16 +0000 (11:16 +1000)
CRM/Contact/Form/DedupeRules.php

index ebfde46b914fac458a87b0cfbe621f1e3eb06af9..912cd680634ed63126009c05f736de5acb2abdde 100644 (file)
@@ -58,7 +58,14 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form {
     }
     $this->_options = CRM_Core_SelectValues::getDedupeRuleTypes();
     $this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
-    $this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0);
+    $contactTypes = civicrm_api3('Contact', 'getOptions', array('field' => "contact_type"));
+    $contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0);
+    if (in_array($contactType, $contactTypes['values'])) {
+      $this->_contactType = $contactTypes['values'][$contactType];
+    }
+    else {
+      throw new CRM_Core_Exception('Contact Type is Not valid');
+    }
     if ($this->_rgid) {
       $rgDao = new CRM_Dedupe_DAO_RuleGroup();
       $rgDao->id = $this->_rgid;