1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +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:
epriestley 2018-01-05 11:08:16 -08:00
parent 7f91c8c4ac
commit 6ef45d8245
2 changed files with 84 additions and 0 deletions

View file

@ -2729,6 +2729,7 @@ phutil_register_library_map(array(
'PhabricatorEdgesDestructionEngineExtension' => 'infrastructure/edges/engineextension/PhabricatorEdgesDestructionEngineExtension.php',
'PhabricatorEditEngine' => 'applications/transactions/editengine/PhabricatorEditEngine.php',
'PhabricatorEditEngineAPIMethod' => 'applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php',
'PhabricatorEditEngineBulkJobType' => 'applications/transactions/bulk/PhabricatorEditEngineBulkJobType.php',
'PhabricatorEditEngineCheckboxesCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCheckboxesCommentAction.php',
'PhabricatorEditEngineColumnsCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineColumnsCommentAction.php',
'PhabricatorEditEngineCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineCommentAction.php',
@ -8110,6 +8111,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
),
'PhabricatorEditEngineAPIMethod' => 'ConduitAPIMethod',
'PhabricatorEditEngineBulkJobType' => 'PhabricatorWorkerBulkJobType',
'PhabricatorEditEngineCheckboxesCommentAction' => 'PhabricatorEditEngineCommentAction',
'PhabricatorEditEngineColumnsCommentAction' => 'PhabricatorEditEngineCommentAction',
'PhabricatorEditEngineCommentAction' => 'Phobject',

View file

@ -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;
}
}