mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-25 21:19:21 +01:00
Summary: Ref T7803. Ref T5873. I want to drive Conduit through more shared infrastructure, but can't currently add parameters automatically. Put a `getX()` around the `defineX()` methods so the parent can provide default behaviors. Also like 60% of methods don't define any special error types; don't require them to implement this method. I want to move away from this in general. Test Plan: - Ran `arc unit --everything`. - Called `conduit.query`. - Browsed Conduit UI. Reviewers: btrahan Reviewed By: btrahan Subscribers: hach-que, epriestley Maniphest Tasks: T5873, T7803 Differential Revision: https://secure.phabricator.com/D12380
100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
final class DiffusionCreateCommentConduitAPIMethod
|
|
extends DiffusionConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'diffusion.createcomment';
|
|
}
|
|
|
|
public function getMethodStatus() {
|
|
return self::METHOD_STATUS_DEPRECATED;
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return 'Add a comment to a Diffusion commit. By specifying an action of '.
|
|
'"concern", "accept", "resign", or "close", auditing actions can '.
|
|
'be triggered. Defaults to "comment".';
|
|
}
|
|
|
|
protected function defineParamTypes() {
|
|
return array(
|
|
'phid' => 'required string',
|
|
'action' => 'optional string',
|
|
'message' => 'required string',
|
|
'silent' => 'optional bool',
|
|
);
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'bool';
|
|
}
|
|
|
|
protected function defineErrorTypes() {
|
|
return array(
|
|
'ERR_BAD_COMMIT' => 'No commit found with that PHID',
|
|
'ERR_BAD_ACTION' => 'Invalid action type',
|
|
'ERR_MISSING_MESSAGE' => 'Message is required',
|
|
);
|
|
}
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
$commit_phid = $request->getValue('phid');
|
|
$commit = id(new DiffusionCommitQuery())
|
|
->setViewer($request->getUser())
|
|
->withPHIDs(array($commit_phid))
|
|
->needAuditRequests(true)
|
|
->executeOne();
|
|
if (!$commit) {
|
|
throw new ConduitException('ERR_BAD_COMMIT');
|
|
}
|
|
|
|
$message = trim($request->getValue('message'));
|
|
if (!$message) {
|
|
throw new ConduitException('ERR_MISSING_MESSAGE');
|
|
}
|
|
|
|
$action = $request->getValue('action');
|
|
if (!$action) {
|
|
$action = PhabricatorAuditActionConstants::COMMENT;
|
|
}
|
|
|
|
// Disallow ADD_CCS, ADD_AUDITORS forever.
|
|
if (!in_array($action, array(
|
|
PhabricatorAuditActionConstants::CONCERN,
|
|
PhabricatorAuditActionConstants::ACCEPT,
|
|
PhabricatorAuditActionConstants::COMMENT,
|
|
PhabricatorAuditActionConstants::RESIGN,
|
|
PhabricatorAuditActionConstants::CLOSE,
|
|
))) {
|
|
throw new ConduitException('ERR_BAD_ACTION');
|
|
}
|
|
|
|
$xactions = array();
|
|
|
|
if ($action != PhabricatorAuditActionConstants::COMMENT) {
|
|
$xactions[] = id(new PhabricatorAuditTransaction())
|
|
->setTransactionType(PhabricatorAuditActionConstants::ACTION)
|
|
->setNewValue($action);
|
|
}
|
|
|
|
if (strlen($message)) {
|
|
$xactions[] = id(new PhabricatorAuditTransaction())
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
->attachComment(
|
|
id(new PhabricatorAuditTransactionComment())
|
|
->setCommitPHID($commit->getPHID())
|
|
->setContent($message));
|
|
}
|
|
|
|
id(new PhabricatorAuditEditor())
|
|
->setActor($request->getUser())
|
|
->setContentSourceFromConduitRequest($request)
|
|
->setDisableEmail($request->getValue('silent'))
|
|
->setContinueOnMissingFields(true)
|
|
->applyTransactions($commit, $xactions);
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|