Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
7c919b71
Unverified
Commit
7c919b71
authored
5 years ago
by
mattwire
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #14197 from eileenmcnaughton/cont_cancel
#927
[ref] Extract contribution.cancel function
parents
cb64a05a
1ee67fa2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Contribute/BAO/Contribution.php
+90
-64
90 additions, 64 deletions
CRM/Contribute/BAO/Contribution.php
with
90 additions
and
64 deletions
CRM/Contribute/BAO/Contribution.php
+
90
−
64
View file @
7c919b71
...
...
@@ -970,6 +970,92 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
])[
'values'
];
}
/**
* Cancel contribution.
*
* This function should only be called from transitioncomponents - it is an interim step in refactoring.
*
* @param $processContributionObject
* @param $memberships
* @param $contributionId
* @param $membershipStatuses
* @param $updateResult
* @param $participant
* @param $oldStatus
* @param $pledgePayment
* @param $pledgeID
* @param $pledgePaymentIDs
* @param $contributionStatusId
* @return array
*/
protected
static
function
cancel
(
$processContributionObject
,
$memberships
,
$contributionId
,
$membershipStatuses
,
$updateResult
,
$participant
,
$oldStatus
,
$pledgePayment
,
$pledgeID
,
$pledgePaymentIDs
,
$contributionStatusId
)
{
$processContribution
=
FALSE
;
$participantStatuses
=
CRM_Event_PseudoConstant
::
participantStatus
();
if
(
is_array
(
$memberships
))
{
foreach
(
$memberships
as
$membership
)
{
$update
=
TRUE
;
//Update Membership status if there is no other completed contribution associated with the membership.
$relatedContributions
=
CRM_Member_BAO_Membership
::
getMembershipContributionId
(
$membership
->
id
,
TRUE
);
foreach
(
$relatedContributions
as
$contriId
)
{
if
(
$contriId
==
$contributionId
)
{
continue
;
}
$statusId
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contribute_BAO_Contribution'
,
$contriId
,
'contribution_status_id'
);
if
(
CRM_Core_PseudoConstant
::
getName
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
$statusId
)
===
'Completed'
)
{
$update
=
FALSE
;
}
}
if
(
$membership
&&
$update
)
{
$newStatus
=
array_search
(
'Cancelled'
,
$membershipStatuses
);
// Create activity
$allStatus
=
CRM_Member_BAO_Membership
::
buildOptions
(
'status_id'
,
'get'
);
$activityParam
=
[
'subject'
=>
"Status changed from
{
$allStatus
[
$membership
->
status_id
]
}
to
{
$allStatus
[
$newStatus
]
}
"
,
'source_contact_id'
=>
CRM_Core_Session
::
singleton
()
->
get
(
'userID'
),
'target_contact_id'
=>
$membership
->
contact_id
,
'source_record_id'
=>
$membership
->
id
,
'activity_type_id'
=>
'Change Membership Status'
,
'status_id'
=>
'Completed'
,
'priority_id'
=>
'Normal'
,
'activity_date_time'
=>
'now'
,
];
$membership
->
status_id
=
$newStatus
;
$membership
->
is_override
=
TRUE
;
$membership
->
status_override_end_date
=
'null'
;
$membership
->
save
();
civicrm_api3
(
'activity'
,
'create'
,
$activityParam
);
$updateResult
[
'updatedComponents'
][
'CiviMember'
]
=
$membership
->
status_id
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
}
}
if
(
$participant
)
{
$updatedStatusId
=
array_search
(
'Cancelled'
,
$participantStatuses
);
CRM_Event_BAO_Participant
::
updateParticipantStatus
(
$participant
->
id
,
$oldStatus
,
$updatedStatusId
,
TRUE
);
$updateResult
[
'updatedComponents'
][
'CiviEvent'
]
=
$updatedStatusId
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
if
(
$pledgePayment
)
{
CRM_Pledge_BAO_PledgePayment
::
updatePledgePaymentStatus
(
$pledgeID
,
$pledgePaymentIDs
,
$contributionStatusId
);
$updateResult
[
'updatedComponents'
][
'CiviPledge'
]
=
$contributionStatusId
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
return
[
$updateResult
,
$processContribution
];
}
/**
* @inheritDoc
*/
...
...
@@ -1757,9 +1843,9 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_
$participant
=
&
$objects
[
'participant'
];
$pledgePayment
=
&
$objects
[
'pledge_payment'
];
$contribution
=
&
$objects
[
'contribution'
];
$pledgeID
=
$oldStatus
=
NULL
;
$pledgePaymentIDs
=
[];
if
(
$pledgePayment
)
{
$pledgePaymentIDs
=
array
();
foreach
(
$pledgePayment
as
$key
=>
$object
)
{
$pledgePaymentIDs
[]
=
$object
->
id
;
}
...
...
@@ -1778,68 +1864,8 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_
// we might want to process contribution object.
$processContribution
=
FALSE
;
if
(
$contributionStatusId
==
array_search
(
'Cancelled'
,
$contributionStatuses
))
{
if
(
is_array
(
$memberships
))
{
foreach
(
$memberships
as
$membership
)
{
$update
=
TRUE
;
//Update Membership status if there is no other completed contribution associated with the membership.
$relatedContributions
=
CRM_Member_BAO_Membership
::
getMembershipContributionId
(
$membership
->
id
,
TRUE
);
foreach
(
$relatedContributions
as
$contriId
)
{
if
(
$contriId
==
$contributionId
)
{
continue
;
}
$statusId
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contribute_BAO_Contribution'
,
$contriId
,
'contribution_status_id'
);
if
(
CRM_Core_PseudoConstant
::
getName
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
$statusId
)
===
'Completed'
)
{
$update
=
FALSE
;
}
}
if
(
$membership
&&
$update
)
{
$newStatus
=
array_search
(
'Cancelled'
,
$membershipStatuses
);
// Create activity
$allStatus
=
CRM_Member_BAO_Membership
::
buildOptions
(
'status_id'
,
'get'
);
$activityParam
=
array
(
'subject'
=>
"Status changed from
{
$allStatus
[
$membership
->
status_id
]
}
to
{
$allStatus
[
$newStatus
]
}
"
,
'source_contact_id'
=>
CRM_Core_Session
::
singleton
()
->
get
(
'userID'
),
'target_contact_id'
=>
$membership
->
contact_id
,
'source_record_id'
=>
$membership
->
id
,
'activity_type_id'
=>
'Change Membership Status'
,
'status_id'
=>
'Completed'
,
'priority_id'
=>
'Normal'
,
'activity_date_time'
=>
'now'
,
);
$membership
->
status_id
=
$newStatus
;
$membership
->
is_override
=
TRUE
;
$membership
->
status_override_end_date
=
'null'
;
$membership
->
save
();
civicrm_api3
(
'activity'
,
'create'
,
$activityParam
);
$updateResult
[
'updatedComponents'
][
'CiviMember'
]
=
$membership
->
status_id
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
}
}
if
(
$participant
)
{
$updatedStatusId
=
array_search
(
'Cancelled'
,
$participantStatuses
);
CRM_Event_BAO_Participant
::
updateParticipantStatus
(
$participant
->
id
,
$oldStatus
,
$updatedStatusId
,
TRUE
);
$updateResult
[
'updatedComponents'
][
'CiviEvent'
]
=
$updatedStatusId
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
if
(
$pledgePayment
)
{
CRM_Pledge_BAO_PledgePayment
::
updatePledgePaymentStatus
(
$pledgeID
,
$pledgePaymentIDs
,
$contributionStatusId
);
$updateResult
[
'updatedComponents'
][
'CiviPledge'
]
=
$contributionStatusId
;
if
(
$processContributionObject
)
{
$processContribution
=
TRUE
;
}
}
// Call interim cancel function - with a goal to cleaning up the signature on it and switching to a tested api Contribution.cancel function.
list
(
$updateResult
,
$processContribution
)
=
self
::
cancel
(
$processContributionObject
,
$memberships
,
$contributionId
,
$membershipStatuses
,
$updateResult
,
$participant
,
$oldStatus
,
$pledgePayment
,
$pledgeID
,
$pledgePaymentIDs
,
$contributionStatusId
);
}
elseif
(
$contributionStatusId
==
array_search
(
'Failed'
,
$contributionStatuses
))
{
if
(
is_array
(
$memberships
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment