Moved job context management to interface

This commit is contained in:
Marcin Kurczewski 2014-06-10 10:47:05 +02:00
parent 2c7f11e57e
commit 538165e3ff
4 changed files with 10 additions and 7 deletions

View file

@ -1,10 +1,6 @@
<?php
abstract class AbstractJob implements IJob
{
const CONTEXT_NORMAL = 1;
const CONTEXT_BATCH_EDIT = 2;
const CONTEXT_BATCH_ADD = 3;
protected $arguments = [];
protected $context = self::CONTEXT_NORMAL;
protected $subJobs;

View file

@ -1,9 +1,16 @@
<?php
interface IJob
{
const CONTEXT_NORMAL = 1;
const CONTEXT_BATCH_EDIT = 2;
const CONTEXT_BATCH_ADD = 3;
public function prepare();
public function execute();
public function getContext();
public function setContext($context);
public function getRequiredArguments();
public function getRequiredMainPrivilege();
public function getRequiredSubPrivileges();

View file

@ -32,7 +32,7 @@ class AddPostJob extends AbstractJob
Logger::bufferChanges();
foreach ($this->getSubJobs() as $subJob)
{
$subJob->setContext(AbstractJob::CONTEXT_BATCH_ADD);
$subJob->setContext(self::CONTEXT_BATCH_ADD);
try
{
Api::run($subJob, $arguments);

View file

@ -53,7 +53,7 @@ class ApiPrivilegeTest extends AbstractFullApiTest
$ctx = function($job)
{
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
$job->setContext(IJob::CONTEXT_BATCH_ADD);
return $job;
};
$this->testDynamicPostPrivilege($ctx(new EditPostContentJob), Privilege::AddPostContent);
@ -139,7 +139,7 @@ class ApiPrivilegeTest extends AbstractFullApiTest
$ctx = function($job)
{
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
$job->setContext(IJob::CONTEXT_BATCH_ADD);
return $job;
};
$this->testDynamicUserPrivilege($ctx(new EditUserAccessRankJob()), Privilege::EditUserAccessRank);