/**
* @param EditPost $command
* @return \Flarum\Core\Post
* @throws \Flarum\Core\Exception\PermissionDeniedException
*/
public function handle(EditPost $command)
{
$actor = $command->actor;
$data = $command->data;
$post = $this->posts->findOrFail($command->postId, $actor);
if ($post instanceof CommentPost) {
$attributes = array_get($data, 'attributes', []);
if (isset($attributes['content'])) {
$this->assertCan($actor, 'edit', $post);
$post->revise($attributes['content'], $actor);
}
if (isset($attributes['isHidden'])) {
$this->assertCan($actor, 'edit', $post);
if ($attributes['isHidden']) {
$post->hide($actor);
} else {
$post->restore();
}
}
}
$this->events->fire(new PostWillBeSaved($post, $actor, $data));
$this->validator->assertValid($post->getDirty());
$post->save();
$this->dispatchEventsFor($post, $actor);
return $post;
}