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

60 lines
1.1 KiB
PHP
Raw Normal View History

2014-05-03 18:09:31 +02:00
<?php
class EditPostJob extends AbstractPostJob
2014-05-03 18:09:31 +02:00
{
public function execute()
{
$post = $this->post;
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;
}
2014-05-12 10:31:34 +02:00
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()));
}
2014-05-03 18:09:31 +02:00
}