Skip to content

Commit

Permalink
Merge pull request #22447 from eileenmcnaughton/legg
Browse files Browse the repository at this point in the history
Remove if & foreach that no longer do anything
  • Loading branch information
colemanw authored Jan 10, 2022
2 parents 9fbb5d0 + e76b110 commit f9c1b95
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,51 +170,43 @@ public static function legacyCreateMultiple($params, $ids = []) {
// and the other in jma grant applications (CRM_Grant_Form_Grant_Confirm)
// both only pass in contact as a key here.
$ids = ['contact' => $ids['contact']];
// Likewise neither place ever passed in relationshipID
$relationshipId = NULL;
// There is only ever one value passed in from the 2 places above that call
// this - by clarifying here like this we can cleanup within this
// function without having to do more universe searches.
$relatedContactIDs = [key($params['contact_check'])];

if (!$relationshipId) {
// creating a new relationship
foreach ($relatedContactIDs as $relatedContactID) {
// check if the relationship is valid between contacts.
// step 1: check if the relationship is valid if not valid skip and keep the count
// step 2: check the if two contacts already have a relationship if yes skip and keep the count
// step 3: if valid relationship then add the relation and keep the count

// step 1
$contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID);
$errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID);
if ($errors) {
return [0, 0];
}
$relatedContactID = key($params['contact_check']);

//CRM-16978:check duplicate relationship as per case id.
// https://issues.civicrm.org/jira/browse/CRM-16978
if ($caseId = CRM_Utils_Array::value('case_id', $params)) {
CRM_Core_Error::deprecatedWarning('this code is believed to be unreachable');
$contactFields['case_id'] = $caseId;
}
if (
self::checkDuplicateRelationship(
$contactFields,
CRM_Utils_Array::value('contact', $ids),
// step 2
$relatedContactID
)
) {
return [0, 1];
}
// check if the relationship is valid between contacts.
// step 1: check if the relationship is valid if not valid skip and keep the count
// step 2: check the if two contacts already have a relationship if yes skip and keep the count
// step 3: if valid relationship then add the relation and keep the count

$singleInstanceParams = array_merge($params, $contactFields);
$relationship = self::add($singleInstanceParams);
}
// editing the relationship
// step 1
$contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID);
$errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID);
if ($errors) {
return [0, 0];
}

//CRM-16978:check duplicate relationship as per case id.
// https://issues.civicrm.org/jira/browse/CRM-16978
if ($caseId = CRM_Utils_Array::value('case_id', $params)) {
CRM_Core_Error::deprecatedWarning('this code is believed to be unreachable');
$contactFields['case_id'] = $caseId;
}
if (
self::checkDuplicateRelationship(
$contactFields,
CRM_Utils_Array::value('contact', $ids),
// step 2
$relatedContactID
)
) {
return [0, 1];
}

$singleInstanceParams = array_merge($params, $contactFields);
$relationship = self::add($singleInstanceParams);

// do not add to recent items for import, CRM-4399
if (!(!empty($params['skipRecentView']))) {
self::addRecent($params, $relationship);
Expand Down

0 comments on commit f9c1b95

Please sign in to comment.