From 464ff9cc9ae1e5233e2de2dec62588699c67c019 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 7 Apr 2015 20:19:18 +1200 Subject: [PATCH] CRM-16247 Move activity creation until after transaction is committed It turns out the activity_contact table is somewhat susceptible to deadlocks & the rollback results in contributions being erased from the DB - especially in the case of IPNs --- CRM/Contribute/BAO/Contribution.php | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 7e1568ebfb..562930f66a 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -367,22 +367,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } } - // check if activity record exist for this contribution, if - // not add activity - $activity = new CRM_Activity_DAO_Activity(); - $activity->source_record_id = $contribution->id; - $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', - 'Contribution', - 'name' - ); - if (!$activity->find(TRUE)) { - CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline'); - } - else { - // CRM-13237 : if activity record found, update it with campaign id of contribution - CRM_Core_DAO::setFieldValue('CRM_Activity_BAO_Activity', $activity->id, 'campaign_id', $contribution->campaign_id); - } - // Handle soft credit and / or link to personal campaign page $softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id); @@ -436,6 +420,22 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $transaction->commit(); + // check if activity record exist for this contribution, if + // not add activity + $activity = new CRM_Activity_DAO_Activity(); + $activity->source_record_id = $contribution->id; + $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', + 'Contribution', + 'name' + ); + if (!$activity->find(TRUE)) { + CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline'); + } + else { + // CRM-13237 : if activity record found, update it with campaign id of contribution + CRM_Core_DAO::setFieldValue('CRM_Activity_BAO_Activity', $activity->id, 'campaign_id', $contribution->campaign_id); + } + // do not add to recent items for import, CRM-4399 if (empty($params['skipRecentView'])) { $url = CRM_Utils_System::url('civicrm/contact/view/contribution', -- 2.25.1