]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added User::singleUserNickname() as (temporary?) fallback for single-user lookup...
authorBrion Vibber <brion@pobox.com>
Mon, 6 Dec 2010 20:39:09 +0000 (12:39 -0800)
committerBrion Vibber <brion@pobox.com>
Mon, 6 Dec 2010 20:39:09 +0000 (12:39 -0800)
classes/User.php
lib/router.php
lib/util.php

index 964bc3e7f3b4f0ea48764f09a499ad69d3b4c037..c824ddb0c22f2e9c442b064ee0d953010c1c78be 100644 (file)
@@ -917,4 +917,36 @@ class User extends Memcached_DataObject
             throw new ServerException(_('Single-user mode code called when not enabled.'));
         }
     }
+
+    /**
+     * This is kind of a hack for using external setup code that's trying to
+     * build single-user sites.
+     *
+     * Will still return a username if the config singleuser/nickname is set
+     * even if the account doesn't exist, which normally indicates that the
+     * site is horribly misconfigured.
+     *
+     * At the moment, we need to let it through so that router setup can
+     * complete, otherwise we won't be able to create the account.
+     *
+     * This will be easier when we can more easily create the account and
+     * *then* switch the site to 1user mode without jumping through hoops.
+     *
+     * @return string
+     * @throws ServerException if no valid single user account is present
+     * @throws ServerException if called when not in single-user mode
+     */
+    static function singleUserNickname()
+    {
+        try {
+            $user = User::singleUser();
+            return $user->nickname;
+        } catch (Exception $e) {
+            if (common_config('singleuser', 'enabled') && common_config('singleuser', 'nickname')) {
+                common_log(LOG_WARN, "Warning: code attempting to pull single-user nickname when the account does not exist. If this is not setup time, this is probably a bug.");
+                return common_config('singleuser', 'nickname');
+            }
+            throw $e;
+        }
+    }
 }
index 7272a96904ba786d81977b1b49c9a3c88b4582df..2a908c7e03ab76df630a8e1ebb36c3f4922a16b1 100644 (file)
@@ -787,8 +787,7 @@ class Router
 
             if (common_config('singleuser', 'enabled')) {
 
-                $user = User::singleUser();
-                $nickname = $user->nickname;
+                $nickname = User::singleUserNickname();
 
                 foreach (array('subscriptions', 'subscribers',
                                'all', 'foaf', 'xrds',
index d50fa2081432246d91eab3f7c196b5a0c81ea443..a1ea1f24dd88ab6220328bd1578c5f191b232599 100644 (file)
@@ -975,9 +975,9 @@ function common_tag_link($tag)
     $canonical = common_canonical_tag($tag);
     if (common_config('singleuser', 'enabled')) {
         // regular TagAction isn't set up in 1user mode
-        $user = User::singleUser();
+        $nickname = User::singleUserNickname();
         $url = common_local_url('showstream',
-                                array('nickname' => $user->nickname,
+                                array('nickname' => $nickname,
                                       'tag' => $canonical));
     } else {
         $url = common_local_url('tag', array('tag' => $canonical));