38 lines
881 B
PHP
38 lines
881 B
PHP
<?php
|
|
class AddCommentJob extends AbstractJob
|
|
{
|
|
public function execute()
|
|
{
|
|
$user = Auth::getCurrentUser();
|
|
$post = PostModel::findById($this->getArgument(self::POST_ID));
|
|
$text = CommentModel::validateText($this->getArgument(self::TEXT));
|
|
|
|
$comment = CommentModel::spawn();
|
|
$comment->setCommenter($user);
|
|
$comment->setPost($post);
|
|
$comment->commentDate = time();
|
|
$comment->text = $text;
|
|
|
|
CommentModel::save($comment);
|
|
LogHelper::log('{user} commented on {post}', [
|
|
'user' => TextHelper::reprUser($user),
|
|
'post' => TextHelper::reprPost($comment->getPost()->id)]);
|
|
|
|
return $comment;
|
|
}
|
|
|
|
public function requiresPrivilege()
|
|
{
|
|
return new Privilege(Privilege::AddComment);
|
|
}
|
|
|
|
public function requiresAuthentication()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function requiresConfirmedEmail()
|
|
{
|
|
return getConfig()->registration->needEmailForCommenting;
|
|
}
|
|
}
|