Skip to content

Commit

Permalink
Merge pull request #23755 from eileenmcnaughton/import_ivory_coast
Browse files Browse the repository at this point in the history
dev/core#3505, dev/core#3506 dev/core#3052 Import fixes for unicode url, Côte d’Ivoire
  • Loading branch information
totten authored Jun 10, 2022
2 parents bd8c4d2 + 8b3f43f commit 6a376dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
24 changes: 20 additions & 4 deletions CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ protected function getTransformedFieldValue(string $fieldName, $importedValue) {
return $importedValue;
}

$comparisonValue = is_numeric($importedValue) ? $importedValue : mb_strtolower($importedValue);
$comparisonValue = $this->getComparisonValue($importedValue);
return $options[$comparisonValue] ?? 'invalid_import_value';
}
if (!empty($fieldMetadata['FKClassName']) || !empty($fieldMetadata['pseudoconstant']['prefetch'])) {
Expand Down Expand Up @@ -1468,10 +1468,10 @@ protected function getFieldMetadata(string $fieldName, bool $loadOptions = FALSE
// name AND label as either might be used. We also lower case before checking
$values = [];
foreach ($options as $option) {
$idKey = is_numeric($option['id']) ? $option['id'] : mb_strtolower($option['id']);
$idKey = $this->getComparisonValue($option['id']);
$values[$idKey] = $option['id'];
foreach (['name', 'label', 'abbr'] as $key) {
$optionValue = mb_strtolower($option[$key] ?? '');
$optionValue = $this->getComparisonValue($option[$key] ?? '');
if ($optionValue !== '') {
if (isset($values[$optionValue]) && $values[$optionValue] !== $option['id']) {
if (!isset($this->ambiguousOptions[$fieldName][$optionValue])) {
Expand Down Expand Up @@ -1775,7 +1775,7 @@ protected function getSiteDefaultCountry(): int {
* @param string $importedValue
*/
protected function isAmbiguous(string $fieldName, $importedValue): bool {
return !empty($this->ambiguousOptions[$fieldName][mb_strtolower($importedValue)]);
return !empty($this->ambiguousOptions[$fieldName][$this->getComparisonValue($importedValue)]);
}

/**
Expand Down Expand Up @@ -2020,4 +2020,20 @@ public static function formatCustomDate(&$params, &$formatted, $dateType, $dateP
$formatted[$dateParam] = CRM_Utils_Date::processDate($params[$dateParam]);
}

/**
* Get the value to use for option comparison purposes.
*
* We do a case-insensitive comparison, also swapping ’ for '
* which has at least one known usage (Côte d’Ivoire).
*
* Note we do this to both sides of the comparison.
*
* @param int|string|false|null $importedValue
*
* @return false|int|string|null
*/
protected function getComparisonValue($importedValue) {
return is_numeric($importedValue) ? $importedValue : mb_strtolower(str_replace('', "'", $importedValue));
}

}
2 changes: 1 addition & 1 deletion CRM/Utils/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function url($url) {
// allow relative URL's (CRM-15598)
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
}
return (bool) filter_var($url, FILTER_VALIDATE_URL);
return (bool) filter_var(self::idnToAsci($url), FILTER_VALIDATE_URL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
first_name,Last Name,Website,Country
Iron,Man,https://কানাডা.com,Côte d'Ivoire
6 changes: 6 additions & 0 deletions tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,12 @@ public function testImport($csv, $mapper, $expectedError, $expectedOutcomes = []
*/
public function importDataProvider(): array {
return [
'individual_unicode.csv' => [
'csv' => 'individual_unicode.csv',
'mapper' => [['first_name'], ['last_name'], ['url', 1], ['country', 1]],
'expected_error' => '',
'expected_outcomes' => [CRM_Import_Parser::VALID => 1],
],
'individual_invalid_sub_type' => [
'csv' => 'individual_invalid_contact_sub_type.csv',
'mapper' => [['first_name'], ['last_name'], ['contact_sub_type']],
Expand Down

0 comments on commit 6a376dd

Please sign in to comment.