mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Update differential.close
to use DifferentialTransactionEditor
Summary: Ref T2222. Straightforward update to new stuff. Test Plan: - Tried to close an uncloseable revision. - Closed a closeable revision. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8425
This commit is contained in:
parent
3dc9afa28d
commit
75514cc0f7
3 changed files with 24 additions and 26 deletions
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group conduit
|
|
||||||
*/
|
|
||||||
abstract class ConduitAPI_differential_Method extends ConduitAPIMethod {
|
abstract class ConduitAPI_differential_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
public function getApplication() {
|
public function getApplication() {
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group conduit
|
|
||||||
*/
|
|
||||||
final class ConduitAPI_differential_close_Method
|
final class ConduitAPI_differential_close_Method
|
||||||
extends ConduitAPIMethod {
|
extends ConduitAPI_differential_Method {
|
||||||
|
|
||||||
public function getMethodDescription() {
|
public function getMethodDescription() {
|
||||||
return "Close a Differential revision.";
|
return pht("Close a Differential revision.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function defineParamTypes() {
|
public function defineParamTypes() {
|
||||||
|
@ -27,40 +24,34 @@ final class ConduitAPI_differential_close_Method
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$viewer = $request->getUser();
|
||||||
$id = $request->getValue('revisionID');
|
$id = $request->getValue('revisionID');
|
||||||
|
|
||||||
$revision = id(new DifferentialRevisionQuery())
|
$revision = id(new DifferentialRevisionQuery())
|
||||||
->withIDs(array($id))
|
->withIDs(array($id))
|
||||||
->setViewer($request->getUser())
|
->setViewer($viewer)
|
||||||
->needRelationships(true)
|
|
||||||
->needReviewerStatus(true)
|
->needReviewerStatus(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$revision) {
|
if (!$revision) {
|
||||||
throw new ConduitException('ERR_NOT_FOUND');
|
throw new ConduitException('ERR_NOT_FOUND');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($revision->getStatus() == ArcanistDifferentialRevisionStatus::CLOSED) {
|
$xactions = array();
|
||||||
// This can occur if someone runs 'close-revision' and hits a race, or
|
$xactions[] = id(new DifferentialTransaction())
|
||||||
// they have a remote hook installed but don't have the
|
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
||||||
// 'remote_hook_installed' flag set, or similar. In any case, just treat
|
->setNewValue(DifferentialAction::ACTION_CLOSE);
|
||||||
// it as a no-op rather than adding another "X closed this revision"
|
|
||||||
// message to the revision comments.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$content_source = PhabricatorContentSource::newForSource(
|
$content_source = PhabricatorContentSource::newForSource(
|
||||||
PhabricatorContentSource::SOURCE_CONDUIT,
|
PhabricatorContentSource::SOURCE_CONDUIT,
|
||||||
array());
|
array());
|
||||||
|
|
||||||
$editor = new DifferentialCommentEditor(
|
$editor = id(new DifferentialTransactionEditor())
|
||||||
$revision,
|
->setActor($viewer)
|
||||||
DifferentialAction::ACTION_CLOSE);
|
->setContentSourceFromConduitRequest($request)
|
||||||
$editor->setContentSource($content_source);
|
->setContinueOnMissingFields(true)
|
||||||
$editor->setActor($request->getUser());
|
->setContinueOnNoEffect(true);
|
||||||
$editor->save();
|
|
||||||
|
|
||||||
$revision->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
|
$editor->applyTransactions($revision, $xactions);
|
||||||
$revision->save();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -450,6 +450,16 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
PhabricatorContentSource::newFromRequest($request));
|
PhabricatorContentSource::newFromRequest($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setContentSourceFromConduitRequest(
|
||||||
|
ConduitAPIRequest $request) {
|
||||||
|
|
||||||
|
$content_source = PhabricatorContentSource::newForSource(
|
||||||
|
PhabricatorContentSource::SOURCE_CONDUIT,
|
||||||
|
array());
|
||||||
|
|
||||||
|
return $this->setContentSource($content_source);
|
||||||
|
}
|
||||||
|
|
||||||
public function getContentSource() {
|
public function getContentSource() {
|
||||||
return $this->contentSource;
|
return $this->contentSource;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue