Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conpherence / conduit / ConpherenceQueryTransactionConduitAPIMethod.php
blob7de3b0678d67a839b1b8ada3305ed4fd9b4e58d7
1 <?php
3 final class ConpherenceQueryTransactionConduitAPIMethod
4 extends ConpherenceConduitAPIMethod {
6 public function getAPIMethodName() {
7 return 'conpherence.querytransaction';
10 public function getMethodDescription() {
11 return pht(
12 'Query for transactions for the logged in user within a specific '.
13 'Conpherence room. You can specify the room by ID or PHID. '.
14 'Otherwise, specify limit and offset to query the most recent '.
15 'transactions within the Conpherence room for the logged in user.');
18 protected function defineParamTypes() {
19 return array(
20 'roomID' => 'optional int',
21 'roomPHID' => 'optional phid',
22 'limit' => 'optional int',
23 'offset' => 'optional int',
27 protected function defineReturnType() {
28 return 'nonempty dict';
31 protected function defineErrorTypes() {
32 return array(
33 'ERR_USAGE_NO_ROOM_ID' => pht(
34 'You must specify a room id or room PHID to query transactions '.
35 'from.'),
39 protected function execute(ConduitAPIRequest $request) {
40 $user = $request->getUser();
41 $room_id = $request->getValue('roomID');
42 $room_phid = $request->getValue('roomPHID');
43 $limit = $request->getValue('limit');
44 $offset = $request->getValue('offset');
46 $query = id(new ConpherenceThreadQuery())
47 ->setViewer($user);
49 if ($room_id) {
50 $query->withIDs(array($room_id));
51 } else if ($room_phid) {
52 $query->withPHIDs(array($room_phid));
53 } else {
54 throw new ConduitException('ERR_USAGE_NO_ROOM_ID');
57 $conpherence = $query->executeOne();
59 $query = id(new ConpherenceTransactionQuery())
60 ->setViewer($user)
61 ->withObjectPHIDs(array($conpherence->getPHID()))
62 ->setLimit($limit)
63 ->setOffset($offset);
65 $transactions = $query->execute();
67 $data = array();
68 foreach ($transactions as $transaction) {
69 $comment = null;
70 $comment_obj = $transaction->getComment();
71 if ($comment_obj) {
72 $comment = $comment_obj->getContent();
74 $title = null;
75 $title_obj = $transaction->getTitle();
76 if ($title_obj) {
77 $title = $title_obj->getHTMLContent();
79 $id = $transaction->getID();
80 $data[$id] = array(
81 'transactionID' => $id,
82 'transactionType' => $transaction->getTransactionType(),
83 'transactionTitle' => $title,
84 'transactionComment' => $comment,
85 'transactionOldValue' => $transaction->getOldValue(),
86 'transactionNewValue' => $transaction->getNewValue(),
87 'transactionMetadata' => $transaction->getMetadata(),
88 'authorPHID' => $transaction->getAuthorPHID(),
89 'dateCreated' => $transaction->getDateCreated(),
90 'roomID' => $conpherence->getID(),
91 'roomPHID' => $conpherence->getPHID(),
94 return $data;