Skip to content

Commit

Permalink
Merge pull request #15215 from eileenmcnaughton/import_next
Browse files Browse the repository at this point in the history
[Ref] Import use process for relationship defaults, add test
eileenmcnaughton authored Sep 4, 2019
2 parents 8437566 + 4535ed2 commit 08a7018
Showing 3 changed files with 17 additions and 28 deletions.
27 changes: 3 additions & 24 deletions CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
@@ -400,6 +400,7 @@ public function buildQuickForm() {
$processor->setFormName($formName);
$processor->setMetadata($this->getContactImportMetadata());
$processor->setContactTypeByConstant($this->get('contactType'));
$processor->setContactSubType($this->get('contactSubType'));

for ($i = 0; $i < $this->_columnCount; $i++) {
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL);
@@ -863,37 +864,15 @@ public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $
if ($mappingName[$i] != ts('- do not import -')) {

if ($processor->getRelationshipKey($i)) {
$contactType = $processor->getContactType();
//CRM-5125
$contactSubType = NULL;
if ($this->get('contactSubType')) {
$contactSubType = $this->get('contactSubType');
}

$relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType,
FALSE, 'label', TRUE, $contactSubType
);

foreach ($relations as $key => $var) {
if ($processor->getValidRelationshipKey($i)) {
$relation = $processor->getValidRelationshipKey($i);
break;
}
}

$contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i]));
$websiteTypeId = $processor->getWebsiteTypeID($i);
$locationId = $processor->getLocationTypeID($i);
$phoneType = $processor->getPhoneTypeID($i);
$imProvider = $processor->getIMProviderID($i);
$typeId = $processor->getPhoneOrIMTypeID($i);

if ($websiteTypeId) {
$defaults["mapper[$i]"] = [$relation, $contactDetails, $websiteTypeId];
}
else {

$defaults["mapper[$i]"] = [$relation, $contactDetails, $locationId, $typeId];
$defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
if (!$websiteTypeId) {
if (!$locationId) {
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
}
6 changes: 6 additions & 0 deletions CRM/Import/ImportProcessor.php
Original file line number Diff line number Diff line change
@@ -513,6 +513,12 @@ public function getQuickFormJSForField($column) {
* @throws \CiviCRM_API3_Exception
*/
public function getSavedQuickformDefaultsForColumn($column) {
if ($this->getValidRelationshipKey($column)) {
if ($this->getWebsiteTypeID($column)) {
return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getWebsiteTypeID($column)];
}
return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getLocationTypeID($column), $this->getPhoneOrIMTypeID($column)];
}
if ($this->getWebsiteTypeID($column)) {
return [$this->getFieldName($column), $this->getWebsiteTypeID($column)];
}
12 changes: 8 additions & 4 deletions tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php
Original file line number Diff line number Diff line change
@@ -310,10 +310,14 @@ public function mapFieldDataProvider() {
],
[
// Yes, the relationship mapping really does use url whereas non relationship uses website because... legacy
['name' => 'Url', 'contact_type' => 'Individual', 'column_number' => 0, 'website_type_id', 'relationship_type_id' => 1, 'relationship_direction' => 'a_b'],
"document.forms.MapField['mapper[0][2]'].style.display = 'none';
document.forms.MapField['mapper[0][3]'].style.display = 'none';\n",
['mapper[0]' => ['1_a_b', 'url', 0, NULL]],
['name' => 'Url', 'contact_type' => 'Individual', 'column_number' => 0, 'website_type_id' => 1, 'relationship_type_id' => 1, 'relationship_direction' => 'a_b'],
"document.forms.MapField['mapper[0][3]'].style.display = 'none';\n",
['mapper[0]' => ['1_a_b', 'url', 1]],
],
[
['name' => 'Phone', 'contact_type' => 'Individual', 'column_number' => 0, 'phone_type_id' => 1, 'relationship_type_id' => 1, 'relationship_direction' => 'b_a'],
'',
['mapper[0]' => ['1_b_a', 'phone', 'Primary', 1]],
],
];
}

0 comments on commit 08a7018

Please sign in to comment.