From 2e537447f9e4d6f508c16893fe920372cdd504a5 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Wed, 17 May 2017 16:09:35 +0530 Subject: [PATCH] move contact id validation to wrapper --- api/v3/Activity.php | 37 ------------------------------------- api/v3/utils.php | 4 +++- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/api/v3/Activity.php b/api/v3/Activity.php index 66d1544b7d..26f45d615f 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -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), diff --git a/api/v3/utils.php b/api/v3/utils.php index dd55453e45..7f0c00cc3b 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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."); -- 2.25.1