Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove if & foreach that no longer do anything #22447

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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