szurubooru/src/Api/Jobs/PostJobs/EditPostJob.php

67 lines
1.3 KiB
PHP
Raw Normal View History

2014-05-03 18:09:31 +02:00
<?php
class EditPostJob extends AbstractJob
2014-05-03 18:09:31 +02:00
{
protected $postRetriever;
public function __construct()
{
$this->postRetriever = new PostRetriever($this);
}
2014-05-03 18:09:31 +02:00
public function execute()
{
$post = $this->postRetriever->retrieve();
2014-05-03 18:09:31 +02:00
2014-05-04 19:23:09 +02:00
Logger::bufferChanges();
2014-05-04 13:39:00 +02:00
2014-05-03 18:09:31 +02:00
$subJobs =
[
new EditPostSafetyJob(),
new EditPostTagsJob(),
new EditPostSourceJob(),
new EditPostRelationsJob(),
new EditPostContentJob(),
new EditPostThumbJob(),
];
foreach ($subJobs as $subJob)
{
$subJob->setContext($this->getContext() == self::CONTEXT_BATCH_ADD
? self::CONTEXT_BATCH_ADD
: self::CONTEXT_BATCH_EDIT);
2014-05-03 18:09:31 +02:00
$args = $this->getArguments();
$args[JobArgs::ARG_POST_ENTITY] = $post;
2014-05-03 18:09:31 +02:00
try
{
Api::run($subJob, $args);
}
catch (ApiJobUnsatisfiedException $e)
2014-05-03 18:09:31 +02:00
{
}
}
if ($this->getContext() == AbstractJob::CONTEXT_NORMAL)
{
PostModel::save($post);
Logger::flush();
}
2014-05-03 18:09:31 +02:00
return $post;
}
public function getRequiredArguments()
2014-05-12 10:31:34 +02:00
{
return $this->postRetriever->getRequiredArguments();
2014-05-12 10:31:34 +02:00
}
public function getRequiredPrivileges()
{
return new Privilege(
$this->getContext() == self::CONTEXT_BATCH_ADD
? Privilege::AddPost
: Privilege::EditPost,
Access::getIdentity($this->postRetriever->retrieve()->getUploader()));
}
2014-05-03 18:09:31 +02:00
}