2014-05-03 18:09:31 +02:00
|
|
|
<?php
|
2014-05-06 19:39:41 +02:00
|
|
|
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)
|
|
|
|
{
|
2014-05-06 19:39:41 +02:00
|
|
|
$subJob->setContext($this->getContext() == self::CONTEXT_BATCH_ADD
|
|
|
|
? self::CONTEXT_BATCH_ADD
|
|
|
|
: self::CONTEXT_BATCH_EDIT);
|
2014-05-04 17:53:40 +02:00
|
|
|
|
2014-05-03 18:09:31 +02:00
|
|
|
$args = $this->getArguments();
|
2014-05-12 00:13:18 +02:00
|
|
|
$args[JobArgs::ARG_POST_ENTITY] = $post;
|
2014-05-03 18:09:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Api::run($subJob, $args);
|
|
|
|
}
|
2014-05-06 19:39:41 +02:00
|
|
|
catch (ApiJobUnsatisfiedException $e)
|
2014-05-03 18:09:31 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
if ($this->getContext() == AbstractJob::CONTEXT_NORMAL)
|
2014-05-07 01:14:52 +02:00
|
|
|
{
|
2014-05-04 17:53:40 +02:00
|
|
|
PostModel::save($post);
|
2014-05-07 01:14:52 +02:00
|
|
|
Logger::flush();
|
|
|
|
}
|
2014-05-04 17:53:40 +02:00
|
|
|
|
2014-05-03 18:09:31 +02:00
|
|
|
return $post;
|
|
|
|
}
|
2014-05-06 19:39:41 +02:00
|
|
|
|
|
|
|
public function requiresPrivilege()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|