From 430bd69312a27f9f97bda78566a78c9f7eec1f14 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 02:16:13 -0800 Subject: add events for subscribing to people and joining groups --- actions/joingroup.php | 16 ++++++---------- actions/leavegroup.php | 21 +++++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) (limited to 'actions') diff --git a/actions/joingroup.php b/actions/joingroup.php index 05e33e7cb..235e5ab4c 100644 --- a/actions/joingroup.php +++ b/actions/joingroup.php @@ -115,16 +115,12 @@ class JoingroupAction extends Action $cur = common_current_user(); - $member = new Group_member(); - - $member->group_id = $this->group->id; - $member->profile_id = $cur->id; - $member->created = common_sql_now(); - - $result = $member->insert(); - - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); + try { + if (Event::handle('StartJoinGroup', array($this->group, $cur))) { + Group_member::join($this->group->id, $cur->id); + Event::handle('EndJoinGroup', array($this->group, $cur)); + } + } catch (Exception $e) { $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $this->group->nickname)); } diff --git a/actions/leavegroup.php b/actions/leavegroup.php index b0f973e1a..9b9d83b6c 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -110,22 +110,15 @@ class LeavegroupAction extends Action $cur = common_current_user(); - $member = new Group_member(); - - $member->group_id = $this->group->id; - $member->profile_id = $cur->id; - - if (!$member->find(true)) { - $this->serverError(_('Could not find membership record.')); - return; - } - - $result = $member->delete(); - - if (!$result) { - common_log_db_error($member, 'DELETE', __FILE__); + try { + if (Event::handle('StartLeaveGroup', array($this->group, $cur))) { + Group_member::leave($this->group->id, $cur->id); + Event::handle('EndLeaveGroup', array($this->group, $cur)); + } + } catch (Exception $e) { $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $this->group->nickname)); + return; } if ($this->boolean('ajax')) { -- cgit v1.2.3-54-g00ecf From 601c3713320c0fe4c4d9f97b486d279bb6884de9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 03:01:22 -0800 Subject: correct check for error in subscribe and unsubscribe actions --- actions/subscribe.php | 2 +- actions/unsubscribe.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/subscribe.php b/actions/subscribe.php index 4c46806e4..a90d7facd 100644 --- a/actions/subscribe.php +++ b/actions/subscribe.php @@ -58,7 +58,7 @@ class SubscribeAction extends Action $result = subs_subscribe_to($user, $other); - if($result != true) { + if (is_string($result)) { $this->clientError($result); return; } diff --git a/actions/unsubscribe.php b/actions/unsubscribe.php index dbb4e4153..6bb10d448 100644 --- a/actions/unsubscribe.php +++ b/actions/unsubscribe.php @@ -87,7 +87,7 @@ class UnsubscribeAction extends Action $result = subs_unsubscribe_to($user, $other); - if ($result != true) { + if (is_string($result)) { $this->clientError($result); return; } -- cgit v1.2.3-54-g00ecf