mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22:41 +01:00
Provide a generic transaction-oriented bulk job worker
Summary: Depends on D18806. Ref T13025. See PHI173. Currently, Maniphest bulk edits are processed by a Maniphest-specific worker. I want to replace this with a generic worker which can apply transactional edits to any object. This implements a generic worker, although it has no callers yet. Future changes give it callers, and later remove the Maniphest-specific worker. Test Plan: See next changes. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13025 Differential Revision: https://secure.phabricator.com/D18862
This commit is contained in:
parent
7f91c8c4ac
commit
6ef45d8245
2 changed files with 84 additions and 0 deletions
|
@ -2729,6 +2729,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEdgesDestructionEngineExtension' => 'infrastructure/edges/engineextension/PhabricatorEdgesDestructionEngineExtension.php',
|
'PhabricatorEdgesDestructionEngineExtension' => 'infrastructure/edges/engineextension/PhabricatorEdgesDestructionEngineExtension.php',
|
||||||
'PhabricatorEditEngine' => 'applications/transactions/editengine/PhabricatorEditEngine.php',
|
'PhabricatorEditEngine' => 'applications/transactions/editengine/PhabricatorEditEngine.php',
|
||||||
'PhabricatorEditEngineAPIMethod' => 'applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php',
|
'PhabricatorEditEngineAPIMethod' => 'applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php',
|
||||||
|
'PhabricatorEditEngineBulkJobType' => 'applications/transactions/bulk/PhabricatorEditEngineBulkJobType.php',
|
||||||
'PhabricatorEditEngineCheckboxesCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCheckboxesCommentAction.php',
|
'PhabricatorEditEngineCheckboxesCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCheckboxesCommentAction.php',
|
||||||
'PhabricatorEditEngineColumnsCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineColumnsCommentAction.php',
|
'PhabricatorEditEngineColumnsCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineColumnsCommentAction.php',
|
||||||
'PhabricatorEditEngineCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCommentAction.php',
|
'PhabricatorEditEngineCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCommentAction.php',
|
||||||
|
@ -8110,6 +8111,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorEditEngineAPIMethod' => 'ConduitAPIMethod',
|
'PhabricatorEditEngineAPIMethod' => 'ConduitAPIMethod',
|
||||||
|
'PhabricatorEditEngineBulkJobType' => 'PhabricatorWorkerBulkJobType',
|
||||||
'PhabricatorEditEngineCheckboxesCommentAction' => 'PhabricatorEditEngineCommentAction',
|
'PhabricatorEditEngineCheckboxesCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||||
'PhabricatorEditEngineColumnsCommentAction' => 'PhabricatorEditEngineCommentAction',
|
'PhabricatorEditEngineColumnsCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||||
'PhabricatorEditEngineCommentAction' => 'Phobject',
|
'PhabricatorEditEngineCommentAction' => 'Phobject',
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorEditEngineBulkJobType
|
||||||
|
extends PhabricatorWorkerBulkJobType {
|
||||||
|
|
||||||
|
public function getBulkJobTypeKey() {
|
||||||
|
return 'transaction.edit';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJobName(PhabricatorWorkerBulkJob $job) {
|
||||||
|
return pht('Bulk Edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescriptionForConfirm(PhabricatorWorkerBulkJob $job) {
|
||||||
|
return pht(
|
||||||
|
'You are about to apply a bulk edit which will affect '.
|
||||||
|
'%s object(s).',
|
||||||
|
new PhutilNumber($job->getSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJobSize(PhabricatorWorkerBulkJob $job) {
|
||||||
|
return count($job->getParameter('objectPHIDs', array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDoneURI(PhabricatorWorkerBulkJob $job) {
|
||||||
|
return $job->getParameter('doneURI');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createTasks(PhabricatorWorkerBulkJob $job) {
|
||||||
|
$tasks = array();
|
||||||
|
|
||||||
|
foreach ($job->getParameter('objectPHIDs', array()) as $phid) {
|
||||||
|
$tasks[] = PhabricatorWorkerBulkTask::initializeNewTask($job, $phid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function runTask(
|
||||||
|
PhabricatorUser $actor,
|
||||||
|
PhabricatorWorkerBulkJob $job,
|
||||||
|
PhabricatorWorkerBulkTask $task) {
|
||||||
|
|
||||||
|
$object = id(new PhabricatorObjectQuery())
|
||||||
|
->setViewer($actor)
|
||||||
|
->withPHIDs(array($task->getObjectPHID()))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
if (!$object) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw_xactions = $job->getParameter('xactions');
|
||||||
|
$xactions = $this->buildTransactions($object, $raw_xactions);
|
||||||
|
|
||||||
|
$editor = $object->getApplicationTransactionEditor()
|
||||||
|
->setActor($actor)
|
||||||
|
->setContentSource($job->newContentSource())
|
||||||
|
->setContinueOnNoEffect(true)
|
||||||
|
->setContinueOnMissingFields(true)
|
||||||
|
->applyTransactions($object, $xactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildTransactions($object, array $raw_xactions) {
|
||||||
|
$xactions = array();
|
||||||
|
|
||||||
|
foreach ($raw_xactions as $raw_xaction) {
|
||||||
|
$xaction = $object->getApplicationTransactionTemplate()
|
||||||
|
->setTransactionType($raw_xaction['type'])
|
||||||
|
->setNewValue($raw_xaction['value']);
|
||||||
|
|
||||||
|
$xactions[] = $xaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue