From f93143f1b80f1f09809d31f2acb025727b9c7a76 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Fri, 3 Feb 2023 12:45:33 +0000 Subject: [PATCH] standalone: tentatively implement some CRM_Utils_System_Standalone methods --- CRM/Utils/System/Standalone.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/CRM/Utils/System/Standalone.php b/CRM/Utils/System/Standalone.php index e0148238e3..f08bb52125 100644 --- a/CRM/Utils/System/Standalone.php +++ b/CRM/Utils/System/Standalone.php @@ -165,21 +165,36 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { /** * @inheritDoc + * + * Note that the parent signature in the docblock says object, but we use a string username for stanalone. + * + * @todo I (artfulrobot) am unclear what this is really needed for/expected to do. */ public function loadUser($username) { - // @todo - throw new \RuntimeException("Standalone loadUser not written yet!"); + $user = \Civi\Api4\User::get(FALSE) + ->addWhere('username', '=', $username) + ->execute() + ->single(); + + // Do we do something like this?: + // CRM_Core_Session::singleton()->set('userID', $user['id']); + // (but we'd need to clear the session etc. and probably use a special method for this? + // or maybe this IS the special method for that?) } /** - * Determine the native ID of the CMS user. + * Determine the CMS-native ID from the user name + * + * In standalone this means the User ID. * * @param string $username * @return int|null */ public function getUfId($username) { - // @todo - throw new \RuntimeException("Standalone getUfId not written yet!"); + return \Civi\Api4\User::get(FALSE) + ->addWhere('username', '=', $username) + ->execute() + ->single()['id']; } /** -- 2.25.1