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

Deprecate duplicate getLoggedInContactID() function #20321

Merged
merged 1 commit into from
Jul 5, 2021

Conversation

mattwire
Copy link
Contributor

Overview

CRM_Core_Form::getLoggedInUserContactID() is doing virtually the same thing as CRM_Core_Session::getLoggedInContactD() but is only used in 3 places. Deprecate it and use the function on the session class.

Before

"Duplicate" function.

After

Use standard function

Technical Details

Only change here is that we explicitly return an int which the contact ID should always be..

Comments

@civibot
Copy link

civibot bot commented May 17, 2021

(Standard links)

@civibot civibot bot added the master label May 17, 2021
@@ -2243,7 +2243,7 @@ protected function setContactID() {
return (int) $tempID;
}

$userID = $this->getLoggedInUserContactID();
$userID = CRM_Core_Session::getLoggedInContactID();

if (!is_null($tempID) && $tempID === $userID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The only difference I can see is that we are changing from a function that returns FALSE to one that returns NULL. So this is_null check maybe needs to become is false (I'm struggling a bit to figure out what it achieves. I know that 0 and potentially '0' are valid / meaningful in this function but I'm not sure the meaning of FALSE - ie could $tempID ever be FALSE & what would that mean)

Copy link
Member

@monishdeb monishdeb May 31, 2021

Choose a reason for hiding this comment

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

May be if CRM_Core_Session::getLoggedInContactID return int|null

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 In this case $tempID is set by CRM_Utils_Request::retrieve and will be NULL if not found. It then may be set via ['select_contact_id'] but only if that is not empty (so not NULL). So the is_null check never changes because $tempID is never set by getLoggedInContactID()

When we do the $tempID === $userID we already checked that $tempID is not null (via !is_null()) so we don't need to worry what the value of $userID is - if it is NULL or FALSE it won't match because we know that $tempID is not NULL and it cannot be set to FALSE in the function

@mattwire
Copy link
Contributor Author

mattwire commented Jun 1, 2021

@eileenmcnaughton @monishdeb Thanks - I've responded to questions

@mattwire
Copy link
Contributor Author

mattwire commented Jul 5, 2021

@monishdeb Happy with this now?

@monishdeb
Copy link
Member

Yep and sorry for the delay. Tested again in local, looks good. Merging now.

@monishdeb monishdeb merged commit 68e1895 into civicrm:master Jul 5, 2021
@mattwire
Copy link
Contributor Author

mattwire commented Jul 5, 2021

Thankyou :-)

@mattwire mattwire deleted the loggedincontactid branch July 5, 2021 11:14
stesi561 added a commit to fuzionnz/nz.co.fuzion.transactional that referenced this pull request Nov 11, 2021
This replaces as per civicrm/civicrm-core#20321
Note the replacement function can return NULL.
It seems like the code that retrieves the value already handles this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants