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';
}