This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Api/Jobs/PreviewCommentJob.php
2014-05-07 21:30:37 +02:00

43 lines
846 B
PHP

<?php
class PreviewCommentJob extends AbstractJob
{
public function execute()
{
$user = Auth::getCurrentUser();
$text = $this->getArgument(self::TEXT);
if ($this->hasArgument(self::POST_ID))
{
$post = PostModel::findById($this->getArgument(self::POST_ID));
$comment = CommentModel::spawn();
$comment->setPost($post);
}
else
{
$comment = CommentModel::findById($this->getArgument(self::COMMENT_ID));
}
$comment->setCommenter($user);
$comment->setCreationTime(time());
$comment->setText($text);
$comment->validate();
return $comment;
}
public function requiresPrivilege()
{
return new Privilege(Privilege::AddComment);
}
public function requiresAuthentication()
{
return false;
}
public function requiresConfirmedEmail()
{
return getConfig()->registration->needEmailForCommenting;
}
}