szurubooru/src/Api/Jobs/EditPostThumbJob.php

37 lines
831 B
PHP
Raw Normal View History

2014-05-03 18:09:31 +02:00
<?php
class EditPostThumbJob extends AbstractPostJob
2014-05-03 18:09:31 +02:00
{
const THUMB_CONTENT = 'thumb-content';
public function isSatisfied()
{
return $this->hasArgument(self::THUMB_CONTENT);
}
2014-05-03 18:09:31 +02:00
public function execute()
{
$post = $this->post;
$file = $this->getArgument(self::THUMB_CONTENT);
$post->setCustomThumbnailFromPath($file->filePath);
if ($this->getContext() == self::CONTEXT_NORMAL)
PostModel::save($post);
2014-05-03 18:09:31 +02:00
2014-05-04 19:23:09 +02:00
Logger::log('{user} changed thumb of {post}', [
2014-05-03 18:09:31 +02:00
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
'post' => TextHelper::reprPost($post)]);
return $post;
}
public function requiresPrivilege()
{
2014-05-04 16:27:15 +02:00
return new Privilege(
$this->getContext() == self::CONTEXT_BATCH_ADD
? Privilege::AddPostThumb
: Privilege::EditPostThumb,
2014-05-04 16:27:15 +02:00
Access::getIdentity($this->post->getUploader()));
2014-05-03 18:09:31 +02:00
}
}