From 88123faced0e9f76096ee0d0204bb7e676da85be Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 7 Sep 2019 09:47:43 +1200 Subject: [PATCH] Respect calling code passing in 'null for creditnote_id. The credit note code was implemented in core quite a while ago, before we were really pushing these things out to extensions. It was implemented such that it iterates through all credit notes & has performance implications in order to meet a use case that is not common to all. Ideally we would move it to an extension, but short of that we can at least respect calling code setting the value to 'null' in order to override it. There is no precedent anywhere in our code for the BAO to deliberately override efforts by calling code to null out a value & in this case it solves a performance problem too Probably we should longer term simply have a hook hook::getCreditNoteID() & more this function to an extension called by that hook --- CRM/Contribute/BAO/Contribution.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 33a350ef6a..3596da0327 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -155,7 +155,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { if (($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) ) { - if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") { + if (empty($params['creditnote_id'])) { $params['creditnote_id'] = self::createCreditNoteId(); } } @@ -1125,7 +1125,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $isARefund = TRUE; // @todo we should stop passing $params by reference - splitting this out would be a step towards that. $params['trxnParams']['total_amount'] = -$params['total_amount']; - if (empty($params['contribution']->creditnote_id) || $params['contribution']->creditnote_id == "null") { + if (empty($params['contribution']->creditnote_id)) { $creditNoteId = self::createCreditNoteId(); CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId); } @@ -1140,7 +1140,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { // @todo we should stop passing $params by reference - splitting this out would be a step towards that. $params['trxnParams']['to_financial_account_id'] = $arAccountId; $params['trxnParams']['total_amount'] = -$params['total_amount']; - if (is_null($params['contribution']->creditnote_id) || $params['contribution']->creditnote_id == "null") { + if (empty($params['contribution']->creditnote_id)) { $creditNoteId = self::createCreditNoteId(); CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId); } -- 2.25.1