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] towards cleanup of update membership code #13759

Merged
merged 1 commit into from
Mar 5, 2019
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
40 changes: 30 additions & 10 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,30 @@ protected static function getToFinancialAccount($contribution, $params) {
}
}

/**
* Get memberships realted to the contribution.
*
* @param int $contributionID
*
* @return array
*/
protected static function getRelatedMemberships($contributionID) {
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $contributionID;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this 'double loading' of contribution is because we expect to stop passing the contribution object later

$contribution->fetch(TRUE);
$contribution->loadRelatedMembershipObjects();
$result = CRM_Utils_Array::value('membership', $contribution->_relatedObjects, []);
$memberships = [];
foreach ($result as $membership) {
if (empty($membership)) {
continue;
}
// @todo - remove this again & just call api in the first place.
_civicrm_api3_object_to_array($membership, $memberships[$membership->id]);
}
return $memberships;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -5231,18 +5255,14 @@ protected static function isPaymentInstrumentChange(&$params, $pendingStatuses)
* @throws \CiviCRM_API3_Exception
*/
public static function updateMembershipBasedOnCompletionOfContribution($contribution, $primaryContributionID, $changeDate) {
$contribution->loadRelatedMembershipObjects();
if (empty($contribution->_relatedObjects['membership'])) {
return;
}
$memberships = $contribution->_relatedObjects['membership'];
foreach ($memberships as $membershipTypeIdKey => $membership) {
$memberships = self::getRelatedMemberships($contribution->id);
foreach ($memberships as $membership) {
if ($membership) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is is extraneous - but let's remove as a separate PR to keep this clean

$membershipParams = array(
'id' => $membership->id,
'contact_id' => $membership->contact_id,
'is_test' => $membership->is_test,
'membership_type_id' => $membership->membership_type_id,
'id' => $membership['id'],
'contact_id' => $membership['contact_id'],
'is_test' => $membership['is_test'],
'membership_type_id' => $membership['membership_type_id'],
'membership_activity_status' => 'Completed',
);

Expand Down