From 97e9e3dc683c9e519ad5ea161098f2068212e4e7 Mon Sep 17 00:00:00 2001 From: yashodha Date: Wed, 1 Jul 2015 17:10:36 +0530 Subject: [PATCH] CRM-16735: PCP notification email should not be sent when contribution record is updated UNLESS a new PCP soft credit is added ---------------------------------------- * CRM-16735: PCP notification email should not be sent when contribution record is updated UNLESS a new PCP soft credit is added https://issues.civicrm.org/jira/browse/CRM-16735 --- CRM/Contribute/BAO/Contribution.php | 45 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index aaaebbb8d6..6f45d2150f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -376,25 +376,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $deleteParams = array('id' => $pcpId); CRM_Contribute_BAO_ContributionSoft::del($deleteParams); } - if ($pcp = CRM_Utils_Array::value('pcp', $params)) { - $softParams = array(); - $softParams['contribution_id'] = $contribution->id; - $softParams['pcp_id'] = $pcp['pcp_made_through_id']; - $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', - $pcp['pcp_made_through_id'], 'contact_id' - ); - $softParams['currency'] = $contribution->currency; - $softParams['amount'] = $contribution->total_amount; - $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp); - $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp); - $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp); - $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name'); - $contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($softParams); - //Send notification to owner for PCP - if ($contributionSoft->pcp_id && empty($params['soft_credit_ids'])) { - CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft); - } - } + if (isset($params['soft_credit'])) { $softParams = $params['soft_credit']; @@ -406,7 +388,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } } } - + $createSoft = FALSE; foreach ($softParams as $softParam) { $softParam['contribution_id'] = $contribution->id; $softParam['currency'] = $contribution->currency; @@ -414,10 +396,33 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { if (empty($softParam['amount'])) { $softParam['amount'] = $contribution->total_amount; } + if (empty($softParam['id'])) { + $createSoft = TRUE; + } CRM_Contribute_BAO_ContributionSoft::add($softParam); } } + if ($pcp = CRM_Utils_Array::value('pcp', $params)) { + $softParams = array(); + $softParams['contribution_id'] = $contribution->id; + $softParams['pcp_id'] = $pcp['pcp_made_through_id']; + $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', + $pcp['pcp_made_through_id'], 'contact_id' + ); + $softParams['currency'] = $contribution->currency; + $softParams['amount'] = $contribution->total_amount; + $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp); + $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp); + $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp); + $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name'); + $contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($softParams); + //Send notification to owner for PCP + if ($contributionSoft->pcp_id && (empty($params['id']) || !empty($createSoft))) { + CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft); + } + } + $transaction->commit(); // check if activity record exist for this contribution, if -- 2.25.1