Skip to content

Commit

Permalink
Revert "Remove unreachable code lines."
Browse files Browse the repository at this point in the history
In the course of civicrm#16462
I concluded that there might be (untested scenarios) where this would still be hit.

In civicrm#16462 I adopted a cleaner (tested) approach. However, I think it's unlikely that
will be merged before 5.23 is cut so I propose reverting this change & re-reverting it
once the rc is cut as a more conservative approach. We can focus on getting civicrm#16462
wrapped up for 5.24

This reverts commit d7943ca.
  • Loading branch information
eileenmcnaughton committed Feb 5, 2020
1 parent 3f4b536 commit 95f7b3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,12 @@ private static function updateFinancialAccountsOnContributionStatusChange(&$para
if (self::isContributionUpdateARefund($params['prevContribution']->contribution_status_id, $params['contribution']->contribution_status_id)) {
// @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)) {
// This is always set in the Contribution::create function.
CRM_Core_Error::deprecatedFunctionWarning('Logic says this line is never reached & can be removed');
$creditNoteId = self::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
}
}
elseif (($previousContributionStatus == 'Pending'
&& $params['prevContribution']->is_pay_later) || $previousContributionStatus == 'In Progress'
Expand All @@ -1118,6 +1124,12 @@ private static function updateFinancialAccountsOnContributionStatusChange(&$para
// @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 (empty($params['contribution']->creditnote_id)) {
// This is always set in the Contribution::create function.
CRM_Core_Error::deprecatedFunctionWarning('Logic says this line is never reached & can be removed');
$creditNoteId = self::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
}
}
else {
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
Expand Down
9 changes: 8 additions & 1 deletion CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,14 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
}

if ($contribution->contribution_status_id == $refundedStatusId || $contribution->contribution_status_id == $cancelledStatusId) {
$creditNoteId = $contribution->creditnote_id;
if (is_null($contribution->creditnote_id)) {
CRM_Core_Error::deprecatedFunctionWarning('This it the wrong place to add a credit note id since the id is added when the status is changed in the Contribution::Create function- hopefully it is never hit');
$creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'creditnote_id', $creditNoteId);
}
else {
$creditNoteId = $contribution->creditnote_id;
}
}
if (!$contribution->invoice_number) {
$contribution->invoice_number = CRM_Contribute_BAO_Contribution::getInvoiceNumber($contribution->id);
Expand Down

0 comments on commit 95f7b3a

Please sign in to comment.