move contact id validation to wrapper
authorJitendra Purohit <jitendra@fuzion.co.nz>
Wed, 17 May 2017 10:39:35 +0000 (16:09 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Wed, 17 May 2017 10:39:35 +0000 (16:09 +0530)
api/v3/Activity.php
api/v3/utils.php

index 66d1544b7d5f297e8a4767523b4fc47b18e81c29..26f45d615fd66b4fae3a8c005b2502f26604e701 100644 (file)
@@ -539,43 +539,6 @@ function civicrm_api3_activity_delete($params) {
  *   array with errors
  */
 function _civicrm_api3_activity_check_params(&$params) {
-
-  $contactIDFields = array_intersect_key($params,
-    array(
-      'source_contact_id' => 1,
-      'assignee_contact_id' => 1,
-      'target_contact_id' => 1,
-    )
-  );
-
-  // this should be handled by wrapper layer & probably the api would already manage it
-  //correctly by doing post validation - ie. a failure should result in a roll-back = an error
-  // needs testing
-  if (!empty($contactIDFields)) {
-    $contactIds = array();
-    foreach ($contactIDFields as $fieldname => $contactfield) {
-      if (empty($contactfield)) {
-        continue;
-      }
-      if (is_array($contactfield)) {
-        foreach ($contactfield as $contactkey => $contactvalue) {
-          $contactIds[$contactvalue] = $contactvalue;
-        }
-      }
-      else {
-        $contactIds[$contactfield] = $contactfield;
-      }
-    }
-
-    $sql = '
-SELECT  count(*)
-  FROM  civicrm_contact
- WHERE  id IN (' . implode(', ', $contactIds) . ' )';
-    if (!empty($contactIds) && count($contactIds) != CRM_Core_DAO::singleValueQuery($sql)) {
-      throw new API_Exception('Invalid Contact Id');
-    }
-  }
-
   $activityIds = array(
     'activity' => CRM_Utils_Array::value('id', $params),
     'parent' => CRM_Utils_Array::value('parent_id', $params),
index dd55453e45828307ab90233a580060099fe9feab..7f0c00cc3b87fd05ea8452f6bc6f4835a11868f6 100644 (file)
@@ -1641,7 +1641,9 @@ function _civicrm_api3_validate_foreign_keys($entity, $action, &$params, $fields
   foreach ($fields as $fieldName => $fieldInfo) {
     if (!empty($fieldInfo['FKClassName'])) {
       if (!empty($params[$fieldName])) {
-        _civicrm_api3_validate_constraint($params[$fieldName], $fieldName, $fieldInfo);
+        foreach ((array) $params[$fieldName] as $fieldValue) {
+          _civicrm_api3_validate_constraint($fieldValue, $fieldName, $fieldInfo);
+        }
       }
       elseif (!empty($fieldInfo['required'])) {
         throw new Exception("DB Constraint Violation - $fieldName should possibly be marked as mandatory for $entity,$action API. If so, please raise a bug report.");