szurubooru/src/Api/Jobs/PostJobs/EditPostJob.php
2014-05-12 15:15:50 +02:00

59 lines
1.1 KiB
PHP

<?php
class EditPostJob extends AbstractPostJob
{
public function execute()
{
$post = $this->post;
Logger::bufferChanges();
$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);
$args = $this->getArguments();
$args[JobArgs::ARG_POST_ENTITY] = $post;
try
{
Api::run($subJob, $args);
}
catch (ApiJobUnsatisfiedException $e)
{
}
}
if ($this->getContext() == AbstractJob::CONTEXT_NORMAL)
{
PostModel::save($post);
Logger::flush();
}
return $post;
}
public function getRequiredSubArguments()
{
return null;
}
public function getRequiredPrivileges()
{
return new Privilege(
$this->getContext() == self::CONTEXT_BATCH_ADD
? Privilege::AddPost
: Privilege::EditPost,
Access::getIdentity($this->post->getUploader()));
}
}