From 2883b934973d76e3488b42a5a1d53f2df72cd232 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Fri, 15 Nov 2019 14:55:48 +0530 Subject: [PATCH] dev/mem#17 - Deleting memberships does not delete its related line item --- CRM/Member/BAO/Membership.php | 3 ++- tests/phpunit/CRM/Member/BAO/MembershipTest.php | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 8386983c6764..9b184d93ccc7 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -641,6 +641,7 @@ public static function deleteMembership($membershipId, $preserveContrib = FALSE) CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId, $preserveContrib); + CRM_Price_BAO_LineItem::deleteLineItems($membershipId, 'civicrm_membership'); $results = $membership->delete(); $transaction->commit(); @@ -2227,7 +2228,7 @@ public static function updateAllMembershipStatus() { self::processOverriddenUntilDateMembership($dao1); } - $query = $baseQuery . " AND (civicrm_membership.is_override = 0 OR civicrm_membership.is_override IS NULL) + $query = $baseQuery . " AND (civicrm_membership.is_override = 0 OR civicrm_membership.is_override IS NULL) AND civicrm_membership.status_id NOT IN (%1, %2, %3, %4) AND civicrm_membership.owner_membership_id IS NULL "; $params = [ diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 08b494293962..f8b57375eb66 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -291,6 +291,9 @@ public function testDeleteMembership() { $this->assertDBNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for deleted membership.' ); + $this->assertDBNull('CRM_Price_BAO_LineItem', $membershipId, 'id', + 'entity_id', 'Database check for deleted line item.' + ); $this->contactDelete($contactId); }