2012-07-16 20:49:06 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DifferentialCreateInlineConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.createinline';
|
|
|
|
}
|
2012-07-16 20:49:06 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2015-05-22 09:27:56 +02:00
|
|
|
return pht('Add an inline comment to a Differential revision.');
|
2012-07-16 20:49:06 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineParamTypes() {
|
2012-07-16 20:49:06 +02:00
|
|
|
return array(
|
|
|
|
'revisionID' => 'optional revisionid',
|
|
|
|
'diffID' => 'optional diffid',
|
|
|
|
'filePath' => 'required string',
|
|
|
|
'isNewFile' => 'required bool',
|
2012-07-17 21:06:18 +02:00
|
|
|
'lineNumber' => 'required int',
|
|
|
|
'lineLength' => 'optional int',
|
|
|
|
'content' => 'required string',
|
2012-07-16 20:49:06 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2012-07-16 20:49:06 +02:00
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineErrorTypes() {
|
2012-07-16 20:49:06 +02:00
|
|
|
return array(
|
2015-05-22 09:27:56 +02:00
|
|
|
'ERR-BAD-REVISION' => pht(
|
|
|
|
'Bad revision ID.'),
|
|
|
|
'ERR-BAD-DIFF' => pht(
|
|
|
|
'Bad diff ID, or diff does not belong to revision.'),
|
|
|
|
'ERR-NEED-DIFF' => pht(
|
|
|
|
'Neither revision ID nor diff ID was provided.'),
|
|
|
|
'ERR-NEED-FILE' => pht(
|
|
|
|
'A file path was not provided.'),
|
|
|
|
'ERR-BAD-FILE' => pht(
|
|
|
|
"Requested file doesn't exist in this revision."),
|
2012-07-16 20:49:06 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$rid = $request->getValue('revisionID');
|
|
|
|
$did = $request->getValue('diffID');
|
|
|
|
|
|
|
|
if ($rid) {
|
|
|
|
// Given both a revision and a diff, check that they match.
|
|
|
|
// Given only a revision, find the active diff.
|
2013-09-26 21:37:19 +02:00
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withIDs(array($rid))
|
|
|
|
->executeOne();
|
2012-07-16 20:49:06 +02:00
|
|
|
if (!$revision) {
|
|
|
|
throw new ConduitException('ERR-BAD-REVISION');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$did) { // did not!
|
|
|
|
$diff = $revision->loadActiveDiff();
|
|
|
|
$did = $diff->getID();
|
|
|
|
} else { // did too!
|
|
|
|
$diff = id(new DifferentialDiff())->load($did);
|
|
|
|
if (!$diff || $diff->getRevisionID() != $rid) {
|
|
|
|
throw new ConduitException('ERR-BAD-DIFF');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($did) {
|
|
|
|
// Given only a diff, find the parent revision.
|
|
|
|
$diff = id(new DifferentialDiff())->load($did);
|
|
|
|
if (!$diff) {
|
|
|
|
throw new ConduitException('ERR-BAD-DIFF');
|
|
|
|
}
|
|
|
|
$rid = $diff->getRevisionID();
|
|
|
|
} else {
|
|
|
|
// Given neither, bail.
|
|
|
|
throw new ConduitException('ERR-NEED-DIFF');
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = $request->getValue('filePath');
|
|
|
|
if (!$file) {
|
|
|
|
throw new ConduitException('ERR-NEED-FILE');
|
|
|
|
}
|
|
|
|
$changes = id(new DifferentialChangeset())->loadAllWhere(
|
|
|
|
'diffID = %d',
|
|
|
|
$did);
|
|
|
|
$cid = null;
|
|
|
|
foreach ($changes as $id => $change) {
|
|
|
|
if ($file == $change->getFilename()) {
|
|
|
|
$cid = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($cid == null) {
|
|
|
|
throw new ConduitException('ERR-BAD-FILE');
|
|
|
|
}
|
|
|
|
|
|
|
|
$inline = id(new DifferentialInlineComment())
|
|
|
|
->setRevisionID($rid)
|
|
|
|
->setChangesetID($cid)
|
|
|
|
->setAuthorPHID($request->getUser()->getPHID())
|
2012-07-17 21:06:18 +02:00
|
|
|
->setContent($request->getValue('content'))
|
2012-07-16 20:49:06 +02:00
|
|
|
->setIsNewFile($request->getValue('isNewFile'))
|
2012-07-17 21:06:18 +02:00
|
|
|
->setLineNumber($request->getValue('lineNumber'))
|
|
|
|
->setLineLength($request->getValue('lineLength', 0))
|
2012-07-16 20:49:06 +02:00
|
|
|
->save();
|
|
|
|
|
|
|
|
// Load everything again, just to be safe.
|
|
|
|
$changeset = id(new DifferentialChangeset())
|
|
|
|
->load($inline->getChangesetID());
|
2012-07-17 21:06:18 +02:00
|
|
|
return $this->buildInlineInfoDictionary($inline, $changeset);
|
2012-07-16 20:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|