- 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
55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
class TogglePostVisibilityJob extends AbstractJob
|
|
{
|
|
protected $postRetriever;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->postRetriever = new PostRetriever($this);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$post = $this->postRetriever->retrieve();
|
|
$visible = TextHelper::toBoolean($this->getArgument(JobArgs::ARG_NEW_STATE));
|
|
|
|
$post->setHidden(!$visible);
|
|
PostModel::save($post);
|
|
|
|
Logger::log(
|
|
$visible
|
|
? '{user} unhidden {post}'
|
|
: '{user} hidden {post}', [
|
|
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
|
'post' => TextHelper::reprPost($post)]);
|
|
|
|
return $post;
|
|
}
|
|
|
|
public function getRequiredArguments()
|
|
{
|
|
return JobArgs::Conjunction(
|
|
$this->postRetriever->getRequiredArguments(),
|
|
JobArgs::ARG_NEW_STATE);
|
|
}
|
|
|
|
public function getRequiredMainPrivilege()
|
|
{
|
|
return Privilege::HidePost;
|
|
}
|
|
|
|
public function getRequiredSubPrivileges()
|
|
{
|
|
return Access::getIdentity($this->postRetriever->retrieve()->getUploader());
|
|
}
|
|
|
|
public function isAuthenticationRequired()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function isConfirmedEmailRequired()
|
|
{
|
|
return false;
|
|
}
|
|
}
|