From 46a19be70eddce5cbe9766efff8a958e09f11c98 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 21 Dec 2021 02:32:11 -0800 Subject: [PATCH] Drupal8::getUfId() - Fix exception on unknown usernames As mentioned in https://github.com/civicrm/civicrm-core/pull/22239#issuecomment-997108926, there can be an exception: ``` Error: Call to a member function id() on bool in ...\CRM\Utils\System\Drupal8.php on line 359 #0 ...\ext\authx\Civi\Authx\Authenticator.php(380) ``` The function signature specifies `@return int|null`. Various callers appear to expect this, and that seems to be how it behaves on D7/WP. --- CRM/Utils/System/Drupal8.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 3037cec10a..52dac70a3b 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -356,7 +356,8 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { * @return int|null */ public function getUfId($username) { - if ($id = user_load_by_name($username)->id()) { + $user = user_load_by_name($username); + if ($user && $id = $user->id()) { return $id; } } -- 2.25.1