From 332fe306ddb93a5f2cfa08cd0af77e3d297a01d8 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 9 Jun 2022 15:32:11 +1200 Subject: [PATCH] Extra fix to headerPatterns so fields 'guess' better --- CRM/Custom/Import/Parser/Api.php | 7 +++---- CRM/Import/Parser.php | 6 +++--- tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CRM/Custom/Import/Parser/Api.php b/CRM/Custom/Import/Parser/Api.php index a8a0020840..0df37ed2a2 100644 --- a/CRM/Custom/Import/Parser/Api.php +++ b/CRM/Custom/Import/Parser/Api.php @@ -1,7 +1,6 @@ getGroupFieldsForImport($customGroupID); $this->importableFieldsMetadata = array_merge([ 'do_not_import' => ['title' => ts('- do not import -')], - 'contact_id' => ['title' => ts('Contact ID'), 'name' => 'contact_id', 'type' => CRM_Utils_Type::T_INT, 'options' => FALSE], - 'external_identifier' => ['title' => ts('External Identifier'), 'name' => 'external_identifier', 'type' => CRM_Utils_Type::T_INT, 'options' => FALSE], + 'contact_id' => ['title' => ts('Contact ID'), 'name' => 'contact_id', 'type' => CRM_Utils_Type::T_INT, 'options' => FALSE, 'headerPattern' => '/contact?|id$/i'], + 'external_identifier' => ['title' => ts('External Identifier'), 'name' => 'external_identifier', 'type' => CRM_Utils_Type::T_INT, 'options' => FALSE, 'headerPattern' => '/external\s?id/i'], ], $importableFields); } } @@ -196,7 +195,7 @@ class CRM_Custom_Import_Parser_Api extends CRM_Import_Parser { $importableFields[$key] = [ 'name' => $key, 'title' => $values['label'] ?? NULL, - 'headerPattern' => '/' . preg_quote($regexp, '/') . '/', + 'headerPattern' => '/' . preg_quote($regexp, '/') . '/i', 'import' => 1, 'custom_field_id' => $values['id'], 'options_per_line' => $values['options_per_line'], diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 099e0afd5d..0e6419ef1b 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -571,9 +571,9 @@ abstract class CRM_Import_Parser { */ public function getHeaderPatterns(): array { $values = []; - foreach ($this->_fields as $name => $field) { - if (isset($field->_headerPattern)) { - $values[$name] = $field->_headerPattern; + foreach ($this->importableFieldsMetadata as $name => $field) { + if (isset($field['headerPattern'])) { + $values[$name] = $field['headerPattern'] ?: '//'; } } return $values; diff --git a/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php b/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php index 05d261b119..4816b19708 100644 --- a/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php +++ b/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php @@ -38,7 +38,6 @@ class CRM_Custom_Import_Parser_ApiTest extends CiviUnitTestCase { $this->assertEquals('ERROR', $row['_status']); } - /** * Get the import's datasource form. * -- 2.25.1