]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/leavegroup.php
Merge branch 'testing'
[quix0rs-gnu-social.git] / actions / leavegroup.php
index 60b22e147d735978090f36d0ecc10644ee07b6c2..9b9d83b6caae243befbd9e43a43eb6b137be53f5 100644 (file)
@@ -56,11 +56,6 @@ class LeavegroupAction extends Action
     {
         parent::prepare($args);
 
-        if (!common_config('inboxes','enabled')) {
-            $this->serverError(_('Inboxes must be enabled for groups to work.'));
-            return false;
-        }
-
         if (!common_logged_in()) {
             $this->clientError(_('You must be logged in to leave a group.'));
             return false;
@@ -115,28 +110,21 @@ 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, 'INSERT', __FILE__);
-            $this->serverError(sprintf(_('Could not remove user %s to group %s'),
+        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')) {
             $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
-            $this->element('title', null, sprintf(_('%s left group %s'),
+            $this->element('title', null, sprintf(_('%1$s left group %2$s'),
                                                   $cur->nickname,
                                                   $this->group->nickname));
             $this->elementEnd('head');