standalone: tentatively implement some CRM_Utils_System_Standalone methods
authorRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Fri, 3 Feb 2023 12:45:33 +0000 (12:45 +0000)
committerRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Fri, 23 Jun 2023 10:47:57 +0000 (11:47 +0100)
CRM/Utils/System/Standalone.php

index e0148238e35f10d41100cb7905dc374ecb975560..f08bb5212567a2cbee4f5bbdf827919307a33922 100644 (file)
@@ -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'];
   }
 
   /**