Skip to content

Commit

Permalink
Merge pull request #23550 from eileenmcnaughton/import_cust
Browse files Browse the repository at this point in the history
Clean up function signature
  • Loading branch information
seamuslee001 authored May 24, 2022
2 parents 2bcb7f6 + fc4954d commit ca13ec4
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,24 @@ public function __construct($mapperKeys = []) {

/**
* @param $customFieldID
* @param array $customFields
* @param $value
* @param array $fieldMetaData
* @param $dateType
*
* @return ?string
*/
private function validateCustomField($customFieldID, array $customFields, $value, $dateType): ?string {
if (!array_key_exists($customFieldID, $customFields)) {
return ts('field ID');
}
$fieldMetaData = $customFields[$customFieldID];
private function validateCustomField($customFieldID, $value, array $fieldMetaData, $dateType): ?string {
// validate null values for required custom fields of type boolean
if (!empty($customFields[$customFieldID]['is_required']) && (empty($value) && !is_numeric($value)) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
return $customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'];
if (!empty($fieldMetaData['is_required']) && (empty($value) && !is_numeric($value)) && $fieldMetaData['data_type'] == 'Boolean') {
return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
}

/* validate the data against the CF type */

if ($value) {
$dataType = $customFields[$customFieldID]['data_type'];
$htmlType = $customFields[$customFieldID]['html_type'];
$isSerialized = CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID]);
$dataType = $fieldMetaData['data_type'];
$htmlType = $fieldMetaData['html_type'];
$isSerialized = CRM_Core_BAO_CustomField::isSerialized($fieldMetaData);
if ($dataType === 'Date') {
$params = ['date_field' => $value];
if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'date_field')) {
Expand All @@ -167,7 +163,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
}
elseif ($dataType == 'Boolean') {
if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
return $customFields[$customFieldID]['label'] . '::' . $customFields[$customFieldID]['groupTitle'];
return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
}
}
// need not check for label filed import
Expand All @@ -179,7 +175,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
if ((!$isSerialized && !in_array($htmlType, $selectHtmlTypes)) || $dataType == 'Boolean' || $dataType == 'ContactReference') {
$valid = CRM_Core_BAO_CustomValue::typecheck($dataType, $value);
if (!$valid) {
return $customFields[$customFieldID]['label'];
return $fieldMetaData['label'];
}
}

Expand All @@ -202,7 +198,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
}

if (!$flag) {
return $customFields[$customFieldID]['label'];
return $fieldMetaData['label'];
}
}
}
Expand All @@ -215,7 +211,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
}
}
if (!$flag) {
return $customFields[$customFieldID]['label'];
return $fieldMetaData['label'];
}
}
elseif ($isSerialized && $dataType === 'StateProvince') {
Expand All @@ -226,7 +222,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
continue;
}
else {
return $customFields[$customFieldID]['label'];
return $fieldMetaData['label'];
}
}
}
Expand All @@ -248,7 +244,7 @@ private function validateCustomField($customFieldID, array $customFields, $value
}

if ($error) {
return $customFields[$customFieldID]['label'];
return $fieldMetaData['label'];
}
}
}
Expand Down Expand Up @@ -1120,11 +1116,14 @@ public static function isErrorInCustomData($params, &$errorMessage, $csType = NU
//values so need to modify
if (array_key_exists($customFieldID, $addressCustomFields)) {
$value = $value[0][$key];
$errors[] = $parser->validateCustomField($customFieldID, $addressCustomFields, $value, $dateType);
$errors[] = $parser->validateCustomField($customFieldID, $value, $addressCustomFields[$customFieldID], $dateType);
}
else {
if (!array_key_exists($customFieldID, $customFields)) {
return ts('field ID');
}
/* check if it's a valid custom field id */
$errors[] = $parser->validateCustomField($customFieldID, $customFields, $value, $dateType);
$errors[] = $parser->validateCustomField($customFieldID, $value, $customFields[$customFieldID], $dateType);
}
}
elseif (is_array($params[$key]) && isset($params[$key]["contact_type"]) && in_array(substr($key, -3), ['a_b', 'b_a'], TRUE)) {
Expand Down

0 comments on commit ca13ec4

Please sign in to comment.