[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class DifferentialConduitAPIMethod extends ConduitAPIMethod { 4 5 final public function getApplication() { 6 return PhabricatorApplication::getByClass( 7 'PhabricatorDifferentialApplication'); 8 } 9 10 protected function buildDiffInfoDictionary(DifferentialDiff $diff) { 11 $uri = '/differential/diff/'.$diff->getID().'/'; 12 $uri = PhabricatorEnv::getProductionURI($uri); 13 14 return array( 15 'id' => $diff->getID(), 16 'uri' => $uri, 17 ); 18 } 19 20 protected function buildInlineInfoDictionary( 21 DifferentialInlineComment $inline, 22 DifferentialChangeset $changeset = null) { 23 24 $file_path = null; 25 $diff_id = null; 26 if ($changeset) { 27 $file_path = $inline->getIsNewFile() 28 ? $changeset->getFilename() 29 : $changeset->getOldFile(); 30 31 $diff_id = $changeset->getDiffID(); 32 } 33 34 return array( 35 'id' => $inline->getID(), 36 'authorPHID' => $inline->getAuthorPHID(), 37 'filePath' => $file_path, 38 'isNewFile' => $inline->getIsNewFile(), 39 'lineNumber' => $inline->getLineNumber(), 40 'lineLength' => $inline->getLineLength(), 41 'diffID' => $diff_id, 42 'content' => $inline->getContent(), 43 ); 44 } 45 46 protected function applyFieldEdit( 47 ConduitAPIRequest $request, 48 DifferentialRevision $revision, 49 DifferentialDiff $diff, 50 array $fields, 51 $message) { 52 53 $viewer = $request->getUser(); 54 55 $field_list = PhabricatorCustomField::getObjectFields( 56 $revision, 57 DifferentialCustomField::ROLE_COMMITMESSAGEEDIT); 58 59 $field_list 60 ->setViewer($viewer) 61 ->readFieldsFromStorage($revision); 62 $field_map = mpull($field_list->getFields(), null, 'getFieldKeyForConduit'); 63 64 $xactions = array(); 65 66 $xactions[] = id(new DifferentialTransaction()) 67 ->setTransactionType(DifferentialTransaction::TYPE_UPDATE) 68 ->setNewValue($diff->getPHID()); 69 70 $values = $request->getValue('fields', array()); 71 foreach ($values as $key => $value) { 72 $field = idx($field_map, $key); 73 if (!$field) { 74 // NOTE: We're just ignoring fields we don't know about. This isn't 75 // ideal, but the way the workflow currently works involves us getting 76 // several read-only fields, like the revision ID field, which we should 77 // just skip. 78 continue; 79 } 80 81 $role = PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS; 82 if (!$field->shouldEnableForRole($role)) { 83 continue; 84 } 85 86 // TODO: This is fairly similar to PhabricatorCustomField's 87 // buildFieldTransactionsFromRequest() method, but that's currently not 88 // easy to reuse. 89 90 $transaction_type = $field->getApplicationTransactionType(); 91 $xaction = id(new DifferentialTransaction()) 92 ->setTransactionType($transaction_type); 93 94 if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) { 95 // For TYPE_CUSTOMFIELD transactions only, we provide the old value 96 // as an input. 97 $old_value = $field->getOldValueForApplicationTransactions(); 98 $xaction->setOldValue($old_value); 99 } 100 101 // The transaction itself will be validated so this is somewhat 102 // redundant, but this validator will sometimes give us a better error 103 // message or a better reaction to a bad value type. 104 $field->validateCommitMessageValue($value); 105 $field->readValueFromCommitMessage($value); 106 107 $xaction 108 ->setNewValue($field->getNewValueForApplicationTransactions()); 109 110 if ($transaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) { 111 // For TYPE_CUSTOMFIELD transactions, add the field key in metadata. 112 $xaction->setMetadataValue('customfield:key', $field->getFieldKey()); 113 } 114 115 $metadata = $field->getApplicationTransactionMetadata(); 116 foreach ($metadata as $meta_key => $meta_value) { 117 $xaction->setMetadataValue($meta_key, $meta_value); 118 } 119 120 $xactions[] = $xaction; 121 } 122 123 $message = $request->getValue('message'); 124 if (strlen($message)) { 125 // This is a little awkward, and should maybe move inside the transaction 126 // editor. It largely exists for legacy reasons. 127 $first_line = head(phutil_split_lines($message, false)); 128 $diff->setDescription($first_line); 129 $diff->save(); 130 131 $xactions[] = id(new DifferentialTransaction()) 132 ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 133 ->attachComment( 134 id(new DifferentialTransactionComment()) 135 ->setContent($message)); 136 } 137 138 $editor = id(new DifferentialTransactionEditor()) 139 ->setActor($viewer) 140 ->setContentSourceFromConduitRequest($request) 141 ->setContinueOnNoEffect(true) 142 ->setContinueOnMissingFields(true); 143 144 $editor->applyTransactions($revision, $xactions); 145 } 146 147 protected function loadCustomFieldsForRevisions( 148 PhabricatorUser $viewer, 149 array $revisions) { 150 assert_instances_of($revisions, 'DifferentialRevision'); 151 152 $results = array(); 153 foreach ($revisions as $revision) { 154 // TODO: This is inefficient and issues a query for each object. 155 $field_list = PhabricatorCustomField::getObjectFields( 156 $revision, 157 PhabricatorCustomField::ROLE_CONDUIT); 158 159 $field_list 160 ->setViewer($viewer) 161 ->readFieldsFromStorage($revision); 162 163 foreach ($field_list->getFields() as $field) { 164 $field_key = $field->getFieldKeyForConduit(); 165 $value = $field->getConduitDictionaryValue(); 166 $results[$revision->getPHID()][$field_key] = $value; 167 } 168 } 169 170 return $results; 171 } 172 173 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |