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

[REF] minor tidy ups on very nasty function #15722

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -1732,14 +1732,14 @@ public static function relatedMemberships($contactId, &$params, $ids, $action =
// contacts.

// Get the Membership Type Details.
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']);
$membershipType = CRM_Member_BAO_MembershipType::getMembershipType($membershipValues['membership_type_id']);
// Check if contact's relationship type exists in membership type
$relTypeDirs = [];
if (!empty($membershipType['relationship_type_id'])) {
$relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
$relTypeIds = (array) $membershipType['relationship_type_id'];
}
if (!empty($membershipType['relationship_direction'])) {
$relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
$relDirections = (array) $membershipType['relationship_direction'];
}
foreach ($relTypeIds as $key => $value) {
$relTypeDirs[] = $value . '_' . $relDirections[$key];
Expand All @@ -1763,11 +1763,6 @@ public static function relatedMemberships($contactId, &$params, $ids, $action =
$membershipValues['status_id'] = $deceasedStatusId;
$membershipValues['skipStatusCal'] = TRUE;
}
foreach (['join_date', 'start_date', 'end_date'] as $dateField) {
if (!empty($membershipValues[$dateField])) {
$membershipValues[$dateField] = CRM_Utils_Date::processDate($membershipValues[$dateField]);
}
}

if ($action & CRM_Core_Action::UPDATE) {
//if updated relationship is already related to contact don't delete existing inherited membership
Expand Down
7 changes: 6 additions & 1 deletion tests/phpunit/CRM/Contact/BAO/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ public function testSingleMembershipForTwoRelationships() {
$this->callAPISuccess('Membership', 'create', [
'membership_type_id' => $membershipType['id'],
'contact_id' => $organisationID,
'start_date' => '2019-08-19',
'join_date' => '2019-07-19',
]);

$relationshipOne = $this->callAPISuccess('Relationship', 'create', [
Expand All @@ -256,7 +258,10 @@ public function testSingleMembershipForTwoRelationships() {
'relationship_type_id' => $orgToPersonTypeId2,
]);

$this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
$inheritedMembership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $individualID]);
$this->assertEquals('2019-08-19', $inheritedMembership['start_date']);
$this->assertEquals('2019-07-19', $inheritedMembership['join_date']);

$this->callAPISuccessGetCount('Membership', ['contact_id' => $organisationID], 1);
// Disable the relationship & check the membership is not removed because the other relationship is still valid.
$relationshipOne['is_active'] = 0;
Expand Down