Skip to content

Commit

Permalink
Merge pull request civicrm#28494 from eileenmcnaughton/crazy_param
Browse files Browse the repository at this point in the history
Cleanup return on processContact
  • Loading branch information
eileenmcnaughton authored Dec 5, 2023
2 parents 810014d + 4237a2b commit bd5a38c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function import(array $values): void {
}
}

[$formatted, $params] = $this->processContact($params, $formatted, TRUE);
$formatted['id'] = $params['id'] = $this->processContact($params, TRUE);

//format common data, CRM-4062
$this->formatCommonData($params, $formatted);
Expand All @@ -177,7 +177,8 @@ public function import(array $values): void {

//relationship contact insert
foreach ($this->getRelatedContactsParams($params) as $key => $field) {
[$formatting, $field] = $this->processContact($field, $field, FALSE);
$field['id'] = $this->processContact($field, FALSE);
$formatting = $field;
//format common data, CRM-4062
$this->formatCommonData($field, $formatting);
$isUpdate = empty($formatting['id']) ? 'new' : 'updated';
Expand Down Expand Up @@ -1546,25 +1547,24 @@ protected function lookupContactID(array $params, bool $isMainContact): ?int {

/**
* @param array $params
* @param array $formatted
* @param bool $isMainContact
*
* @return array[]
* @return int|null
* @throws \CRM_Core_Exception
*/
protected function processContact(array $params, array $formatted, bool $isMainContact): array {
$params['id'] = $formatted['id'] = $this->lookupContactID($params, $isMainContact);
if ($params['id'] && !empty($params['contact_sub_type'])) {
protected function processContact(array $params, bool $isMainContact): ?int {
$contactID = $this->lookupContactID($params, $isMainContact);
if ($contactID && !empty($params['contact_sub_type'])) {
$contactSubType = Contact::get(FALSE)
->addWhere('id', '=', $params['id'])
->addWhere('id', '=', $contactID)
->addSelect('contact_sub_type')
->execute()
->first()['contact_sub_type'];
if (!empty($contactSubType) && $contactSubType[0] !== $params['contact_sub_type'] && !CRM_Contact_BAO_ContactType::isAllowEdit($params['id'], $contactSubType[0])) {
if (!empty($contactSubType) && $contactSubType[0] !== $params['contact_sub_type'] && !CRM_Contact_BAO_ContactType::isAllowEdit($contactID, $contactSubType[0])) {
throw new CRM_Core_Exception('Mismatched contact SubTypes :', CRM_Import_Parser::NO_MATCH);
}
}
return [$formatted, $params];
return $contactID;
}

/**
Expand Down

0 comments on commit bd5a38c

Please sign in to comment.