Skip to content
Snippets Groups Projects
Commit 4e90c17e authored by jaapjansma's avatar jaapjansma
Browse files

Fixed issue with the Add Contribution Trigger and retrieving Participant Data...

Fixed issue with the Add Contribution Trigger and retrieving Participant Data when it is a participant payment.
parent 849a5f61
Branches
Tags 1.15
No related merge requests found
# CHANGELOG
## Version 3.15-dev (not yet released)
## Version 3.15
* Fixed issue with the Add Contribution Trigger and retrieving Participant Data when it is a participant payment.
## Version 3.14.0 (2024-11-07)
......
<?php
/**
* Copyright (C) 2025 Jaap Jansma (jaap.jansma@civicoop.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
class CRM_Civirules_Utils_ContributionTrigger {
protected static $participantId = null;
public static function pre($op, $objectName, $objectId, &$params) {
if ($op == 'create' && $objectName == 'Contribution') {
self::$participantId = null;
if (isset($params['participant_id'])) {
self::$participantId = $params['participant_id'];
}
}
}
public static function getParticipantId():? int {
return self::$participantId;
}
}
......@@ -9,8 +9,8 @@
class CRM_CivirulesPostTrigger_Contribution extends CRM_Civirules_Trigger_Post {
/**
* Override alter trigger data.
*
* Override alter trigger data.
*
* When a contribution is added/updated after an online payment is made
* contact_id and financial_type_id are not present in the data in the post hook.
* So we should retrieve this data from the database.
......@@ -22,10 +22,18 @@
// Merge both arrays preserving the data in the posthook.
$newData = array_merge($dataInDatabase, $dataFromPostHook);
$triggerData->setEntityData('Contribution', $newData);
if (CRM_Civirules_Utils_ContributionTrigger::getParticipantId()) {
try {
$participant = civicrm_api3('Participant', 'getsingle', array('id' => CRM_Civirules_Utils_ContributionTrigger::getParticipantId()));
$triggerData->setEntityData('Participant', $participant);
} catch (Exception $e) {
// Do nothing
}
}
} catch (Exception $e) {
// Do nothing. There could be an exception when the contribution does not exists in the database anymore.
}
parent::alterTriggerData($triggerData);
}
......
......@@ -141,6 +141,7 @@ function _civirules_upgrade_to_2x_backup() {
* @param $params
*/
function civirules_civicrm_pre($op, $objectName, $objectId, &$params) {
CRM_Civirules_Utils_ContributionTrigger::pre($op, $objectName, $objectId, $params);
// New style pre/post Delete/Insert/Update events exist from 5.34.
if (civirules_use_prehook($op, $objectName, $objectId, $params)) {
try {
......
......@@ -14,8 +14,8 @@
<author>CiviCooP</author>
<email>helpdesk@civicoop.org</email>
</maintainer>
<releaseDate>2024-11-07</releaseDate>
<version>3.15-dev</version>
<releaseDate>2025-01-14</releaseDate>
<version>3.15</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.68</ver>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment