[REF] Relocate another function from DeprecatedUtils to the calling class
authoreileen <emcnaughton@wikimedia.org>
Mon, 21 Dec 2020 07:54:20 +0000 (20:54 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 21 Dec 2020 08:25:57 +0000 (21:25 +1300)
This is only called from one class so relocate to there

CRM/Activity/Import/Parser/Activity.php
CRM/Utils/DeprecatedUtils.php

index aa2239dc3da856d3f187a6d6fa3ae3b58299aafe..cccd68e0dbfe97933800c26ba1443df54ecea943 100644 (file)
@@ -271,8 +271,7 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
       }
     }
     // Date-Format part ends.
-    require_once 'CRM/Utils/DeprecatedUtils.php';
-    $formatError = _civicrm_api3_deprecated_activity_formatted_param($params, $params, TRUE);
+    $formatError = $this->deprecated_activity_formatted_param($params, $params, TRUE);
 
     if ($formatError) {
       array_unshift($values, $formatError['error_message']);
@@ -374,4 +373,67 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
     return CRM_Import_Parser::VALID;
   }
 
+  /**
+   * take the input parameter list as specified in the data model and
+   * convert it into the same format that we use in QF and BAO object
+   *
+   * @param array $params
+   *   Associative array of property name/value.
+   *                             pairs to insert in new contact.
+   * @param array $values
+   *   The reformatted properties that we can use internally.
+   *
+   * @param array|bool $create Is the formatted Values array going to
+   *                             be used for CRM_Activity_BAO_Activity::create()
+   *
+   * @return array|CRM_Error
+   */
+  protected function deprecated_activity_formatted_param(&$params, &$values, $create = FALSE) {
+    // copy all the activity fields as is
+    $fields = CRM_Activity_DAO_Activity::fields();
+    _civicrm_api3_store_values($fields, $params, $values);
+
+    require_once 'CRM/Core/OptionGroup.php';
+    $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
+
+    foreach ($params as $key => $value) {
+      // ignore empty values or empty arrays etc
+      if (CRM_Utils_System::isNull($value)) {
+        continue;
+      }
+
+      //Handling Custom Data
+      if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
+        $values[$key] = $value;
+        $type = $customFields[$customFieldID]['html_type'];
+        if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID])) {
+          $values[$key] = CRM_Import_Parser::unserializeCustomValue($customFieldID, $value, $type);
+        }
+        elseif ($type == 'Select' || $type == 'Radio') {
+          $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+          foreach ($customOption as $customFldID => $customValue) {
+            $val = $customValue['value'] ?? NULL;
+            $label = $customValue['label'] ?? NULL;
+            $label = strtolower($label);
+            $value = strtolower(trim($value));
+            if (($value == $label) || ($value == strtolower($val))) {
+              $values[$key] = $val;
+            }
+          }
+        }
+      }
+
+      if ($key == 'target_contact_id') {
+        if (!CRM_Utils_Rule::integer($value)) {
+          return civicrm_api3_create_error("contact_id not valid: $value");
+        }
+        $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value");
+        if (!$contactID) {
+          return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = $value.");
+        }
+      }
+    }
+    return NULL;
+  }
+
 }
index 8f8b27cf4c5be55f7b0ab73eff3f0271550087ea..1fe35cc8da1ed6fa345212f9e1670dbc1723cb9f 100644 (file)
@@ -101,69 +101,6 @@ function _civicrm_api3_deprecated_check_contact_dedupe($params) {
   return _civicrm_api3_deprecated_duplicate_formatted_contact($contactFormatted);
 }
 
-/**
- * take the input parameter list as specified in the data model and
- * convert it into the same format that we use in QF and BAO object
- *
- * @param array $params
- *   Associative array of property name/value.
- *                             pairs to insert in new contact.
- * @param array $values
- *   The reformatted properties that we can use internally.
- *
- * @param array|bool $create Is the formatted Values array going to
- *                             be used for CRM_Activity_BAO_Activity::create()
- *
- * @return array|CRM_Error
- */
-function _civicrm_api3_deprecated_activity_formatted_param(&$params, &$values, $create = FALSE) {
-  // copy all the activity fields as is
-  $fields = CRM_Activity_DAO_Activity::fields();
-  _civicrm_api3_store_values($fields, $params, $values);
-
-  require_once 'CRM/Core/OptionGroup.php';
-  $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    //Handling Custom Data
-    if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
-      $values[$key] = $value;
-      $type = $customFields[$customFieldID]['html_type'];
-      if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID])) {
-        $values[$key] = CRM_Import_Parser::unserializeCustomValue($customFieldID, $value, $type);
-      }
-      elseif ($type == 'Select' || $type == 'Radio') {
-        $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
-        foreach ($customOption as $customFldID => $customValue) {
-          $val = $customValue['value'] ?? NULL;
-          $label = $customValue['label'] ?? NULL;
-          $label = strtolower($label);
-          $value = strtolower(trim($value));
-          if (($value == $label) || ($value == strtolower($val))) {
-            $values[$key] = $val;
-          }
-        }
-      }
-    }
-
-    if ($key == 'target_contact_id') {
-      if (!CRM_Utils_Rule::integer($value)) {
-        return civicrm_api3_create_error("contact_id not valid: $value");
-      }
-      $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value");
-      if (!$contactID) {
-        return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = $value.");
-      }
-    }
-  }
-  return NULL;
-}
-
 /**
  * This function adds the contact variable in $values to the
  * parameter list $params.  For most cases, $values should have length 1.  If