]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' into inline-comments
authorBrion Vibber <brion@pobox.com>
Tue, 1 Mar 2011 00:48:05 +0000 (16:48 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 1 Mar 2011 00:48:05 +0000 (16:48 -0800)
actions/apigroupjoin.php
actions/apigroupleave.php
actions/joingroup.php

index 345fed2215e7587d582a46605f2df578fd9c2721..2e35cb87de364636e247e95953507703bc7f8069 100644 (file)
@@ -125,26 +125,17 @@ class ApiGroupJoinAction extends ApiAuthAction
             return;
         }
 
-        $member = new Group_member();
-
-        $member->group_id   = $this->group->id;
-        $member->profile_id = $this->user->id;
-        $member->created    = common_sql_now();
-
-        $result = $member->insert();
-
-        if (!$result) {
-            common_log_db_error($member, 'INSERT', __FILE__);
-            $this->serverError(
-                sprintf(
-                    // TRANS: Server error displayed when joining a group fails.
-                    // TRANS: %1$s is a user nickname, $2$s is a group nickname.
-                    _('Could not join user %1$s to group %2$s.'),
-                    $this->user->nickname,
-                    $this->group->nickname
-                )
-            );
-            return;
+        try {
+            if (Event::handle('StartJoinGroup', array($this->group, $this->user))) {
+                Group_member::join($this->group->id, $this->user->id);
+                Event::handle('EndJoinGroup', array($this->group, $this->user));
+            }
+        } catch (Exception $e) {
+            // TRANS: Server error displayed when joining a group failed in the database.
+            // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
+            $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
+                                       $cur->nickname, $this->group->nickname));
+                       return;
         }
 
         switch($this->format) {
index 0ceb3523c8483a95f6f45dc1a31a9a4a8d755175..083ebd890f2c0b38e85e4f927b95e120ed08913c 100644 (file)
@@ -116,22 +116,18 @@ class ApiGroupLeaveAction extends ApiAuthAction
             return;
         }
 
-        $result = $member->delete();
-
-        if (!$result) {
-            common_log_db_error($member, 'DELETE', __FILE__);
-            $this->serverError(
-                sprintf(
-                    // TRANS: Server error displayed when leaving a group fails.
-                    // TRANS: %1$s is a user nickname, $2$s is a group nickname.
-                    _('Could not remove user %1$s from group %2$s.'),
-                    $this->user->nickname,
-                    $this->group->nickname
-                )
-            );
+        try {
+            if (Event::handle('StartLeaveGroup', array($this->group,$this->user))) {
+                Group_member::leave($this->group->id, $this->user->id);
+                Event::handle('EndLeaveGroup', array($this->group, $this->user));
+            }
+        } catch (Exception $e) {
+            // TRANS: Server error displayed when leaving a group failed in the database.
+            // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed.
+            $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'),
+                                       $cur->nickname, $this->group->nickname));
             return;
         }
-
         switch($this->format) {
         case 'xml':
             $this->showSingleXmlGroup($this->group);
index 7beaf4f64ac22abb393d69a9f7b42359bcfe5056..4c45ca8b9ddee3137c61d0564ffc89dc255cc802 100644 (file)
@@ -138,6 +138,7 @@ class JoingroupAction extends Action
             // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
             $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
                                        $cur->nickname, $this->group->nickname));
+            return;
         }
 
         if ($this->boolean('ajax')) {