2014-05-03 18:09:31 +02:00
|
|
|
<?php
|
2014-05-12 16:46:14 +02:00
|
|
|
class EditPostJob extends AbstractJob
|
2014-05-03 18:09:31 +02:00
|
|
|
{
|
2014-05-12 16:46:14 +02:00
|
|
|
protected $postRetriever;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->postRetriever = new PostRetriever($this);
|
|
|
|
}
|
|
|
|
|
2014-05-03 18:09:31 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2014-05-12 16:46:14 +02:00
|
|
|
$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)
|
|
|
|
{
|
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
|
|
|
|
2014-05-12 16:46:14 +02:00
|
|
|
public function getRequiredArguments()
|
2014-05-12 10:31:34 +02:00
|
|
|
{
|
2014-05-12 16:46:14 +02:00
|
|
|
return $this->postRetriever->getRequiredArguments();
|
2014-05-12 10:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredPrivileges()
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
|
|
|
return new Privilege(
|
|
|
|
$this->getContext() == self::CONTEXT_BATCH_ADD
|
|
|
|
? Privilege::AddPost
|
|
|
|
: Privilege::EditPost,
|
2014-05-12 16:46:14 +02:00
|
|
|
Access::getIdentity($this->postRetriever->retrieve()->getUploader()));
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|
2014-05-03 18:09:31 +02:00
|
|
|
}
|