Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CRM_Utils_Array::value in contribution/confirm and bao/membership #18157

Merged

Conversation

mattwire
Copy link
Contributor

Overview

Simple replace of deprecated function - helps make code more readable for further changes.

Before

Lot's of uses of CRM_Utils_Array::value

After

No uses

Technical Details

There are almost certainly further simplifications in some cases. In most cases I've just replaced with ?? NULL where there was no default.

Comments

@civibot
Copy link

civibot bot commented Aug 15, 2020

(Standard links)

@civibot civibot bot added the master label Aug 15, 2020
Comment on lines -1540 to +1549
$pending = $this->getIsPending();
// The concept of contributeMode is deprecated.
// the is_monetary concept probably should be too as it can be calculated from
// the existence of 'amount' & seems fragile.
if (((isset($this->_contributeMode)) || !empty($this->_params['is_pay_later'])
) &&
(($this->_values['is_monetary'] && $this->_amount > 0.0))
) {
$pending = TRUE;
}
$pending = FALSE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only used here. We want to move it to BAO/membership but first step is remove function and put inline so you can see what it is doing.
This is the only bit that is not replacing CRM_Utils_Array::value

list($membership, $renewalMode, $dates) = CRM_Member_BAO_Membership::processMembership(
$contactID, $memType, $isTest,
date('YmdHis'), CRM_Utils_Array::value('cms_contactID', $membershipParams),
date('YmdHis'), $membershipParams['cms_contactID'] ?? NULL,
$customFieldsFormatted,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton cms_contactID would be a good variable to eliminate in a future PR because it is only used in very few circumstances and is almost certainly available via other parameters.

@colemanw
Copy link
Member

I've reviewed the code & am happy with this if tests pass.

@mattwire mattwire force-pushed the utilsarraycontributionmembership branch from 556c8a3 to b92c6ce Compare August 15, 2020 14:46
@@ -155,19 +155,19 @@ public static function getContributionParams(
$paymentProcessorOutcome, $receiptDate, $recurringContributionID) {
$contributionParams = [
'financial_type_id' => $financialTypeID,
'receive_date' => (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
'receive_date' => isset($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for $params['receive_date'] to be the empty string? If so then this now evaluates to null instead of today's date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy My understanding of CRM_Utils_Array::value was that it would return the value of receive_date if set otherwise NULL. So I don't think this line changes anything?

Copy link
Contributor

@demeritcowboy demeritcowboy Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's what it does but consider when $params['receive_date'] = "";

It's also checkable with cv:

cv ev "$params['receive_date'] = ''; $result = (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'); var_dump($result);"

vs

cv ev "$params['receive_date'] = ''; $result = isset($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'); var_dump($result);"

The difference would also come up if $params['receive_date'] = 0; or $params['receive_date'] = FALSE;, but that seems much less likely to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now. I'll update the PR :-)

@@ -887,7 +887,7 @@ public static function processFormContribution(

$isEmailReceipt = !empty($form->_values['is_email_receipt']);
$isSeparateMembershipPayment = !empty($params['separate_membership_payment']);
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : CRM_Utils_Array::value('pledge_id', $form->_values);
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : $form->_values['pledge_id'] ?? NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns out to be ok no matter which has precedence, just might be slightly clearer with brackets around the last clause, i.e. ($form->_values['pledge_id'] ?? NULL)

@@ -2398,7 +2394,7 @@ public static function recordMembershipContribution(&$params) {
$contributionParams = [];
$config = CRM_Core_Config::singleton();
$contributionParams['currency'] = $config->defaultCurrency;
$contributionParams['receipt_date'] = (CRM_Utils_Array::value('receipt_date', $params)) ? $params['receipt_date'] : 'null';
$contributionParams['receipt_date'] = isset($params['receipt_date']) ? $params['receipt_date'] : 'null';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as earlier if it's possible to be the empty string.

@eileenmcnaughton
Copy link
Contributor

related fail

@eileenmcnaughton
Copy link
Contributor

(style)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants