Differential D17114 Diff 41157 src/applications/differential/xaction/DifferentialRevisionReviewTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/xaction/DifferentialRevisionReviewTransaction.php
- This file was copied from src/applications/differential/xaction/DifferentialRevisionActionTransaction.php.
<?php | <?php | ||||
abstract class DifferentialRevisionActionTransaction | abstract class DifferentialRevisionReviewTransaction | ||||
extends DifferentialRevisionTransactionType { | extends DifferentialRevisionActionTransaction { | ||||
final public function getRevisionActionKey() { | protected function getRevisionActionGroupKey() { | ||||
return $this->getPhobjectClassConstant('ACTIONKEY', 32); | return DifferentialRevisionEditEngine::ACTIONGROUP_REVIEW; | ||||
} | |||||
public function isActionAvailable($object, PhabricatorUser $viewer) { | |||||
try { | |||||
$this->validateAction($object, $viewer); | |||||
return true; | |||||
} catch (Exception $ex) { | |||||
return false; | |||||
} | |||||
} | |||||
abstract protected function validateAction($object, PhabricatorUser $viewer); | |||||
abstract protected function getRevisionActionLabel(); | |||||
protected function getRevisionActionDescription() { | |||||
return null; | |||||
} | |||||
public static function loadAllActions() { | |||||
return id(new PhutilClassMapQuery()) | |||||
->setAncestorClass(__CLASS__) | |||||
->setUniqueMethod('getRevisionActionKey') | |||||
->execute(); | |||||
} | |||||
protected function isViewerRevisionAuthor( | |||||
DifferentialRevision $revision, | |||||
PhabricatorUser $viewer) { | |||||
if (!$viewer->getPHID()) { | |||||
return false; | |||||
} | |||||
return ($viewer->getPHID() === $revision->getAuthorPHID()); | |||||
} | } | ||||
protected function isViewerAnyReviewer( | protected function isViewerAnyReviewer( | ||||
DifferentialRevision $revision, | DifferentialRevision $revision, | ||||
PhabricatorUser $viewer) { | PhabricatorUser $viewer) { | ||||
return ($this->getViewerReviewerStatus($revision, $viewer) !== null); | return ($this->getViewerReviewerStatus($revision, $viewer) !== null); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | foreach ($map as $dst_phid => $edge_data) { | ||||
} else { | } else { | ||||
$editor->addEdge($src_phid, $edge_type, $dst_phid, $edge_data); | $editor->addEdge($src_phid, $edge_type, $dst_phid, $edge_data); | ||||
} | } | ||||
} | } | ||||
$editor->save(); | $editor->save(); | ||||
} | } | ||||
public function newEditField( | |||||
DifferentialRevision $revision, | |||||
PhabricatorUser $viewer) { | |||||
$field = id(new PhabricatorApplyEditField()) | |||||
->setKey($this->getRevisionActionKey()) | |||||
->setTransactionType($this->getTransactionTypeConstant()) | |||||
->setValue(true); | |||||
if ($this->isActionAvailable($revision, $viewer)) { | |||||
$label = $this->getRevisionActionLabel(); | |||||
if ($label !== null) { | |||||
$field->setCommentActionLabel($label); | |||||
$description = $this->getRevisionActionDescription(); | |||||
$field->setActionDescription($description); | |||||
} | |||||
} | |||||
return $field; | |||||
} | |||||
public function validateTransactions($object, array $xactions) { | |||||
$errors = array(); | |||||
$actor = $this->getActor(); | |||||
$action_exception = null; | |||||
try { | |||||
$this->validateAction($object, $actor); | |||||
} catch (Exception $ex) { | |||||
$action_exception = $ex; | |||||
} | |||||
foreach ($xactions as $xaction) { | |||||
if ($action_exception) { | |||||
$errors[] = $this->newInvalidError( | |||||
$action_exception->getMessage(), | |||||
$xaction); | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} | } |