Differential D17020 Diff 41026 src/applications/release/changes/actions/ReleaseChangeRequestMarkStateAction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/release/changes/actions/ReleaseChangeRequestMarkStateAction.php
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
<?php | |||||
final class ReleaseChangeRequestMarkStateAction | |||||
extends ReleaseChangeRequestAction { | |||||
private $name; | |||||
private $icon; | |||||
private $key; | |||||
const ACTION_REJECT = 'reject'; | |||||
const ACTION_MARK_MERGED = 'markmerged'; | |||||
public function getPrompt(ReleaseChangeRequest $change) { | |||||
return pht('Set this Change Request as %s?', ReleaseChangeRequest::translateStatusName($this->getChangeStatus())); | |||||
} | |||||
public function getFormTitle(ReleaseChangeRequest $change) { | |||||
return pht('Mark as %s', ReleaseChangeRequest::translateStatusName($this->getChangeStatus())); | |||||
} | |||||
public function act(ReleaseChangeRequest $change, AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | |||||
$xaction_type = ReleaseChangeRequestStateTransaction::TRANSACTIONTYPE; | |||||
$status = $this->getChangeStatus(); | |||||
$xaction = id(new ReleaseChangeRequestTransaction()) | |||||
->setTransactionType($xaction_type) | |||||
->setNewValue($status); | |||||
$editor = id(new ReleaseChangeRequestEditor()) | |||||
->setActor($viewer) | |||||
->setContentSourceFromRequest($request) | |||||
->setContinueOnNoEffect(true); | |||||
$editor->applyTransactions($change, array($xaction)); | |||||
return $change->getURI(); | |||||
} | |||||
private function getChangeStatus() { | |||||
$statuses = array( | |||||
self::ACTION_REJECT => ReleaseChangeRequest::STATUS_REJECTED, | |||||
self::ACTION_MARK_MERGED => ReleaseChangeRequest::STATUS_INCLUDED, | |||||
); | |||||
$status = idx($statuses, $this->key); | |||||
if ($status) { | |||||
return $status; | |||||
} | |||||
throw new Exception( | |||||
pht('Status not found for action key %s', $action_key)); | |||||
} | |||||
public function setActionName($name) { | |||||
$this->name = $name; | |||||
return $this; | |||||
} | |||||
public function setActionIcon($icon) { | |||||
$this->icon = $icon; | |||||
return $this; | |||||
} | |||||
public function setActionKey($action_key) { | |||||
$this->key = $action_key; | |||||
return $this; | |||||
} | |||||
public function getActionName() { | |||||
return $this->name; | |||||
} | |||||
public function getActionIcon() { | |||||
return $this->icon; | |||||
} | |||||
public function getActionKey() { | |||||
return $this->key; | |||||
} | |||||
public function generateActions() { | |||||
return array( | |||||
id(new ReleaseChangeRequestMarkStateAction()) | |||||
->setActionName(pht('Reject')) | |||||
->setActionKey(self::ACTION_REJECT) | |||||
->setActionIcon('fa-times'), | |||||
// We should try to detect commits like with Revisions, and | |||||
// automatically mark a Change as Merged, but I'm not sure how complex | |||||
// that would be (And how scalable across Implmentations). | |||||
// Until then, I'd like to hide this option locally, and use my hack for | |||||
// T182 to do the merge. | |||||
// Actually, I think I'm just going to delete this, and offer it as an | |||||
// Extension for the happy few who want to try it. Preview FTW :-) | |||||
// Also replace the rest of the class with a non-generic ...RejectAction | |||||
id(new ReleaseChangeRequestMarkStateAction()) | |||||
->setActionName(pht('Mark as Merged')) | |||||
->setActionKey(self::ACTION_MARK_MERGED) | |||||
->setActionIcon('fa-check'), | |||||
); | |||||
} | |||||
} |