mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Mostly modularize the Differential "update" transaction
Summary: Ref T13099. Move most of the "Update" logic to modular transactions Test Plan: Created and updated revisions. Flushed the task queue. Grepped for `TYPE_UPDATE`. Reviewed update transactions in the timeline and feed. Maniphest Tasks: T13099 Differential Revision: https://secure.phabricator.com/D19175
This commit is contained in:
parent
44f0664d2c
commit
743d1ac426
10 changed files with 208 additions and 208 deletions
|
@ -75,7 +75,7 @@ foreach ($rows as $row) {
|
||||||
|
|
||||||
if ($diff_id || $row['action'] == DifferentialAction::ACTION_UPDATE) {
|
if ($diff_id || $row['action'] == DifferentialAction::ACTION_UPDATE) {
|
||||||
$xactions[] = array(
|
$xactions[] = array(
|
||||||
'type' => DifferentialTransaction::TYPE_UPDATE,
|
'type' => DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE,
|
||||||
'old' => null,
|
'old' => null,
|
||||||
'new' => $diff_id,
|
'new' => $diff_id,
|
||||||
);
|
);
|
||||||
|
|
|
@ -598,6 +598,7 @@ phutil_register_library_map(array(
|
||||||
'DifferentialRevisionTitleTransaction' => 'applications/differential/xaction/DifferentialRevisionTitleTransaction.php',
|
'DifferentialRevisionTitleTransaction' => 'applications/differential/xaction/DifferentialRevisionTitleTransaction.php',
|
||||||
'DifferentialRevisionTransactionType' => 'applications/differential/xaction/DifferentialRevisionTransactionType.php',
|
'DifferentialRevisionTransactionType' => 'applications/differential/xaction/DifferentialRevisionTransactionType.php',
|
||||||
'DifferentialRevisionUpdateHistoryView' => 'applications/differential/view/DifferentialRevisionUpdateHistoryView.php',
|
'DifferentialRevisionUpdateHistoryView' => 'applications/differential/view/DifferentialRevisionUpdateHistoryView.php',
|
||||||
|
'DifferentialRevisionUpdateTransaction' => 'applications/differential/xaction/DifferentialRevisionUpdateTransaction.php',
|
||||||
'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php',
|
'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php',
|
||||||
'DifferentialRevisionVoidTransaction' => 'applications/differential/xaction/DifferentialRevisionVoidTransaction.php',
|
'DifferentialRevisionVoidTransaction' => 'applications/differential/xaction/DifferentialRevisionVoidTransaction.php',
|
||||||
'DifferentialRevisionWrongStateTransaction' => 'applications/differential/xaction/DifferentialRevisionWrongStateTransaction.php',
|
'DifferentialRevisionWrongStateTransaction' => 'applications/differential/xaction/DifferentialRevisionWrongStateTransaction.php',
|
||||||
|
@ -5822,6 +5823,7 @@ phutil_register_library_map(array(
|
||||||
'DifferentialRevisionTitleTransaction' => 'DifferentialRevisionTransactionType',
|
'DifferentialRevisionTitleTransaction' => 'DifferentialRevisionTransactionType',
|
||||||
'DifferentialRevisionTransactionType' => 'PhabricatorModularTransactionType',
|
'DifferentialRevisionTransactionType' => 'PhabricatorModularTransactionType',
|
||||||
'DifferentialRevisionUpdateHistoryView' => 'AphrontView',
|
'DifferentialRevisionUpdateHistoryView' => 'AphrontView',
|
||||||
|
'DifferentialRevisionUpdateTransaction' => 'DifferentialRevisionTransactionType',
|
||||||
'DifferentialRevisionViewController' => 'DifferentialController',
|
'DifferentialRevisionViewController' => 'DifferentialController',
|
||||||
'DifferentialRevisionVoidTransaction' => 'DifferentialRevisionTransactionType',
|
'DifferentialRevisionVoidTransaction' => 'DifferentialRevisionTransactionType',
|
||||||
'DifferentialRevisionWrongStateTransaction' => 'DifferentialRevisionTransactionType',
|
'DifferentialRevisionWrongStateTransaction' => 'DifferentialRevisionTransactionType',
|
||||||
|
|
|
@ -58,7 +58,7 @@ abstract class DifferentialConduitAPIMethod extends ConduitAPIMethod {
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
$xactions[] = array(
|
$xactions[] = array(
|
||||||
'type' => DifferentialRevisionEditEngine::KEY_UPDATE,
|
'type' => DifferentialRevisionUpdateTransaction::EDITKEY,
|
||||||
'value' => $diff->getPHID(),
|
'value' => $diff->getPHID(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ final class DifferentialRevisionEditEngine
|
||||||
|
|
||||||
const ENGINECONST = 'differential.revision';
|
const ENGINECONST = 'differential.revision';
|
||||||
|
|
||||||
const KEY_UPDATE = 'update';
|
|
||||||
|
|
||||||
const ACTIONGROUP_REVIEW = 'review';
|
const ACTIONGROUP_REVIEW = 'review';
|
||||||
const ACTIONGROUP_REVISION = 'revision';
|
const ACTIONGROUP_REVISION = 'revision';
|
||||||
|
|
||||||
|
@ -123,12 +121,13 @@ final class DifferentialRevisionEditEngine
|
||||||
$fields = array();
|
$fields = array();
|
||||||
|
|
||||||
$fields[] = id(new PhabricatorHandlesEditField())
|
$fields[] = id(new PhabricatorHandlesEditField())
|
||||||
->setKey(self::KEY_UPDATE)
|
->setKey(DifferentialRevisionUpdateTransaction::EDITKEY)
|
||||||
->setLabel(pht('Update Diff'))
|
->setLabel(pht('Update Diff'))
|
||||||
->setDescription(pht('New diff to create or update the revision with.'))
|
->setDescription(pht('New diff to create or update the revision with.'))
|
||||||
->setConduitDescription(pht('Create or update a revision with a diff.'))
|
->setConduitDescription(pht('Create or update a revision with a diff.'))
|
||||||
->setConduitTypeDescription(pht('PHID of the diff.'))
|
->setConduitTypeDescription(pht('PHID of the diff.'))
|
||||||
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
->setTransactionType(
|
||||||
|
DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE)
|
||||||
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
|
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
|
||||||
->setSingleValue($diff_phid)
|
->setSingleValue($diff_phid)
|
||||||
->setIsConduitOnly(!$diff)
|
->setIsConduitOnly(!$diff)
|
||||||
|
|
|
@ -33,7 +33,7 @@ final class DifferentialTransactionEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDiffUpdateTransaction(array $xactions) {
|
public function getDiffUpdateTransaction(array $xactions) {
|
||||||
$type_update = DifferentialTransaction::TYPE_UPDATE;
|
$type_update = DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE;
|
||||||
|
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
if ($xaction->getTransactionType() == $type_update) {
|
if ($xaction->getTransactionType() == $type_update) {
|
||||||
|
@ -76,7 +76,6 @@ final class DifferentialTransactionEditor
|
||||||
$types[] = PhabricatorTransactions::TYPE_INLINESTATE;
|
$types[] = PhabricatorTransactions::TYPE_INLINESTATE;
|
||||||
|
|
||||||
$types[] = DifferentialTransaction::TYPE_INLINE;
|
$types[] = DifferentialTransaction::TYPE_INLINE;
|
||||||
$types[] = DifferentialTransaction::TYPE_UPDATE;
|
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
@ -88,12 +87,6 @@ final class DifferentialTransactionEditor
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_INLINE:
|
case DifferentialTransaction::TYPE_INLINE:
|
||||||
return null;
|
return null;
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
|
||||||
if ($this->getIsNewObject()) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return $object->getActiveDiff()->getPHID();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
return parent::getCustomTransactionOldValue($object, $xaction);
|
||||||
|
@ -104,8 +97,6 @@ final class DifferentialTransactionEditor
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
|
||||||
return $xaction->getNewValue();
|
|
||||||
case DifferentialTransaction::TYPE_INLINE:
|
case DifferentialTransaction::TYPE_INLINE:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -120,29 +111,6 @@ final class DifferentialTransactionEditor
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_INLINE:
|
case DifferentialTransaction::TYPE_INLINE:
|
||||||
return;
|
return;
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
|
||||||
if (!$this->getIsCloseByCommit()) {
|
|
||||||
if ($object->isNeedsRevision() ||
|
|
||||||
$object->isChangePlanned() ||
|
|
||||||
$object->isAbandoned()) {
|
|
||||||
$object->setModernRevisionStatus(
|
|
||||||
DifferentialRevisionStatus::NEEDS_REVIEW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff = $this->requireDiff($xaction->getNewValue());
|
|
||||||
|
|
||||||
$this->updateRevisionLineCounts($object, $diff);
|
|
||||||
|
|
||||||
if ($this->repositoryPHIDOverride !== false) {
|
|
||||||
$object->setRepositoryPHID($this->repositoryPHIDOverride);
|
|
||||||
} else {
|
|
||||||
$object->setRepositoryPHID($diff->getRepositoryPHID());
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->attachActiveDiff($diff);
|
|
||||||
$object->setActiveDiffPHID($diff->getPHID());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
return parent::applyCustomInternalTransaction($object, $xaction);
|
||||||
|
@ -196,7 +164,7 @@ final class DifferentialTransactionEditor
|
||||||
// commit.
|
// commit.
|
||||||
} else {
|
} else {
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
$downgrade_rejects = true;
|
$downgrade_rejects = true;
|
||||||
if (!$is_sticky_accept) {
|
if (!$is_sticky_accept) {
|
||||||
// If "sticky accept" is disabled, also downgrade the accepts.
|
// If "sticky accept" is disabled, also downgrade the accepts.
|
||||||
|
@ -243,7 +211,7 @@ final class DifferentialTransactionEditor
|
||||||
|
|
||||||
$is_commandeer = false;
|
$is_commandeer = false;
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
if ($this->getIsCloseByCommit()) {
|
if ($this->getIsCloseByCommit()) {
|
||||||
// Don't bother with any of this if this update is a side effect of
|
// Don't bother with any of this if this update is a side effect of
|
||||||
// commit detection.
|
// commit detection.
|
||||||
|
@ -293,7 +261,7 @@ final class DifferentialTransactionEditor
|
||||||
if (!$this->didExpandInlineState) {
|
if (!$this->didExpandInlineState) {
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorTransactions::TYPE_COMMENT:
|
case PhabricatorTransactions::TYPE_COMMENT:
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
case DifferentialTransaction::TYPE_INLINE:
|
case DifferentialTransaction::TYPE_INLINE:
|
||||||
$this->didExpandInlineState = true;
|
$this->didExpandInlineState = true;
|
||||||
|
|
||||||
|
@ -343,45 +311,6 @@ final class DifferentialTransactionEditor
|
||||||
if ($reply && !$reply->getHasReplies()) {
|
if ($reply && !$reply->getHasReplies()) {
|
||||||
$reply->setHasReplies(1)->save();
|
$reply->setHasReplies(1)->save();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
|
||||||
// Now that we're inside the transaction, do a final check.
|
|
||||||
$diff = $this->requireDiff($xaction->getNewValue());
|
|
||||||
|
|
||||||
// TODO: It would be slightly cleaner to just revalidate this
|
|
||||||
// transaction somehow using the same validation code, but that's
|
|
||||||
// not easy to do at the moment.
|
|
||||||
|
|
||||||
$revision_id = $diff->getRevisionID();
|
|
||||||
if ($revision_id && ($revision_id != $object->getID())) {
|
|
||||||
throw new Exception(
|
|
||||||
pht(
|
|
||||||
'Diff is already attached to another revision. You lost '.
|
|
||||||
'a race?'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This can race with diff updates, particularly those from
|
|
||||||
// Harbormaster. See discussion in T8650.
|
|
||||||
$diff->setRevisionID($object->getID());
|
|
||||||
$diff->save();
|
|
||||||
|
|
||||||
// If there are any outstanding buildables for this diff, tell
|
|
||||||
// Harbormaster that their containers need to be updated. This is
|
|
||||||
// common, because `arc` creates buildables so it can upload lint
|
|
||||||
// and unit results.
|
|
||||||
|
|
||||||
$buildables = id(new HarbormasterBuildableQuery())
|
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
||||||
->withManualBuildables(false)
|
|
||||||
->withBuildablePHIDs(array($diff->getPHID()))
|
|
||||||
->execute();
|
|
||||||
foreach ($buildables as $buildable) {
|
|
||||||
$buildable->sendMessage(
|
|
||||||
$this->getActor(),
|
|
||||||
HarbormasterMessageType::BUILDABLE_CONTAINER,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +366,7 @@ final class DifferentialTransactionEditor
|
||||||
|
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
$diff = $this->requireDiff($xaction->getNewValue(), true);
|
$diff = $this->requireDiff($xaction->getNewValue(), true);
|
||||||
|
|
||||||
// Update these denormalized index tables when we attach a new
|
// Update these denormalized index tables when we attach a new
|
||||||
|
@ -554,44 +483,6 @@ final class DifferentialTransactionEditor
|
||||||
return $xactions;
|
return $xactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function validateTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
$type,
|
|
||||||
array $xactions) {
|
|
||||||
|
|
||||||
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
||||||
|
|
||||||
$config_self_accept_key = 'differential.allow-self-accept';
|
|
||||||
$allow_self_accept = PhabricatorEnv::getEnvConfig($config_self_accept_key);
|
|
||||||
|
|
||||||
foreach ($xactions as $xaction) {
|
|
||||||
switch ($type) {
|
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
|
||||||
$diff = $this->loadDiff($xaction->getNewValue());
|
|
||||||
if (!$diff) {
|
|
||||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Invalid'),
|
|
||||||
pht('The specified diff does not exist.'),
|
|
||||||
$xaction);
|
|
||||||
} else if (($diff->getRevisionID()) &&
|
|
||||||
($diff->getRevisionID() != $object->getID())) {
|
|
||||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Invalid'),
|
|
||||||
pht(
|
|
||||||
'You can not update this revision to the specified diff, '.
|
|
||||||
'because the diff is already attached to another revision.'),
|
|
||||||
$xaction);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function sortTransactions(array $xactions) {
|
protected function sortTransactions(array $xactions) {
|
||||||
$xactions = parent::sortTransactions($xactions);
|
$xactions = parent::sortTransactions($xactions);
|
||||||
|
|
||||||
|
@ -674,7 +565,7 @@ final class DifferentialTransactionEditor
|
||||||
$action = parent::getMailAction($object, $xactions);
|
$action = parent::getMailAction($object, $xactions);
|
||||||
|
|
||||||
$strongest = $this->getStrongestAction($object, $xactions);
|
$strongest = $this->getStrongestAction($object, $xactions);
|
||||||
$type_update = DifferentialTransaction::TYPE_UPDATE;
|
$type_update = DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE;
|
||||||
if ($strongest->getTransactionType() == $type_update) {
|
if ($strongest->getTransactionType() == $type_update) {
|
||||||
$show_lines = true;
|
$show_lines = true;
|
||||||
}
|
}
|
||||||
|
@ -772,7 +663,7 @@ final class DifferentialTransactionEditor
|
||||||
$update_xaction = null;
|
$update_xaction = null;
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
$update_xaction = $xaction;
|
$update_xaction = $xaction;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1053,7 +944,7 @@ final class DifferentialTransactionEditor
|
||||||
return $query->executeOne();
|
return $query->executeOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function requireDiff($phid, $need_changesets = false) {
|
public function requireDiff($phid, $need_changesets = false) {
|
||||||
$diff = $this->loadDiff($phid, $need_changesets);
|
$diff = $this->loadDiff($phid, $need_changesets);
|
||||||
if (!$diff) {
|
if (!$diff) {
|
||||||
throw new Exception(pht('Diff "%s" does not exist!', $phid));
|
throw new Exception(pht('Diff "%s" does not exist!', $phid));
|
||||||
|
@ -1274,7 +1165,7 @@ final class DifferentialTransactionEditor
|
||||||
$has_update = false;
|
$has_update = false;
|
||||||
$has_commit = false;
|
$has_commit = false;
|
||||||
|
|
||||||
$type_update = DifferentialTransaction::TYPE_UPDATE;
|
$type_update = DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE;
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
if ($xaction->getTransactionType() != $type_update) {
|
if ($xaction->getTransactionType() != $type_update) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1721,27 +1612,6 @@ final class DifferentialTransactionEditor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateRevisionLineCounts(
|
|
||||||
DifferentialRevision $revision,
|
|
||||||
DifferentialDiff $diff) {
|
|
||||||
|
|
||||||
$revision->setLineCount($diff->getLineCount());
|
|
||||||
|
|
||||||
$conn = $revision->establishConnection('r');
|
|
||||||
|
|
||||||
$row = queryfx_one(
|
|
||||||
$conn,
|
|
||||||
'SELECT SUM(addLines) A, SUM(delLines) D FROM %T
|
|
||||||
WHERE diffID = %d',
|
|
||||||
id(new DifferentialChangeset())->getTableName(),
|
|
||||||
$diff->getID());
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$revision->setAddedLineCount((int)$row['A']);
|
|
||||||
$revision->setRemovedLineCount((int)$row['D']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function requireReviewers(DifferentialRevision $revision) {
|
private function requireReviewers(DifferentialRevision $revision) {
|
||||||
if ($revision->hasAttachedReviewers()) {
|
if ($revision->hasAttachedReviewers()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -278,8 +278,10 @@ final class DifferentialDiffExtractionEngine extends Phobject {
|
||||||
->setNewValue($revision->getModernRevisionStatus());
|
->setNewValue($revision->getModernRevisionStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$type_update = DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE;
|
||||||
|
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
->setTransactionType($type_update)
|
||||||
->setIgnoreOnNoEffect(true)
|
->setIgnoreOnNoEffect(true)
|
||||||
->setNewValue($new_diff->getPHID())
|
->setNewValue($new_diff->getPHID())
|
||||||
->setMetadataValue('isCommitUpdate', true);
|
->setMetadataValue('isCommitUpdate', true);
|
||||||
|
|
|
@ -22,14 +22,14 @@ final class PhabricatorDifferentialRevisionTestDataGenerator
|
||||||
$revision->setTestPlan($this->generateDescription());
|
$revision->setTestPlan($this->generateDescription());
|
||||||
|
|
||||||
$diff = $this->generateDiff($author);
|
$diff = $this->generateDiff($author);
|
||||||
|
$type_update = DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE;
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$xactions[] = id(new DifferentialTransaction())
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
->setTransactionType($type_update)
|
||||||
->setNewValue($diff->getPHID());
|
->setNewValue($diff->getPHID());
|
||||||
|
|
||||||
|
|
||||||
id(new DifferentialTransactionEditor())
|
id(new DifferentialTransactionEditor())
|
||||||
->setActor($author)
|
->setActor($author)
|
||||||
->setContentSource($this->getLipsumContentSource())
|
->setContentSource($this->getLipsumContentSource())
|
||||||
|
|
|
@ -6,7 +6,6 @@ final class DifferentialTransaction
|
||||||
private $isCommandeerSideEffect;
|
private $isCommandeerSideEffect;
|
||||||
|
|
||||||
const TYPE_INLINE = 'differential:inline';
|
const TYPE_INLINE = 'differential:inline';
|
||||||
const TYPE_UPDATE = 'differential:update';
|
|
||||||
const TYPE_ACTION = 'differential:action';
|
const TYPE_ACTION = 'differential:action';
|
||||||
|
|
||||||
const MAILTAG_REVIEWERS = 'differential-reviewers';
|
const MAILTAG_REVIEWERS = 'differential-reviewers';
|
||||||
|
@ -75,18 +74,6 @@ final class DifferentialTransaction
|
||||||
$new = $this->getNewValue();
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
// Older versions of this transaction have an ID for the new value,
|
|
||||||
// and/or do not record the old value. Only hide the transaction if
|
|
||||||
// the new value is a PHID, indicating that this is a newer style
|
|
||||||
// transaction.
|
|
||||||
if ($old === null) {
|
|
||||||
if (phid_get_type($new) == DifferentialDiffPHIDType::TYPECONST) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE:
|
case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE:
|
||||||
// Don't hide the initial "X requested review: ..." transaction from
|
// Don't hide the initial "X requested review: ..." transaction from
|
||||||
// mail or feed even when it occurs during creation. We need this
|
// mail or feed even when it occurs during creation. We need this
|
||||||
|
@ -139,11 +126,6 @@ final class DifferentialTransaction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
if ($new) {
|
|
||||||
$phids[] = $new;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $phids;
|
return $phids;
|
||||||
|
@ -153,8 +135,6 @@ final class DifferentialTransaction
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
return 3;
|
return 3;
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getActionStrength();
|
return parent::getActionStrength();
|
||||||
|
@ -165,13 +145,6 @@ final class DifferentialTransaction
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_INLINE:
|
case self::TYPE_INLINE:
|
||||||
return pht('Commented On');
|
return pht('Commented On');
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
if ($old === null) {
|
|
||||||
return pht('Request');
|
|
||||||
} else {
|
|
||||||
return pht('Updated');
|
|
||||||
}
|
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
$map = array(
|
$map = array(
|
||||||
DifferentialAction::ACTION_ACCEPT => pht('Accepted'),
|
DifferentialAction::ACTION_ACCEPT => pht('Accepted'),
|
||||||
|
@ -209,7 +182,7 @@ final class DifferentialTransaction
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
$old = $this->getOldValue();
|
$old = $this->getOldValue();
|
||||||
if ($old === null) {
|
if ($old === null) {
|
||||||
$tags[] = self::MAILTAG_REVIEW_REQUEST;
|
$tags[] = self::MAILTAG_REVIEW_REQUEST;
|
||||||
|
@ -248,28 +221,6 @@ final class DifferentialTransaction
|
||||||
return pht(
|
return pht(
|
||||||
'%s added inline comments.',
|
'%s added inline comments.',
|
||||||
$author_handle);
|
$author_handle);
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
if ($this->getMetadataValue('isCommitUpdate')) {
|
|
||||||
return pht(
|
|
||||||
'This revision was automatically updated to reflect the '.
|
|
||||||
'committed changes.');
|
|
||||||
} else if ($new) {
|
|
||||||
// TODO: Migrate to PHIDs and use handles here?
|
|
||||||
if (phid_get_type($new) == DifferentialDiffPHIDType::TYPECONST) {
|
|
||||||
return pht(
|
|
||||||
'%s updated this revision to %s.',
|
|
||||||
$author_handle,
|
|
||||||
$this->renderHandleLink($new));
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s updated this revision.',
|
|
||||||
$author_handle);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s updated this revision.',
|
|
||||||
$author_handle);
|
|
||||||
}
|
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
switch ($new) {
|
switch ($new) {
|
||||||
case DifferentialAction::ACTION_CLOSE:
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
|
@ -347,11 +298,6 @@ final class DifferentialTransaction
|
||||||
'%s added inline comments to %s.',
|
'%s added inline comments to %s.',
|
||||||
$author_link,
|
$author_link,
|
||||||
$object_link);
|
$object_link);
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
return pht(
|
|
||||||
'%s updated the diff for %s.',
|
|
||||||
$author_link,
|
|
||||||
$object_link);
|
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
switch ($new) {
|
switch ($new) {
|
||||||
case DifferentialAction::ACTION_ACCEPT:
|
case DifferentialAction::ACTION_ACCEPT:
|
||||||
|
@ -462,8 +408,6 @@ final class DifferentialTransaction
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_INLINE:
|
case self::TYPE_INLINE:
|
||||||
return 'fa-comment';
|
return 'fa-comment';
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
return 'fa-refresh';
|
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
switch ($this->getNewValue()) {
|
switch ($this->getNewValue()) {
|
||||||
case DifferentialAction::ACTION_CLOSE:
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
|
@ -526,8 +470,6 @@ final class DifferentialTransaction
|
||||||
|
|
||||||
public function getColor() {
|
public function getColor() {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_UPDATE:
|
|
||||||
return PhabricatorTransactions::COLOR_SKY;
|
|
||||||
case self::TYPE_ACTION:
|
case self::TYPE_ACTION:
|
||||||
switch ($this->getNewValue()) {
|
switch ($this->getNewValue()) {
|
||||||
case DifferentialAction::ACTION_CLOSE:
|
case DifferentialAction::ACTION_CLOSE:
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DifferentialRevisionUpdateTransaction
|
||||||
|
extends DifferentialRevisionTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'differential:update';
|
||||||
|
const EDITKEY = 'update';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getActiveDiffPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$should_review = $this->shouldRequestReviewAfterUpdate($object);
|
||||||
|
if ($should_review) {
|
||||||
|
$object->setModernRevisionStatus(
|
||||||
|
DifferentialRevisionStatus::NEEDS_REVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = $this->getEditor();
|
||||||
|
$diff = $editor->requireDiff($value);
|
||||||
|
|
||||||
|
$this->updateRevisionLineCounts($object, $diff);
|
||||||
|
|
||||||
|
$object->setRepositoryPHID($diff->getRepositoryPHID());
|
||||||
|
$object->setActiveDiffPHID($diff->getPHID());
|
||||||
|
$object->attachActiveDiff($diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function shouldRequestReviewAfterUpdate($object) {
|
||||||
|
if ($this->isCommitUpdate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$should_update =
|
||||||
|
$object->isNeedsRevision() ||
|
||||||
|
$object->isChangePlanned() ||
|
||||||
|
$object->isAbandoned();
|
||||||
|
if ($should_update) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyExternalEffects($object, $value) {
|
||||||
|
$editor = $this->getEditor();
|
||||||
|
$diff = $editor->requireDiff($value);
|
||||||
|
|
||||||
|
// TODO: This can race with diff updates, particularly those from
|
||||||
|
// Harbormaster. See discussion in T8650.
|
||||||
|
$diff->setRevisionID($object->getID());
|
||||||
|
$diff->save();
|
||||||
|
|
||||||
|
// If there are any outstanding buildables for this diff, tell
|
||||||
|
// Harbormaster that their containers need to be updated. This is
|
||||||
|
// common, because `arc` creates buildables so it can upload lint
|
||||||
|
// and unit results.
|
||||||
|
|
||||||
|
$buildables = id(new HarbormasterBuildableQuery())
|
||||||
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
|
->withManualBuildables(false)
|
||||||
|
->withBuildablePHIDs(array($diff->getPHID()))
|
||||||
|
->execute();
|
||||||
|
foreach ($buildables as $buildable) {
|
||||||
|
$buildable->sendMessage(
|
||||||
|
$this->getActor(),
|
||||||
|
HarbormasterMessageType::BUILDABLE_CONTAINER,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColor() {
|
||||||
|
return 'sky';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
return 'fa-refresh';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActionName() {
|
||||||
|
if ($this->isCreateTransaction()) {
|
||||||
|
return pht('Request');
|
||||||
|
} else {
|
||||||
|
return pht('Updated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActionStrength() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
if ($this->isCommitUpdate()) {
|
||||||
|
return pht(
|
||||||
|
'This revision was automatically updated to reflect the '.
|
||||||
|
'committed changes.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Very, very old update transactions did not have a new value or
|
||||||
|
// did not use a diff PHID as a new value. This was changed years ago,
|
||||||
|
// but wasn't migrated. We might consider migrating if this causes issues.
|
||||||
|
|
||||||
|
return pht(
|
||||||
|
'%s updated this revision to %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderNewHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
return pht(
|
||||||
|
'%s updated the diff for %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
$diff_phid = null;
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$diff_phid = $xaction->getNewValue();
|
||||||
|
|
||||||
|
$diff = id(new DifferentialDiffQuery())
|
||||||
|
->withPHIDs(array($diff_phid))
|
||||||
|
->setViewer($this->getActor())
|
||||||
|
->executeOne();
|
||||||
|
if (!$diff) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'Specified diff ("%s") does not exist.',
|
||||||
|
$diff_phid),
|
||||||
|
$xaction);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($diff->getRevisionID()) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'You can not update this revision with the specified diff ("%s") '.
|
||||||
|
'because the diff is already attached to another revision.',
|
||||||
|
$diff_phid),
|
||||||
|
$xaction);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$diff_phid && !$object->getActiveDiffPHID()) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'You must specify an initial diff when creating a revision.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCommitUpdate() {
|
||||||
|
return (bool)$this->getMetadataValue('isCommitUpdate');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateRevisionLineCounts(
|
||||||
|
DifferentialRevision $revision,
|
||||||
|
DifferentialDiff $diff) {
|
||||||
|
|
||||||
|
$revision->setLineCount($diff->getLineCount());
|
||||||
|
|
||||||
|
$conn = $revision->establishConnection('r');
|
||||||
|
|
||||||
|
$row = queryfx_one(
|
||||||
|
$conn,
|
||||||
|
'SELECT SUM(addLines) A, SUM(delLines) D FROM %T
|
||||||
|
WHERE diffID = %d',
|
||||||
|
id(new DifferentialChangeset())->getTableName(),
|
||||||
|
$diff->getID());
|
||||||
|
|
||||||
|
if ($row) {
|
||||||
|
$revision->setAddedLineCount((int)$row['A']);
|
||||||
|
$revision->setRemovedLineCount((int)$row['D']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ final class ReleephDiffChurnFieldSpecification
|
||||||
case PhabricatorTransactions::TYPE_COMMENT:
|
case PhabricatorTransactions::TYPE_COMMENT:
|
||||||
$comments++;
|
$comments++;
|
||||||
break;
|
break;
|
||||||
case DifferentialTransaction::TYPE_UPDATE:
|
case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
|
||||||
$updates++;
|
$updates++;
|
||||||
break;
|
break;
|
||||||
case DifferentialTransaction::TYPE_ACTION:
|
case DifferentialTransaction::TYPE_ACTION:
|
||||||
|
|
Loading…
Reference in a new issue