Moved job context management to interface
This commit is contained in:
parent
2c7f11e57e
commit
538165e3ff
4 changed files with 10 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue