Error cancelling a contribution if CiviPledge is disabled
Overview
If the CiviPledge component is disabled, changing a contribution's status to "Cancelled" will throw an error.
Reproduction steps
- Disable CiviPledge at /civicrm/admin/setting/component?reset=1
- Create a contribution
- Edit the contribution and set the status to "Cancelled"
- Save
Comments
When trying to cancel through the UI, the ajax spinner will keep going. If you refresh page the contribution status will be updated.
I tried cancelling the contribution through the APIv4 browser and it throws this error: "PledgePayment API is not available because CiviPledge component is disabled".
The culprit seems to be disconnectPledgePaymentsIfCancelled()
that is called by CRM_Contribute_BAO_Contribution::create()
. It makes an APIv4 call for PledgePayment but doesn't take the status of the component into account.
Environment information
- CiviCRM: 5.46.1