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/PostJobs/EditPostContentJob.php

45 lines
1 KiB
PHP
Raw Normal View History

2014-05-03 14:20:48 +02:00
<?php
class EditPostContentJob extends AbstractPostJob
2014-05-03 14:20:48 +02:00
{
public function execute()
{
2014-05-03 18:09:31 +02:00
$post = $this->post;
2014-05-03 14:20:48 +02:00
if ($this->hasArgument(JobArgs::ARG_NEW_POST_CONTENT_URL))
{
$url = $this->getArgument(JobArgs::ARG_NEW_POST_CONTENT_URL);
$post->setContentFromUrl($url);
}
else
{
$file = $this->getArgument(JobArgs::ARG_NEW_POST_CONTENT);
$post->setContentFromPath($file->filePath, $file->fileName);
}
2014-05-03 14:20:48 +02:00
if ($this->getContext() == self::CONTEXT_NORMAL)
PostModel::save($post);
2014-05-04 19:23:09 +02:00
Logger::log('{user} changed contents of {post}', [
2014-05-03 14:20:48 +02:00
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
2014-05-03 18:09:31 +02:00
'post' => TextHelper::reprPost($post)]);
2014-05-03 14:20:48 +02:00
2014-05-03 18:09:31 +02:00
return $post;
2014-05-03 14:20:48 +02:00
}
2014-05-12 10:31:34 +02:00
public function getRequiredSubArguments()
{
return JobArgs::Alternative(
JobArgs::ARG_NEW_POST_CONTENT,
JobArgs::ARG_NEW_POST_CONTENT_URL);
}
public function getRequiredPrivileges()
2014-05-03 14:20:48 +02:00
{
2014-05-04 16:27:15 +02:00
return new Privilege(
$this->getContext() == self::CONTEXT_BATCH_ADD
? Privilege::AddPostContent
: Privilege::EditPostContent,
2014-05-04 16:27:15 +02:00
Access::getIdentity($this->post->getUploader()));
2014-05-03 14:20:48 +02:00
}
}