2012-06-20 21:35:04 +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
|
|
|
abstract class DifferentialConduitAPIMethod extends ConduitAPIMethod {
|
2012-06-20 21:35:04 +02:00
|
|
|
|
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 public function getApplication() {
|
2013-03-13 15:09:05 +01:00
|
|
|
return PhabricatorApplication::getByClass(
|
2014-07-23 02:03:09 +02:00
|
|
|
'PhabricatorDifferentialApplication');
|
2013-03-13 15:09:05 +01:00
|
|
|
}
|
|
|
|
|
2012-06-20 21:35:04 +02:00
|
|
|
protected function buildDiffInfoDictionary(DifferentialDiff $diff) {
|
|
|
|
$uri = '/differential/diff/'.$diff->getID().'/';
|
|
|
|
$uri = PhabricatorEnv::getProductionURI($uri);
|
|
|
|
|
|
|
|
return array(
|
2015-01-30 19:31:39 +01:00
|
|
|
'id' => $diff->getID(),
|
|
|
|
'phid' => $diff->getPHID(),
|
|
|
|
'uri' => $uri,
|
2012-06-20 21:35:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-07-17 21:06:18 +02:00
|
|
|
protected function buildInlineInfoDictionary(
|
|
|
|
DifferentialInlineComment $inline,
|
|
|
|
DifferentialChangeset $changeset = null) {
|
|
|
|
|
|
|
|
$file_path = null;
|
|
|
|
$diff_id = null;
|
|
|
|
if ($changeset) {
|
|
|
|
$file_path = $inline->getIsNewFile()
|
|
|
|
? $changeset->getFilename()
|
|
|
|
: $changeset->getOldFile();
|
|
|
|
|
|
|
|
$diff_id = $changeset->getDiffID();
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'id' => $inline->getID(),
|
|
|
|
'authorPHID' => $inline->getAuthorPHID(),
|
|
|
|
'filePath' => $file_path,
|
|
|
|
'isNewFile' => $inline->getIsNewFile(),
|
|
|
|
'lineNumber' => $inline->getLineNumber(),
|
|
|
|
'lineLength' => $inline->getLineLength(),
|
|
|
|
'diffID' => $diff_id,
|
|
|
|
'content' => $inline->getContent(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-03-08 20:21:38 +01:00
|
|
|
protected function applyFieldEdit(
|
|
|
|
ConduitAPIRequest $request,
|
|
|
|
DifferentialRevision $revision,
|
|
|
|
DifferentialDiff $diff,
|
|
|
|
array $fields,
|
|
|
|
$message) {
|
|
|
|
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$revision,
|
|
|
|
DifferentialCustomField::ROLE_COMMITMESSAGEEDIT);
|
|
|
|
|
|
|
|
$field_list
|
|
|
|
->setViewer($viewer)
|
|
|
|
->readFieldsFromStorage($revision);
|
|
|
|
$field_map = mpull($field_list->getFields(), null, 'getFieldKeyForConduit');
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
|
|
|
->setNewValue($diff->getPHID());
|
|
|
|
|
|
|
|
$values = $request->getValue('fields', array());
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$field = idx($field_map, $key);
|
|
|
|
if (!$field) {
|
|
|
|
// NOTE: We're just ignoring fields we don't know about. This isn't
|
|
|
|
// ideal, but the way the workflow currently works involves us getting
|
|
|
|
// several read-only fields, like the revision ID field, which we should
|
|
|
|
// just skip.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$role = PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS;
|
|
|
|
if (!$field->shouldEnableForRole($role)) {
|
2014-03-11 23:36:03 +01:00
|
|
|
continue;
|
2014-03-08 20:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This is fairly similar to PhabricatorCustomField's
|
|
|
|
// buildFieldTransactionsFromRequest() method, but that's currently not
|
|
|
|
// easy to reuse.
|
|
|
|
|
|
|
|
$transaction_type = $field->getApplicationTransactionType();
|
|
|
|
$xaction = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($transaction_type);
|
|
|
|
|
|
|
|
if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) {
|
|
|
|
// For TYPE_CUSTOMFIELD transactions only, we provide the old value
|
|
|
|
// as an input.
|
|
|
|
$old_value = $field->getOldValueForApplicationTransactions();
|
|
|
|
$xaction->setOldValue($old_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transaction itself will be validated so this is somewhat
|
|
|
|
// redundant, but this validator will sometimes give us a better error
|
|
|
|
// message or a better reaction to a bad value type.
|
|
|
|
$field->validateCommitMessageValue($value);
|
|
|
|
$field->readValueFromCommitMessage($value);
|
|
|
|
|
|
|
|
$xaction
|
|
|
|
->setNewValue($field->getNewValueForApplicationTransactions());
|
|
|
|
|
|
|
|
if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) {
|
|
|
|
// For TYPE_CUSTOMFIELD transactions, add the field key in metadata.
|
|
|
|
$xaction->setMetadataValue('customfield:key', $field->getFieldKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
$metadata = $field->getApplicationTransactionMetadata();
|
|
|
|
foreach ($metadata as $meta_key => $meta_value) {
|
|
|
|
$xaction->setMetadataValue($meta_key, $meta_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $request->getValue('message');
|
|
|
|
if (strlen($message)) {
|
|
|
|
// This is a little awkward, and should maybe move inside the transaction
|
|
|
|
// editor. It largely exists for legacy reasons.
|
|
|
|
$first_line = head(phutil_split_lines($message, false));
|
|
|
|
$diff->setDescription($first_line);
|
|
|
|
$diff->save();
|
|
|
|
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new DifferentialTransactionComment())
|
|
|
|
->setContent($message));
|
|
|
|
}
|
|
|
|
|
|
|
|
$editor = id(new DifferentialTransactionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromConduitRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true);
|
|
|
|
|
|
|
|
$editor->applyTransactions($revision, $xactions);
|
|
|
|
}
|
2012-07-17 21:06:18 +02:00
|
|
|
|
2014-03-09 19:23:55 +01:00
|
|
|
protected function loadCustomFieldsForRevisions(
|
|
|
|
PhabricatorUser $viewer,
|
|
|
|
array $revisions) {
|
|
|
|
assert_instances_of($revisions, 'DifferentialRevision');
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
// TODO: This is inefficient and issues a query for each object.
|
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$revision,
|
|
|
|
PhabricatorCustomField::ROLE_CONDUIT);
|
|
|
|
|
|
|
|
$field_list
|
|
|
|
->setViewer($viewer)
|
|
|
|
->readFieldsFromStorage($revision);
|
|
|
|
|
|
|
|
foreach ($field_list->getFields() as $field) {
|
|
|
|
$field_key = $field->getFieldKeyForConduit();
|
|
|
|
$value = $field->getConduitDictionaryValue();
|
|
|
|
$results[$revision->getPHID()][$field_key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:35:04 +02:00
|
|
|
}
|