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/CommentJobs/EditCommentJob.php
Marcin Kurczewski e59b7e8b7b Refactored privilege system a bit
- Jobs specify main privilege and sub privileges separately
  Rationale: increase maintenance, restrict what can be done runtime
- Renamed ChangeUser* to EditUser* (consistency with EditPost*)
- Simplified enum names and configuration reading
- IJob interface members must be explicitly implemented
  Rationale: reduce chances of forgetting something, or typos in
  inherited method names
- Invalid privileges names in configuration yield exceptions
2014-05-18 21:59:56 +02:00

52 lines
1.1 KiB
PHP

<?php
class EditCommentJob extends AbstractJob
{
protected $commentRetriever;
public function __construct()
{
$this->commentRetriever = new CommentRetriever($this);
}
public function execute()
{
$comment = $this->commentRetriever->retrieve();
$comment->setCreationTime(time());
$comment->setText($this->getArgument(JobArgs::ARG_NEW_TEXT));
CommentModel::save($comment);
Logger::log('{user} edited comment in {post}', [
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
'post' => TextHelper::reprPost($comment->getPost())]);
return $comment;
}
public function getRequiredArguments()
{
return JobArgs::Conjunction(
$this->commentRetriever->getRequiredArguments(),
JobArgs::ARG_NEW_TEXT);
}
public function getRequiredMainPrivilege()
{
return Privilege::EditComment;
}
public function getRequiredSubPrivileges()
{
return Access::getIdentity($this->commentRetriever->retrieve()->getCommenter());
}
public function isAuthenticationRequired()
{
return true;
}
public function isConfirmedEmailRequired()
{
return false;
}
}