summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-20 14:34:25 -0700
committerBrion Vibber <brion@pobox.com>2010-10-20 14:34:25 -0700
commit8004e2809d98bdd535a3c59bd7d15c3fa2dd7ba9 (patch)
tree177994041c35b5910d0227de6e64e8ff5c7667cc /classes
parent75ebf3c34844dbba0eb229d0c7d0d618118ce1ab (diff)
Fix for ticket #2845: singleuser nickname configuration was being overridden by site owner in router setup.
I've consolidated the checks for which user to use for single-user mode into User::singleUser(), which now uses the configured nickname by preference, falling back to the site owner if it's unset. This is now called consistently from the places that needed to use the primary user's nickname in routing setup. Setting $config['singleuser']['nickname'] should now work again as expected.
Diffstat (limited to 'classes')
-rw-r--r--classes/User.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/classes/User.php b/classes/User.php
index e784fd9e9..c68be223d 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -875,4 +875,33 @@ 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 {
+ throw new ServerException(_("No single user defined for single-user mode."));
+ }
+ } else {
+ throw new ServerException(_('Single-user mode code called when not enabled.'));
+ }
+ }
}