X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapigroupjoin.php;h=2e35cb87de364636e247e95953507703bc7f8069;hb=f5bde9b6938e1f20b9eb4d20da366859ad88b5b3;hp=345fed2215e7587d582a46605f2df578fd9c2721;hpb=9e9b7b972c5c2365f1861327600a02e4aaa7c430;p=quix0rs-gnu-social.git diff --git a/actions/apigroupjoin.php b/actions/apigroupjoin.php index 345fed2215..2e35cb87de 100644 --- a/actions/apigroupjoin.php +++ b/actions/apigroupjoin.php @@ -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) {