summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorSarven Capadisli <csarven@status.net>2010-01-31 23:42:19 +0100
committerSarven Capadisli <csarven@status.net>2010-01-31 23:42:19 +0100
commit7558e2fd61c527b31b5a49d29a59b6b0b1d6d542 (patch)
tree4f71863c12f8b20b261dad09496f65ca872f5712 /classes
parent4d0ee6a41f3cfb2e99dcb92e7b14f3183393f1a5 (diff)
parent81087e45c5b797028e90181459e4c673cd7be278 (diff)
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'classes')
-rw-r--r--classes/Memcached_DataObject.php26
-rw-r--r--classes/Notice.php2
-rw-r--r--classes/Profile_role.php1
-rw-r--r--classes/User.php197
-rw-r--r--classes/status_network.ini1
5 files changed, 144 insertions, 83 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index f4dfe6314..ab65c30ce 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -552,4 +552,30 @@ class Memcached_DataObject extends DB_DataObject
{
throw new ServerException("DB_DataObject error [$type]: $message");
}
+
+ static function cacheGet($keyPart)
+ {
+ $c = self::memcache();
+
+ if (empty($c)) {
+ return false;
+ }
+
+ $cacheKey = common_cache_key($keyPart);
+
+ return $c->get($cacheKey);
+ }
+
+ static function cacheSet($keyPart, $value)
+ {
+ $c = self::memcache();
+
+ if (empty($c)) {
+ return false;
+ }
+
+ $cacheKey = common_cache_key($keyPart);
+
+ return $c->set($cacheKey, $value);
+ }
}
diff --git a/classes/Notice.php b/classes/Notice.php
index a60dd5bcd..42878d94f 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -140,7 +140,7 @@ class Notice extends Memcached_DataObject
foreach(array_unique($hashtags) as $hashtag) {
/* elide characters we don't want in the tag */
$this->saveTag($hashtag);
- self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, $tag->tag);
+ self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, $hashtag);
}
return true;
}
diff --git a/classes/Profile_role.php b/classes/Profile_role.php
index 74aca3730..bf2c453ed 100644
--- a/classes/Profile_role.php
+++ b/classes/Profile_role.php
@@ -48,6 +48,7 @@ class Profile_role extends Memcached_DataObject
return Memcached_DataObject::pkeyGet('Profile_role', $kv);
}
+ const OWNER = 'owner';
const MODERATOR = 'moderator';
const ADMINISTRATOR = 'administrator';
const SANDBOXED = 'sandboxed';
diff --git a/classes/User.php b/classes/User.php
index 6ea975202..022044aac 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -209,8 +209,6 @@ class User extends Memcached_DataObject
$profile = new Profile();
- $profile->query('BEGIN');
-
if(!empty($email))
{
$email = common_canonical_email($email);
@@ -220,7 +218,7 @@ class User extends Memcached_DataObject
$profile->nickname = $nickname;
if(! User::allowed_nickname($nickname)){
common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
- __FILE__);
+ __FILE__);
}
$profile->profileurl = common_profile_url($nickname);
@@ -248,16 +246,8 @@ class User extends Memcached_DataObject
$profile->created = common_sql_now();
- $id = $profile->insert();
-
- if (empty($id)) {
- common_log_db_error($profile, 'INSERT', __FILE__);
- return false;
- }
-
$user = new User();
- $user->id = $id;
$user->nickname = $nickname;
if (!empty($password)) { // may not have a password for OpenID users
@@ -282,109 +272,126 @@ class User extends Memcached_DataObject
$user->inboxed = 1;
$user->created = common_sql_now();
- $user->uri = common_user_uri($user);
- $result = $user->insert();
+ if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
- if (!$result) {
- common_log_db_error($user, 'INSERT', __FILE__);
- return false;
- }
+ $profile->query('BEGIN');
- // Everyone gets an inbox
+ $id = $profile->insert();
- $inbox = new Inbox();
-
- $inbox->user_id = $user->id;
- $inbox->notice_ids = '';
-
- $result = $inbox->insert();
+ if (empty($id)) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ return false;
+ }
- if (!$result) {
- common_log_db_error($inbox, 'INSERT', __FILE__);
- return false;
- }
+ $user->id = $id;
+ $user->uri = common_user_uri($user);
- // Everyone is subscribed to themself
+ $result = $user->insert();
- $subscription = new Subscription();
- $subscription->subscriber = $user->id;
- $subscription->subscribed = $user->id;
- $subscription->created = $user->created;
+ if (!$result) {
+ common_log_db_error($user, 'INSERT', __FILE__);
+ return false;
+ }
- $result = $subscription->insert();
+ // Everyone gets an inbox
- if (!$result) {
- common_log_db_error($subscription, 'INSERT', __FILE__);
- return false;
- }
+ $inbox = new Inbox();
- if (!empty($email) && !$user->email) {
+ $inbox->user_id = $user->id;
+ $inbox->notice_ids = '';
- $confirm = new Confirm_address();
- $confirm->code = common_confirmation_code(128);
- $confirm->user_id = $user->id;
- $confirm->address = $email;
- $confirm->address_type = 'email';
+ $result = $inbox->insert();
- $result = $confirm->insert();
if (!$result) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_log_db_error($inbox, 'INSERT', __FILE__);
return false;
}
- }
- if (!empty($code) && $user->email) {
- $user->emailChanged();
- }
+ // Everyone is subscribed to themself
- // Default system subscription
+ $subscription = new Subscription();
+ $subscription->subscriber = $user->id;
+ $subscription->subscribed = $user->id;
+ $subscription->created = $user->created;
- $defnick = common_config('newuser', 'default');
+ $result = $subscription->insert();
- if (!empty($defnick)) {
- $defuser = User::staticGet('nickname', $defnick);
- if (empty($defuser)) {
- common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
- __FILE__);
- } else {
- $defsub = new Subscription();
- $defsub->subscriber = $user->id;
- $defsub->subscribed = $defuser->id;
- $defsub->created = $user->created;
+ if (!$result) {
+ common_log_db_error($subscription, 'INSERT', __FILE__);
+ return false;
+ }
- $result = $defsub->insert();
+ if (!empty($email) && !$user->email) {
+
+ $confirm = new Confirm_address();
+ $confirm->code = common_confirmation_code(128);
+ $confirm->user_id = $user->id;
+ $confirm->address = $email;
+ $confirm->address_type = 'email';
+
+ $result = $confirm->insert();
if (!$result) {
- common_log_db_error($defsub, 'INSERT', __FILE__);
+ common_log_db_error($confirm, 'INSERT', __FILE__);
return false;
}
}
- }
- $profile->query('COMMIT');
+ if (!empty($code) && $user->email) {
+ $user->emailChanged();
+ }
- if (!empty($email) && !$user->email) {
- mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
- }
+ // Default system subscription
- // Welcome message
+ $defnick = common_config('newuser', 'default');
- $welcome = common_config('newuser', 'welcome');
+ if (!empty($defnick)) {
+ $defuser = User::staticGet('nickname', $defnick);
+ if (empty($defuser)) {
+ common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
+ __FILE__);
+ } else {
+ $defsub = new Subscription();
+ $defsub->subscriber = $user->id;
+ $defsub->subscribed = $defuser->id;
+ $defsub->created = $user->created;
- if (!empty($welcome)) {
- $welcomeuser = User::staticGet('nickname', $welcome);
- if (empty($welcomeuser)) {
- common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
- __FILE__);
- } else {
- $notice = Notice::saveNew($welcomeuser->id,
- sprintf(_('Welcome to %1$s, @%2$s!'),
- common_config('site', 'name'),
- $user->nickname),
- 'system');
+ $result = $defsub->insert();
+
+ if (!$result) {
+ common_log_db_error($defsub, 'INSERT', __FILE__);
+ return false;
+ }
+ }
+ }
+
+ $profile->query('COMMIT');
+ if (!empty($email) && !$user->email) {
+ mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+ }
+
+ // Welcome message
+
+ $welcome = common_config('newuser', 'welcome');
+
+ if (!empty($welcome)) {
+ $welcomeuser = User::staticGet('nickname', $welcome);
+ if (empty($welcomeuser)) {
+ common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
+ __FILE__);
+ } else {
+ $notice = Notice::saveNew($welcomeuser->id,
+ sprintf(_('Welcome to %1$s, @%2$s!'),
+ common_config('site', 'name'),
+ $user->nickname),
+ 'system');
+
+ }
}
+
+ Event::handle('EndUserRegister', array(&$profile, &$user));
}
return $user;
@@ -925,4 +932,30 @@ class User extends Memcached_DataObject
return $share;
}
}
+
+ static function siteOwner()
+ {
+ $owner = self::cacheGet('user:site_owner');
+
+ if ($owner === false) { // cache miss
+
+ $pr = new Profile_role();
+
+ $pr->role = Profile_role::OWNER;
+
+ $pr->orderBy('created');
+
+ $pr->limit(0, 1);
+
+ if ($pr->fetch($true)) {
+ $owner = User::staticGet('id', $pr->profile_id);
+ } else {
+ $owner = null;
+ }
+
+ self::cacheSet('user:site_owner', $owner);
+ }
+
+ return $owner;
+ }
}
diff --git a/classes/status_network.ini b/classes/status_network.ini
index 8123265e4..adb71cba7 100644
--- a/classes/status_network.ini
+++ b/classes/status_network.ini
@@ -11,6 +11,7 @@ theme = 2
logo = 2
created = 142
modified = 384
+tags = 34
[status_network__keys]
nickname = K