From: Eileen McNaughton <emcnaughton@wikimedia.org> Date: Sun, 19 Mar 2023 00:46:47 +0000 (+1300) Subject: Switch out the switch X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5b4d543fe3d06309d444534f3ee8988ffd9758de;p=civicrm-core.git Switch out the switch --- diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index e85444c370..fcbc856caf 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -533,60 +533,50 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { private function deprecatedFormatParams($params, &$values, $create = FALSE): void { // copy all the contribution fields as is require_once 'api/v3/utils.php'; - - foreach ($params as $key => $value) { - // ignore empty values or empty arrays etc - if (CRM_Utils_System::isNull($value)) { - continue; + if (empty($params['pledge_id'])) { + return; + } + // get total amount of from import fields + $totalAmount = $params['total_amount'] ?? NULL; + $contributionContactID = $params['contact_id']; + // we need to get contact id $contributionContactID to + // retrieve pledge details as well as to validate pledge ID + + // first need to check for update mode + if (!empty($params['id'])) { + $contribution = new CRM_Contribute_DAO_Contribution(); + if ($params['id']) { + $contribution->id = $params['id']; } - switch ($key) { - - case 'pledge_id': - // get total amount of from import fields - $totalAmount = $params['total_amount'] ?? NULL; - $contributionContactID = $params['contact_id']; - // we need to get contact id $contributionContactID to - // retrieve pledge details as well as to validate pledge ID - - // first need to check for update mode - if (!empty($params['id'])) { - $contribution = new CRM_Contribute_DAO_Contribution(); - if ($params['id']) { - $contribution->id = $params['id']; - } - - if ($contribution->find(TRUE)) { - if (!$totalAmount) { - $totalAmount = $contribution->total_amount; - } - } - else { - throw new CRM_Core_Exception('No match found for specified contact in pledge payment data. Row was skipped.', CRM_Import_Parser::ERROR); - } - } - - if (!empty($params['pledge_id'])) { - if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) { - throw new CRM_Core_Exception('Invalid Pledge ID provided. Contribution row was skipped.', CRM_Import_Parser::ERROR); - } - $values['pledge_id'] = $params['pledge_id']; - } - - // we need to check if oldest payment amount equal to contribution amount - require_once 'CRM/Pledge/BAO/PledgePayment.php'; - $pledgePaymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($values['pledge_id']); - - if ($pledgePaymentDetails['amount'] == $totalAmount) { - $values['pledge_payment_id'] = $pledgePaymentDetails['id']; - } - else { - throw new CRM_Core_Exception('Contribution and Pledge Payment amount mismatch for this record. Contribution row was skipped.', CRM_Import_Parser::ERROR); - } - break; + if ($contribution->find(TRUE)) { + if (!$totalAmount) { + $totalAmount = $contribution->total_amount; + } + } + else { + throw new CRM_Core_Exception('No match found for specified contact in pledge payment data. Row was skipped.', CRM_Import_Parser::ERROR); + } + } + if (!empty($params['pledge_id'])) { + if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) { + throw new CRM_Core_Exception('Invalid Pledge ID provided. Contribution row was skipped.', CRM_Import_Parser::ERROR); } + $values['pledge_id'] = $params['pledge_id']; } + + // we need to check if oldest payment amount equal to contribution amount + require_once 'CRM/Pledge/BAO/PledgePayment.php'; + $pledgePaymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($values['pledge_id']); + + if ($pledgePaymentDetails['amount'] == $totalAmount) { + $values['pledge_payment_id'] = $pledgePaymentDetails['id']; + } + else { + throw new CRM_Core_Exception('Contribution and Pledge Payment amount mismatch for this record. Contribution row was skipped.', CRM_Import_Parser::ERROR); + } + } /**