Merge pull request #25886 from eileenmcnaughton/import_contribution_api4
authorcolemanw <coleman@civicrm.org>
Mon, 27 Mar 2023 20:21:38 +0000 (16:21 -0400)
committerGitHub <noreply@github.com>
Mon, 27 Mar 2023 20:21:38 +0000 (16:21 -0400)
Update Contribution Import to use apiv4 field names, prior to adding hooks

1  2 
CRM/Contribute/Import/Parser/Contribution.php
CRM/Import/Parser.php

index baac46be146c42346a8e2c40e7fe9c1df92efe80,88ff6690eab0197b4ea6a2c85b57c26521e50616..0ccf1f8a0cd72a18f35db2480295b02b9e25df7c
@@@ -1594,16 -1594,30 +1594,30 @@@ abstract class CRM_Import_Parser implem
        return CRM_Utils_Rule::email($importedValue) ? $importedValue : 'invalid_import_value';
      }
  
-     if ($fieldMetadata['type'] === CRM_Utils_Type::T_FLOAT) {
+     // DataType is defined on apiv4 metadata - ie what we are moving to.
+     $typeMap = [
+       CRM_Utils_Type::T_FLOAT => 'Float',
+       CRM_Utils_Type::T_MONEY => 'Money',
+       CRM_Utils_Type::T_BOOLEAN => 'Boolean',
+       CRM_Utils_Type::T_DATE => 'Date',
+       (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) => 'Timestamp',
+       CRM_Utils_Type::T_TIMESTAMP => 'Timestamp',
+       CRM_Utils_Type::T_INT => 'Integer',
+       CRM_Utils_Type::T_TEXT => 'String',
+       CRM_Utils_Type::T_STRING => 'String',
+     ];
+     $dataType = $fieldMetadata['data_type'] ?? $typeMap[$fieldMetadata['type']];
+     if ($dataType === 'Float') {
        return CRM_Utils_Rule::numeric($importedValue) ? $importedValue : 'invalid_import_value';
      }
-     if ($fieldMetadata['type'] === CRM_Utils_Type::T_MONEY) {
+     if ($dataType === 'Money') {
        return CRM_Utils_Rule::money($importedValue, TRUE) ? CRM_Utils_Rule::cleanMoney($importedValue) : 'invalid_import_value';
      }
-     if ($fieldMetadata['type'] === CRM_Utils_Type::T_BOOLEAN) {
+     if ($dataType === 'Boolean') {
        $value = CRM_Utils_String::strtoboolstr($importedValue);
        if ($value !== FALSE) {
 -        return (bool) $value;
 +        return (int) $value;
        }
        return 'invalid_import_value';
      }