Summary:
Ref T10537. For Nuance, I want to introduce new sources (like "GitHub" or "GitHub via Nuance" or something) but this needs to modularize eventually.
Split ContentSource apart so applications can add new content sources.
Test Plan:
This change has huge surface area, so I'll hold it until post-release. I think it's fairly safe (and if it does break anything, the breaks should be fatals, not anything subtle or difficult to fix), there's just no reason not to hold it for a few hours.
- Viewed new module page.
- Grepped for all removed functions/constants.
- Viewed some transactions.
- Hovered over timestamps to get content source details.
- Added a comment via Conduit.
- Added a comment via web.
- Ran `bin/storage upgrade --namespace XXXXX --no-quickstart -f` to re-run all historic migrations.
- Generated some objects with `bin/lipsum`.
- Ran a bulk job on some tasks.
- Ran unit tests.
{F1190182}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10537
Differential Revision: https://secure.phabricator.com/D15521
107 lines
2.9 KiB
PHP
107 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 pht(
|
|
'Add a comment to a Diffusion commit. By specifying an action '.
|
|
'of "%s", "%s", "%s", or "%s", auditing actions can '.
|
|
'be triggered. Defaults to "%s".',
|
|
'concern',
|
|
'accept',
|
|
'resign',
|
|
'close',
|
|
'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' => pht('No commit found with that PHID.'),
|
|
'ERR_BAD_ACTION' => pht('Invalid action type.'),
|
|
'ERR_MISSING_MESSAGE' => pht('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())
|
|
->setContentSource($request->newContentSource())
|
|
->setDisableEmail($request->getValue('silent'))
|
|
->setContinueOnMissingFields(true)
|
|
->applyTransactions($commit, $xactions);
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|