Differential D21582 Diff 51378 src/applications/diffusion/worker/DiffusionUpdateObjectAfterCommitWorker.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/worker/DiffusionUpdateObjectAfterCommitWorker.php
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | private function updateTask( | ||||
$editor->applyTransactions($task, $xactions); | $editor->applyTransactions($task, $xactions); | ||||
} | } | ||||
private function updateRevision( | private function updateRevision( | ||||
PhabricatorRepositoryCommit $commit, | PhabricatorRepositoryCommit $commit, | ||||
DifferentialRevision $revision) { | DifferentialRevision $revision) { | ||||
$acting_phid = $this->getActingPHID($commit); | |||||
$acting_user = $this->loadActingUser($acting_phid); | |||||
// See T13625. The "Acting User" is the author of the commit based on the | |||||
// author string, or the Diffusion application PHID if we could not | |||||
// identify an author. | |||||
// This user may not be able to view the commit or the revision, and may | |||||
// also be unable to make API calls. Here, we execute queries and apply | |||||
// transactions as the omnipotent user. | |||||
// It would probably be better to use the acting user everywhere here, and | |||||
// exit gracefully if they can't see the revision (this is how the flow | |||||
// on tasks works). However, without a positive indicator in the UI | |||||
// explaining "no revision was updated because the author of this commit | |||||
// can't see anything", this might be fairly confusing, and break workflows | |||||
// which have worked historically. | |||||
// This isn't, per se, a policy violation (you can't get access to anything | |||||
// you don't already have access to by making commits that reference | |||||
// revisions, even if you can't see the commits or revisions), so just | |||||
// leave it for now. | |||||
$viewer = $this->getViewer(); | |||||
// Reload the revision to get the active diff, which is currently required | // Reload the revision to get the active diff, which is currently required | ||||
// by "updateRevisionWithCommit()". | // by "updateRevisionWithCommit()". | ||||
$revision = id(new DifferentialRevisionQuery()) | $revision = id(new DifferentialRevisionQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($viewer) | ||||
->withIDs(array($revision->getID())) | ->withIDs(array($revision->getID())) | ||||
->needActiveDiffs(true) | ->needActiveDiffs(true) | ||||
->executeOne(); | ->executeOne(); | ||||
$acting_phid = $this->getActingPHID($commit); | |||||
$acting_user = $this->loadActingUser($acting_phid); | |||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = $this->newEdgeTransaction( | $xactions[] = $this->newEdgeTransaction( | ||||
$revision, | $revision, | ||||
$commit, | $commit, | ||||
DifferentialRevisionHasCommitEdgeType::EDGECONST); | DifferentialRevisionHasCommitEdgeType::EDGECONST); | ||||
$match_data = $this->getUpdateProperty('revisionMatchData'); | $match_data = $this->getUpdateProperty('revisionMatchData'); | ||||
$type_close = DifferentialRevisionCloseTransaction::TRANSACTIONTYPE; | $type_close = DifferentialRevisionCloseTransaction::TRANSACTIONTYPE; | ||||
$xactions[] = $revision->getApplicationTransactionTemplate() | $xactions[] = $revision->getApplicationTransactionTemplate() | ||||
->setTransactionType($type_close) | ->setTransactionType($type_close) | ||||
->setNewValue(true) | ->setNewValue(true) | ||||
->setMetadataValue('isCommitClose', true) | ->setMetadataValue('isCommitClose', true) | ||||
->setMetadataValue('revisionMatchData', $match_data) | ->setMetadataValue('revisionMatchData', $match_data) | ||||
->setMetadataValue('commitPHID', $commit->getPHID()); | ->setMetadataValue('commitPHID', $commit->getPHID()); | ||||
$extraction_engine = id(new DifferentialDiffExtractionEngine()) | $extraction_engine = id(new DifferentialDiffExtractionEngine()) | ||||
->setViewer($acting_user) | ->setViewer($viewer) | ||||
->setAuthorPHID($acting_phid); | ->setAuthorPHID($acting_phid); | ||||
$content_source = $this->newContentSource(); | $content_source = $this->newContentSource(); | ||||
$extraction_engine->updateRevisionWithCommit( | $extraction_engine->updateRevisionWithCommit( | ||||
$revision, | $revision, | ||||
$commit, | $commit, | ||||
$xactions, | $xactions, | ||||
Show All 23 Lines |