Reduced job hierarchy
This commit is contained in:
parent
634d0061d4
commit
de078677fe
5 changed files with 62 additions and 41 deletions
|
@ -3,7 +3,12 @@ class AddPostJob extends AbstractJob
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->addSubJob(new EditPostJob());
|
$this->addSubJob(new EditPostSafetyJob());
|
||||||
|
$this->addSubJob(new EditPostTagsJob());
|
||||||
|
$this->addSubJob(new EditPostSourceJob());
|
||||||
|
$this->addSubJob(new EditPostRelationsJob());
|
||||||
|
$this->addSubJob(new EditPostContentJob());
|
||||||
|
$this->addSubJob(new EditPostThumbJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
|
@ -23,16 +28,21 @@ class AddPostJob extends AbstractJob
|
||||||
$arguments[JobArgs::ARG_POST_ENTITY] = $post;
|
$arguments[JobArgs::ARG_POST_ENTITY] = $post;
|
||||||
|
|
||||||
Logger::bufferChanges();
|
Logger::bufferChanges();
|
||||||
|
foreach ($this->getSubJobs() as $subJob)
|
||||||
|
{
|
||||||
|
$subJob->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$job = $this->getSubJobs()[0];
|
Api::run($subJob, $arguments);
|
||||||
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
}
|
||||||
Api::run($job, $arguments);
|
catch (ApiJobUnsatisfiedException $e)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Logger::discardBuffer();
|
Logger::discardBuffer();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//save the post to db if everything went okay
|
//save the post to db if everything went okay
|
||||||
PostModel::save($post);
|
PostModel::save($post);
|
||||||
|
|
|
@ -18,30 +18,25 @@ class EditPostJob extends AbstractJob
|
||||||
{
|
{
|
||||||
$post = $this->postRetriever->retrieve();
|
$post = $this->postRetriever->retrieve();
|
||||||
|
|
||||||
Logger::bufferChanges();
|
$arguments = $this->getArguments();
|
||||||
|
$arguments[JobArgs::ARG_POST_ENTITY] = $post;
|
||||||
|
|
||||||
|
Logger::bufferChanges();
|
||||||
foreach ($this->getSubJobs() as $subJob)
|
foreach ($this->getSubJobs() as $subJob)
|
||||||
{
|
{
|
||||||
$subJob->setContext($this->getContext() == self::CONTEXT_BATCH_ADD
|
$subJob->setContext(self::CONTEXT_BATCH_EDIT);
|
||||||
? self::CONTEXT_BATCH_ADD
|
|
||||||
: self::CONTEXT_BATCH_EDIT);
|
|
||||||
|
|
||||||
$args = $this->getArguments();
|
|
||||||
$args[JobArgs::ARG_POST_ENTITY] = $post;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Api::run($subJob, $args);
|
Api::run($subJob, $arguments);
|
||||||
}
|
}
|
||||||
catch (ApiJobUnsatisfiedException $e)
|
catch (ApiJobUnsatisfiedException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getContext() == AbstractJob::CONTEXT_NORMAL)
|
|
||||||
{
|
|
||||||
PostModel::save($post);
|
PostModel::save($post);
|
||||||
Logger::flush();
|
Logger::flush();
|
||||||
}
|
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
@ -54,9 +49,7 @@ class EditPostJob extends AbstractJob
|
||||||
public function getRequiredPrivileges()
|
public function getRequiredPrivileges()
|
||||||
{
|
{
|
||||||
return new Privilege(
|
return new Privilege(
|
||||||
$this->getContext() == self::CONTEXT_BATCH_ADD
|
Privilege::EditPost,
|
||||||
? Privilege::AddPost
|
|
||||||
: Privilege::EditPost,
|
|
||||||
Access::getIdentity($this->postRetriever->retrieve()->getUploader()));
|
Access::getIdentity($this->postRetriever->retrieve()->getUploader()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@ class AddUserJob extends AbstractJob
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->addSubJob(new EditUserJob());
|
$this->addSubJob(new EditUserAccessRankJob());
|
||||||
|
$this->addSubJob(new EditUserNameJob());
|
||||||
|
$this->addSubJob(new EditUserPasswordJob());
|
||||||
|
$this->addSubJob(new EditUserEmailJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
|
@ -28,16 +31,22 @@ class AddUserJob extends AbstractJob
|
||||||
$arguments[JobArgs::ARG_USER_ENTITY] = $user;
|
$arguments[JobArgs::ARG_USER_ENTITY] = $user;
|
||||||
|
|
||||||
Logger::bufferChanges();
|
Logger::bufferChanges();
|
||||||
|
foreach ($this->getSubJobs() as $subJob)
|
||||||
|
{
|
||||||
|
$subJob->setContext(self::CONTEXT_BATCH_ADD);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$job = $this->getSubJobs()[0];
|
Api::run($subJob, $arguments);
|
||||||
$job->setContext(self::CONTEXT_BATCH_ADD);
|
}
|
||||||
Api::run($job, $arguments);
|
catch (ApiJobUnsatisfiedException $e)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Logger::discardBuffer();
|
Logger::discardBuffer();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//save the user to db if everything went okay
|
//save the user to db if everything went okay
|
||||||
UserModel::save($user);
|
UserModel::save($user);
|
||||||
|
|
|
@ -34,19 +34,17 @@ class EditUserJob extends AbstractJob
|
||||||
{
|
{
|
||||||
$user = $this->userRetriever->retrieve();
|
$user = $this->userRetriever->retrieve();
|
||||||
|
|
||||||
Logger::bufferChanges();
|
$arguments = $this->getArguments();
|
||||||
|
$arguments[JobArgs::ARG_USER_ENTITY] = $user;
|
||||||
|
|
||||||
|
Logger::bufferChanges();
|
||||||
foreach ($this->getSubJobs() as $subJob)
|
foreach ($this->getSubJobs() as $subJob)
|
||||||
{
|
{
|
||||||
$subJob->setContext($this->getContext() == self::CONTEXT_BATCH_ADD
|
$subJob->setContext(self::CONTEXT_BATCH_EDIT);
|
||||||
? self::CONTEXT_BATCH_ADD
|
|
||||||
: self::CONTEXT_BATCH_EDIT);
|
|
||||||
|
|
||||||
$args = $this->getArguments();
|
|
||||||
$args[JobArgs::ARG_USER_ENTITY] = $user;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Api::run($subJob, $args);
|
Api::run($subJob, $arguments);
|
||||||
}
|
}
|
||||||
catch (ApiJobUnsatisfiedException $e)
|
catch (ApiJobUnsatisfiedException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,7 +55,6 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
||||||
return $job;
|
return $job;
|
||||||
};
|
};
|
||||||
$this->testDynamicPostPrivilege($ctx(new EditPostJob), new Privilege(Privilege::AddPost));
|
|
||||||
$this->testDynamicPostPrivilege($ctx(new EditPostContentJob), new Privilege(Privilege::AddPostContent));
|
$this->testDynamicPostPrivilege($ctx(new EditPostContentJob), new Privilege(Privilege::AddPostContent));
|
||||||
$this->testDynamicPostPrivilege($ctx(new EditPostRelationsJob), new Privilege(Privilege::AddPostRelations));
|
$this->testDynamicPostPrivilege($ctx(new EditPostRelationsJob), new Privilege(Privilege::AddPostRelations));
|
||||||
$this->testDynamicPostPrivilege($ctx(new EditPostSafetyJob), new Privilege(Privilege::AddPostSafety));
|
$this->testDynamicPostPrivilege($ctx(new EditPostSafetyJob), new Privilege(Privilege::AddPostSafety));
|
||||||
|
@ -135,6 +134,18 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
$this->testDynamicUserPrivilege(new EditUserNameJob(), new Privilege(Privilege::ChangeUserName));
|
$this->testDynamicUserPrivilege(new EditUserNameJob(), new Privilege(Privilege::ChangeUserName));
|
||||||
$this->testDynamicUserPrivilege(new EditUserPasswordJob(), new Privilege(Privilege::ChangeUserPassword));
|
$this->testDynamicUserPrivilege(new EditUserPasswordJob(), new Privilege(Privilege::ChangeUserPassword));
|
||||||
$this->testDynamicUserPrivilege(new EditUserSettingsJob(), new Privilege(Privilege::ChangeUserSettings));
|
$this->testDynamicUserPrivilege(new EditUserSettingsJob(), new Privilege(Privilege::ChangeUserSettings));
|
||||||
|
|
||||||
|
$ctx = function($job)
|
||||||
|
{
|
||||||
|
$job->setContext(AbstractJob::CONTEXT_BATCH_ADD);
|
||||||
|
return $job;
|
||||||
|
};
|
||||||
|
$this->testDynamicUserPrivilege($ctx(new EditUserAccessRankJob()), new Privilege(Privilege::ChangeUserAccessRank));
|
||||||
|
$this->testDynamicUserPrivilege($ctx(new EditUserEmailJob()), new Privilege(Privilege::RegisterAccount));
|
||||||
|
$this->testDynamicUserPrivilege($ctx(new EditUserNameJob()), new Privilege(Privilege::RegisterAccount));
|
||||||
|
$this->testDynamicUserPrivilege($ctx(new EditUserPasswordJob()), new Privilege(Privilege::RegisterAccount));
|
||||||
|
$this->testDynamicUserPrivilege($ctx(new EditUserSettingsJob()), new Privilege(Privilege::ChangeUserSettings));
|
||||||
|
|
||||||
$this->testDynamicUserPrivilege(new FlagUserJob(), new Privilege(Privilege::FlagUser));
|
$this->testDynamicUserPrivilege(new FlagUserJob(), new Privilege(Privilege::FlagUser));
|
||||||
$this->testDynamicUserPrivilege(new GetUserJob(), new Privilege(Privilege::ViewUser));
|
$this->testDynamicUserPrivilege(new GetUserJob(), new Privilege(Privilege::ViewUser));
|
||||||
$this->testDynamicUserPrivilege(new GetUserSettingsJob(), new Privilege(Privilege::ChangeUserSettings));
|
$this->testDynamicUserPrivilege(new GetUserSettingsJob(), new Privilege(Privilege::ChangeUserSettings));
|
||||||
|
|
Loading…
Reference in a new issue