Merge pull request #5057 from cividesk/CRM-15901-4.5
[civicrm-core.git] / CRM / Utils / DeprecatedUtils.php
index 591cac52a7041009829dfb03cf4df46db53a8912..0fda33b51655724e5c3e980d03e9cf7c6fd576d4 100644 (file)
@@ -285,11 +285,13 @@ function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = F
         }
         $dao = new CRM_Core_DAO();
         $qParams = array();
-        $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value",
+        $svq = $dao->singleValueQuery("SELECT is_deleted FROM civicrm_contact WHERE id = $value",
           $qParams
         );
-        if (!$svq) {
+        if (!isset($svq)) {
           return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = $value.");
+        } else if ($svq == 1) {
+          return civicrm_api3_create_error("Invalid Contact ID: contact_id $value is a soft-deleted contact.");
         }
 
         $values['contact_id'] = $values['contribution_contact_id'];
@@ -415,7 +417,9 @@ function _civicrm_api3_deprecated_formatted_param($params, &$values, $create = F
               $contact->external_identifier = $externalId;
               $errorMsg = NULL;
               if (!$contact->find(TRUE)) {
-                $errorMsg = $contactId ? ts("Soft Credit ContactID - $contactId doesn't exist. Row was skipped.") : ts("Provided Soft Credit External Identifier - $externalIddoesn't exist. Row was skipped.");
+                $field = $contactId ? ts('Contact ID') : ts('External ID');
+                $errorMsg = ts("Soft Credit %1 - %2 doesn't exist. Row was skipped.",
+                  array(1 => $field, 2 => $contactId ? $contactId : $externalId));
               }
 
               if ($errorMsg) {
@@ -869,7 +873,7 @@ function _civicrm_api3_deprecated_add_formatted_param(&$values, &$params) {
     return TRUE;
   }
 
-  if (isset($values['preferred_communication_method'])) {
+  if (!empty($values['preferred_communication_method'])) {
     $comm = array();
     $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method')), CASE_LOWER);
 
@@ -1188,7 +1192,7 @@ function _civicrm_api3_deprecated_validate_formatted_contact(&$params) {
           $valid = CRM_Core_BAO_CustomValue::typecheck(CRM_Utils_Array::value('type', $value),
             CRM_Utils_Array::value('value', $value)
           );
-          if (!$valid) {
+          if (!$valid && $value['is_required']) {
             return civicrm_api3_create_error('Invalid value for custom field \'' .
               CRM_Utils_Array::value('name', $custom) . '\''
             );