summaryrefslogtreecommitdiff
path: root/classes/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/User.php')
-rw-r--r--classes/User.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/classes/User.php b/classes/User.php
index e784fd9e9..f381ec607 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -875,4 +875,35 @@ class User extends Memcached_DataObject
return $owner;
}
+
+ /**
+ * Pull the primary site account to use in single-user mode.
+ * If a valid user nickname is listed in 'singleuser':'nickname'
+ * in the config, this will be used; otherwise the site owner
+ * account is taken by default.
+ *
+ * @return User
+ * @throws ServerException if no valid single user account is present
+ * @throws ServerException if called when not in single-user mode
+ */
+ static function singleUser()
+ {
+ if (common_config('singleuser', 'enabled')) {
+ $nickname = common_config('singleuser', 'nickname');
+ if ($nickname) {
+ $user = User::staticGet('nickname', $nickname);
+ } else {
+ $user = User::siteOwner();
+ }
+ if ($user) {
+ return $user;
+ } else {
+ // TRANS: Server exception.
+ throw new ServerException(_('No single user defined for single-user mode.'));
+ }
+ } else {
+ // TRANS: Server exception.
+ throw new ServerException(_('Single-user mode code called when not enabled.'));
+ }
+ }
}