From dcf73aab8af4f8a2a0a1d3b5da8b7390aeada21b Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 7 Jul 2015 12:37:12 +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 | 11 ++++++----- CRM/Contribute/Form/Contribution.php | 4 +--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index a4ab84a2a4..d46fb266a8 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -370,12 +370,8 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { // Handle soft credit and / or link to personal campaign page $softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id); - //Delete PCP against this contribution and create new on submitted PCP information $pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE); - if ($pcpId) { - $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; @@ -395,6 +391,11 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft); } } + //Delete PCP against this contribution and create new on submitted PCP information + elseif (array_key_exists('pcp', $params) && $pcpId) { + $deleteParams = array('id' => $pcpId); + CRM_Contribute_BAO_ContributionSoft::del($deleteParams); + } if (isset($params['soft_credit'])) { $softParams = $params['soft_credit']; diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index cc2376f24a..d37164e03d 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1202,9 +1202,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $params[$f] = CRM_Utils_Array::value($f, $formValues); } - if (!empty($pcp)) { - $params['pcp'] = $pcp; - } + $params['pcp'] = !empty($pcp) ? $pcp : NULL; if (!empty($softParams)) { $params['soft_credit'] = $softParams; $params['soft_credit_ids'] = $softIDs; -- 2.25.1