git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 76f3dc32 authored by Brion Vibber's avatar Brion Vibber

Added User::singleUserNickname() as (temporary?) fallback for single-user...

Added User::singleUserNickname() as (temporary?) fallback for single-user lookup as a workaround for site setup of 1user sites. We found that an external tool attempting to spin up StatusNet and then register the user would fail because StatusNet's router setup dies on being unable to find its single-user account, since the nickname is needed in setting up routing entries. This tweak will let it survive, using the configured setting as a fallback if it can't actually find the user account.
parent b4fc54c3
...@@ -917,4 +917,36 @@ class User extends Memcached_DataObject ...@@ -917,4 +917,36 @@ class User extends Memcached_DataObject
throw new ServerException(_('Single-user mode code called when not enabled.')); 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;
}
}
} }
...@@ -787,8 +787,7 @@ class Router ...@@ -787,8 +787,7 @@ class Router
if (common_config('singleuser', 'enabled')) { if (common_config('singleuser', 'enabled')) {
$user = User::singleUser(); $nickname = User::singleUserNickname();
$nickname = $user->nickname;
foreach (array('subscriptions', 'subscribers', foreach (array('subscriptions', 'subscribers',
'all', 'foaf', 'xrds', 'all', 'foaf', 'xrds',
......
...@@ -975,9 +975,9 @@ function common_tag_link($tag) ...@@ -975,9 +975,9 @@ function common_tag_link($tag)
$canonical = common_canonical_tag($tag); $canonical = common_canonical_tag($tag);
if (common_config('singleuser', 'enabled')) { if (common_config('singleuser', 'enabled')) {
// regular TagAction isn't set up in 1user mode // regular TagAction isn't set up in 1user mode
$user = User::singleUser(); $nickname = User::singleUserNickname();
$url = common_local_url('showstream', $url = common_local_url('showstream',
array('nickname' => $user->nickname, array('nickname' => $nickname,
'tag' => $canonical)); 'tag' => $canonical));
} else { } else {
$url = common_local_url('tag', array('tag' => $canonical)); $url = common_local_url('tag', array('tag' => $canonical));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment