Update to use existing objectExists rule.
authorDarrick Servis <darrick@davismedia.org>
Sun, 3 Jul 2016 00:46:38 +0000 (17:46 -0700)
committerDarrick Servis <darrick@davismedia.org>
Sun, 3 Jul 2016 00:46:38 +0000 (17:46 -0700)
CRM/Admin/Form/PaymentProcessor.php
CRM/Core/DAO.php
CRM/Utils/Rule.php

index 191a2519ada79f85c7eed717b09729e9bbffc309..939ee2a6254fb98bfce29d48e3839edd21ea330c 100644 (file)
@@ -176,10 +176,11 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
       $attributes['name'], TRUE
     );
 
-    $this->registerRule('paymentProcessorNameExists', 'callback', 'paymentProcessorNameExists', 'CRM_Admin_Form_PaymentProcessor');
-    $this->addRule('name', ts('Name already exists in Database.'), 'paymentProcessorNameExists', array(
+    $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
         'CRM_Financial_DAO_PaymentProcessor',
         $this->_id,
+        'name',
+        CRM_Core_Config::domainID(),
       ));
 
     $this->add('text', 'description', ts('Description'),
@@ -401,34 +402,4 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
     civicrm_api3('PaymentProcessor', 'create', $params);
   }
 
-  /**
-   * Check if there is a record with the same name in the db.
-   *
-   * @param string $value
-   *   The value of the field we are checking.
-   * @param array $options
-   *   The daoName and fieldName (optional ).
-   *
-   * @return bool
-   *   true if object exists
-   */
-  public static function paymentProcessorNameExists($value, $options) {
-    $fieldName = 'name';
-    $daoName = CRM_Utils_Array::value(0, $options);
-    $daoID = CRM_Utils_Array::value(1, $options);
-    $domain_id = CRM_Core_Config::domainID();
-    $object = new $daoName();
-    $object->$fieldName = $value;
-    $object->domain_id = $domain_id;
-
-    $config = CRM_Core_Config::singleton();
-
-    if ($object->find(TRUE)) {
-      return ($daoID && $object->id == $daoID) ? TRUE : FALSE;
-    }
-    else {
-      return TRUE;
-    }
-  }
-
 }
index cb02a95c57335ff71943064581fa23d3b27b6b9a..b4aa48427c3d630f182278d12fd063bbe782ff89 100644 (file)
@@ -723,14 +723,18 @@ class CRM_Core_DAO extends DB_DataObject {
    * @param string $fieldName
    *   The name of the field in the DAO.
    *
+   * @param string $domainID
+   *   The id of the domain.  Object exists only for the given domain.
+   *
    * @return bool
    *   true if object exists
    */
-  public static function objectExists($value, $daoName, $daoID, $fieldName = 'name') {
+  public static function objectExists($value, $daoName, $daoID, $fieldName = 'name', $domainID = NULL) {
     $object = new $daoName();
     $object->$fieldName = $value;
-
-    $config = CRM_Core_Config::singleton();
+    if ($domainID) {
+      $object->domain_id = $domainID;
+    }
 
     if ($object->find(TRUE)) {
       return ($daoID && $object->id == $daoID) ? TRUE : FALSE;
index 3251d26bbefb4991a76b4cbe15b501e21a1a38f5..650f5e6883d9d246db389e074c1e18a4d20917ed 100644 (file)
@@ -695,7 +695,7 @@ class CRM_Utils_Rule {
    * @param string $value
    *   The value of the field we are checking.
    * @param array $options
-   *   The daoName and fieldName (optional ).
+   *   The daoName, fieldName (optional) and DomainID (optional).
    *
    * @return bool
    *   true if object exists
@@ -706,7 +706,7 @@ class CRM_Utils_Rule {
       $name = $options[2];
     }
 
-    return CRM_Core_DAO::objectExists($value, CRM_Utils_Array::value(0, $options), CRM_Utils_Array::value(1, $options), CRM_Utils_Array::value(2, $options, $name));
+    return CRM_Core_DAO::objectExists($value, CRM_Utils_Array::value(0, $options), CRM_Utils_Array::value(1, $options), CRM_Utils_Array::value(2, $options, $name), CRM_Utils_Array::value(3, $options));
   }
 
   /**