- 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 TogglePostFavoriteJob extends AbstractJob
|
|
{
|
|
protected $postRetriever;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->postRetriever = new PostRetriever($this);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$post = $this->postRetriever->retrieve();
|
|
$favorite = TextHelper::toBoolean($this->getArgument(JobArgs::ARG_NEW_STATE));
|
|
|
|
if ($favorite)
|
|
{
|
|
UserModel::updateUserScore(Auth::getCurrentUser(), $post, 1);
|
|
UserModel::addToUserFavorites(Auth::getCurrentUser(), $post);
|
|
}
|
|
else
|
|
{
|
|
UserModel::removeFromUserFavorites(Auth::getCurrentUser(), $post);
|
|
}
|
|
|
|
return $post;
|
|
}
|
|
|
|
public function getRequiredArguments()
|
|
{
|
|
return JobArgs::Conjunction(
|
|
$this->postRetriever->getRequiredArguments(),
|
|
JobArgs::ARG_NEW_STATE);
|
|
}
|
|
|
|
public function getRequiredMainPrivilege()
|
|
{
|
|
return Privilege::FavoritePost;
|
|
}
|
|
|
|
public function getRequiredSubPrivileges()
|
|
{
|
|
return Access::getIdentity($this->postRetriever->retrieve()->getUploader());
|
|
}
|
|
|
|
public function isAuthenticationRequired()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function isConfirmedEmailRequired()
|
|
{
|
|
return false;
|
|
}
|
|
}
|