diff options
author | Brion Vibber <brion@pobox.com> | 2010-03-22 13:56:16 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-03-22 13:56:16 -0700 |
commit | e89908f26140c217e01b2f8f755712f38f3935f3 (patch) | |
tree | 6b241fc2e33f3528cf48b415ef67906826b02e24 /classes/Subscription.php | |
parent | 714d920faea302b55857cc3bec4e9e6160ea136a (diff) | |
parent | eb563937df921e5fc67ca0c87e229feb2907fd19 (diff) |
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 1.0.x
Conflicts:
lib/channel.php
scripts/imdaemon.php
Diffstat (limited to 'classes/Subscription.php')
-rw-r--r-- | classes/Subscription.php | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/classes/Subscription.php b/classes/Subscription.php index 9cef2df1a..0679c0925 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -62,6 +62,14 @@ class Subscription extends Memcached_DataObject static function start($subscriber, $other) { + // @fixme should we enforce this as profiles in callers instead? + if ($subscriber instanceof User) { + $subscriber = $subscriber->getProfile(); + } + if ($other instanceof User) { + $other = $other->getProfile(); + } + if (!$subscriber->hasRight(Right::SUBSCRIBE)) { throw new Exception(_('You have been banned from subscribing.')); } @@ -75,26 +83,13 @@ class Subscription extends Memcached_DataObject } if (Event::handle('StartSubscribe', array($subscriber, $other))) { - - $sub = new Subscription(); - - $sub->subscriber = $subscriber->id; - $sub->subscribed = $other->id; - $sub->created = common_sql_now(); - - $result = $sub->insert(); - - if (!$result) { - common_log_db_error($sub, 'INSERT', __FILE__); - throw new Exception(_('Could not save subscription.')); - } - + $sub = self::saveNew($subscriber->id, $other->id); $sub->notify(); self::blow('user:notices_with_friends:%d', $subscriber->id); - $subscriber->blowSubscriptionsCount(); - $other->blowSubscribersCount(); + $subscriber->blowSubscriptionCount(); + $other->blowSubscriberCount(); $otherUser = User::staticGet('id', $other->id); @@ -103,20 +98,11 @@ class Subscription extends Memcached_DataObject !self::exists($other, $subscriber) && !$subscriber->hasBlocked($other)) { - $auto = new Subscription(); - - $auto->subscriber = $subscriber->id; - $auto->subscribed = $other->id; - $auto->created = common_sql_now(); - - $result = $auto->insert(); - - if (!$result) { - common_log_db_error($auto, 'INSERT', __FILE__); - throw new Exception(_('Could not save subscription.')); + try { + self::start($other, $subscriber); + } catch (Exception $e) { + common_log(LOG_ERR, "Exception during autosubscribe of {$other->nickname} to profile {$subscriber->id}: {$e->getMessage()}"); } - - $auto->notify(); } Event::handle('EndSubscribe', array($subscriber, $other)); @@ -125,6 +111,30 @@ class Subscription extends Memcached_DataObject return true; } + /** + * Low-level subscription save. + * Outside callers should use Subscription::start() + */ + protected function saveNew($subscriber_id, $other_id) + { + $sub = new Subscription(); + + $sub->subscriber = $subscriber_id; + $sub->subscribed = $other_id; + $sub->jabber = 1; + $sub->sms = 1; + $sub->created = common_sql_now(); + + $result = $sub->insert(); + + if (!$result) { + common_log_db_error($sub, 'INSERT', __FILE__); + throw new Exception(_('Could not save subscription.')); + } + + return $sub; + } + function notify() { # XXX: add other notifications (Jabber, SMS) here @@ -203,8 +213,8 @@ class Subscription extends Memcached_DataObject self::blow('user:notices_with_friends:%d', $subscriber->id); - $subscriber->blowSubscriptionsCount(); - $other->blowSubscribersCount(); + $subscriber->blowSubscriptionCount(); + $other->blowSubscriberCount(); Event::handle('EndUnsubscribe', array($subscriber, $other)); } |