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
|
<?php
|
||||||
abstract class AbstractJob implements IJob
|
abstract class AbstractJob implements IJob
|
||||||
{
|
{
|
||||||
const CONTEXT_NORMAL = 1;
|
|
||||||
const CONTEXT_BATCH_EDIT = 2;
|
|
||||||
const CONTEXT_BATCH_ADD = 3;
|
|
||||||
|
|
||||||
protected $arguments = [];
|
protected $arguments = [];
|
||||||
protected $context = self::CONTEXT_NORMAL;
|
protected $context = self::CONTEXT_NORMAL;
|
||||||
protected $subJobs;
|
protected $subJobs;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
interface IJob
|
interface IJob
|
||||||
{
|
{
|
||||||
|
const CONTEXT_NORMAL = 1;
|
||||||
|
const CONTEXT_BATCH_EDIT = 2;
|
||||||
|
const CONTEXT_BATCH_ADD = 3;
|
||||||
|
|
||||||
public function prepare();
|
public function prepare();
|
||||||
public function execute();
|
public function execute();
|
||||||
|
|
||||||
|
public function getContext();
|
||||||
|
public function setContext($context);
|
||||||
|
|
||||||
public function getRequiredArguments();
|
public function getRequiredArguments();
|
||||||
public function getRequiredMainPrivilege();
|
public function getRequiredMainPrivilege();
|
||||||
public function getRequiredSubPrivileges();
|
public function getRequiredSubPrivileges();
|
||||||
|
|
|
@ -32,7 +32,7 @@ class AddPostJob extends AbstractJob
|
||||||
Logger::bufferChanges();
|
Logger::bufferChanges();
|
||||||
foreach ($this->getSubJobs() as $subJob)
|
foreach ($this->getSubJobs() as $subJob)
|
||||||
{
|
{
|
||||||
$subJob->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
$subJob->setContext(self::CONTEXT_BATCH_ADD);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Api::run($subJob, $arguments);
|
Api::run($subJob, $arguments);
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
|
|
||||||
$ctx = function($job)
|
$ctx = function($job)
|
||||||
{
|
{
|
||||||
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
$job->setContext(IJob::CONTEXT_BATCH_ADD);
|
||||||
return $job;
|
return $job;
|
||||||
};
|
};
|
||||||
$this->testDynamicPostPrivilege($ctx(new EditPostContentJob), Privilege::AddPostContent);
|
$this->testDynamicPostPrivilege($ctx(new EditPostContentJob), Privilege::AddPostContent);
|
||||||
|
@ -139,7 +139,7 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
|
|
||||||
$ctx = function($job)
|
$ctx = function($job)
|
||||||
{
|
{
|
||||||
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
$job->setContext(IJob::CONTEXT_BATCH_ADD);
|
||||||
return $job;
|
return $job;
|
||||||
};
|
};
|
||||||
$this->testDynamicUserPrivilege($ctx(new EditUserAccessRankJob()), Privilege::EditUserAccessRank);
|
$this->testDynamicUserPrivilege($ctx(new EditUserAccessRankJob()), Privilege::EditUserAccessRank);
|
||||||
|
|
Loading…
Reference in a new issue