/** * @param \Flarum\Events\DiscussionWasRenamed $event */ public function whenDiscussionWasRenamed(DiscussionWasRenamed $event) { $post = DiscussionRenamedPost::reply($event->discussion->id, $event->actor->id, $event->oldTitle, $event->discussion->title); $post = $event->discussion->mergePost($post); if ($event->discussion->start_user_id !== $event->actor->id) { $blueprint = new DiscussionRenamedBlueprint($post); if ($post->exists) { $this->notifications->sync($blueprint, [$event->discussion->startUser]); } else { $this->notifications->delete($blueprint); } } }
/** * @param PostReply $command * @return CommentPost * @throws \Flarum\Core\Exceptions\PermissionDeniedException */ public function handle(PostReply $command) { $actor = $command->actor; // Make sure the user has permission to reply to this discussion. First, // make sure the discussion exists and that the user has permission to // view it; if not, fail with a ModelNotFound exception so we don't give // away the existence of the discussion. If the user is allowed to view // it, check if they have permission to reply. $discussion = $this->discussions->findOrFail($command->discussionId, $actor); $discussion->assertCan($actor, 'reply'); // Create a new Post entity, persist it, and dispatch domain events. // Before persistence, though, fire an event to give plugins an // opportunity to alter the post entity based on data in the command. $post = CommentPost::reply($command->discussionId, array_get($command->data, 'attributes.content'), $actor->id); event(new PostWillBeSaved($post, $actor, $command->data)); $post->save(); $this->notifications->onePerUser(function () use($post) { $this->dispatchEventsFor($post); }); return $post; }