1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10: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:
epriestley 2014-03-07 08:09:59 -08:00
parent 3dc9afa28d
commit 75514cc0f7
3 changed files with 24 additions and 26 deletions

View file

@ -1,8 +1,5 @@
<?php
/**
* @group conduit
*/
abstract class ConduitAPI_differential_Method extends ConduitAPIMethod {
public function getApplication() {

View file

@ -1,13 +1,10 @@
<?php
/**
* @group conduit
*/
final class ConduitAPI_differential_close_Method
extends ConduitAPIMethod {
extends ConduitAPI_differential_Method {
public function getMethodDescription() {
return "Close a Differential revision.";
return pht("Close a Differential revision.");
}
public function defineParamTypes() {
@ -27,40 +24,34 @@ final class ConduitAPI_differential_close_Method
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$id = $request->getValue('revisionID');
$revision = id(new DifferentialRevisionQuery())
->withIDs(array($id))
->setViewer($request->getUser())
->needRelationships(true)
->setViewer($viewer)
->needReviewerStatus(true)
->executeOne();
if (!$revision) {
throw new ConduitException('ERR_NOT_FOUND');
}
if ($revision->getStatus() == ArcanistDifferentialRevisionStatus::CLOSED) {
// This can occur if someone runs 'close-revision' and hits a race, or
// they have a remote hook installed but don't have the
// 'remote_hook_installed' flag set, or similar. In any case, just treat
// it as a no-op rather than adding another "X closed this revision"
// message to the revision comments.
return;
}
$xactions = array();
$xactions[] = id(new DifferentialTransaction())
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
->setNewValue(DifferentialAction::ACTION_CLOSE);
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONDUIT,
array());
$editor = new DifferentialCommentEditor(
$revision,
DifferentialAction::ACTION_CLOSE);
$editor->setContentSource($content_source);
$editor->setActor($request->getUser());
$editor->save();
$editor = id(new DifferentialTransactionEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$revision->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
$revision->save();
$editor->applyTransactions($revision, $xactions);
return;
}

View file

@ -450,6 +450,16 @@ abstract class PhabricatorApplicationTransactionEditor
PhabricatorContentSource::newFromRequest($request));
}
public function setContentSourceFromConduitRequest(
ConduitAPIRequest $request) {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONDUIT,
array());
return $this->setContentSource($content_source);
}
public function getContentSource() {
return $this->contentSource;
}