From bbdd11238a9d927f20ebf992c0d92e10d5515fb2 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Wed, 15 Jul 2015 12:01:47 +0530 Subject: [PATCH] CRM-16804 fix - Contribution updated via api wrongfully deletes PCP soft contribution https://issues.civicrm.org/jira/browse/CRM-16804 --- CRM/Contribute/BAO/Contribution.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d46fb266a8..9062f5c735 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -374,6 +374,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { if ($pcp = CRM_Utils_Array::value('pcp', $params)) { $softParams = array(); + $softParams['id'] = $pcpId ? $pcpId : NULL; $softParams['contribution_id'] = $contribution->id; $softParams['pcp_id'] = $pcp['pcp_made_through_id']; $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', @@ -398,17 +399,12 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } if (isset($params['soft_credit'])) { $softParams = $params['soft_credit']; - - if (!empty($softIDs)) { - foreach ($softIDs as $softID) { - if (!in_array($softID, $params['soft_credit_ids'])) { - $deleteParams = array('id' => $softID); - CRM_Contribute_BAO_ContributionSoft::del($deleteParams); - } - } - } - foreach ($softParams as $softParam) { + if (!empty($softIDs)) { + $key = key($softIDs); + $softParam['id'] = $softIDs[$key]; + unset($softIDs[$key]); + } $softParam['contribution_id'] = $contribution->id; $softParam['currency'] = $contribution->currency; //case during Contribution Import when we assign soft contribution amount as contribution's total_amount by default @@ -417,6 +413,15 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } CRM_Contribute_BAO_ContributionSoft::add($softParam); } + + if (!empty($softIDs)) { + foreach ($softIDs as $softID) { + if (!in_array($softID, $params['soft_credit_ids'])) { + $deleteParams = array('id' => $softID); + CRM_Contribute_BAO_ContributionSoft::del($deleteParams); + } + } + } } $transaction->commit(); -- 2.25.1