diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 689cccbd6a..7e7d87b05b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -121,6 +121,7 @@ phutil_register_library_map(array( 'ConduitAPI_conpherence_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_Method.php', 'ConduitAPI_conpherence_createthread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_createthread_Method.php', 'ConduitAPI_conpherence_querythread_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querythread_Method.php', + 'ConduitAPI_conpherence_querytransaction_Method' => 'applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php', 'ConduitAPI_daemon_launched_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php', 'ConduitAPI_daemon_log_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_log_Method.php', 'ConduitAPI_daemon_setstatus_Method' => 'applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php', @@ -1961,6 +1962,7 @@ phutil_register_library_map(array( 'ConduitAPI_conpherence_Method' => 'ConduitAPIMethod', 'ConduitAPI_conpherence_createthread_Method' => 'ConduitAPI_conpherence_Method', 'ConduitAPI_conpherence_querythread_Method' => 'ConduitAPI_conpherence_Method', + 'ConduitAPI_conpherence_querytransaction_Method' => 'ConduitAPI_conpherence_Method', 'ConduitAPI_daemon_launched_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_log_Method' => 'ConduitAPIMethod', 'ConduitAPI_daemon_setstatus_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php b/src/applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php new file mode 100644 index 0000000000..f6ea2ad1ef --- /dev/null +++ b/src/applications/conpherence/conduit/ConduitAPI_conpherence_querytransaction_Method.php @@ -0,0 +1,95 @@ + 'optional int', + 'threadPHID' => 'optional phid', + 'limit' => 'optional int', + 'offset' => 'optional int' + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR_USAGE_NO_THREAD_ID' => pht( + 'You must specify a thread id or thread phid to query transactions '. + 'from.') + ); + } + + protected function execute(ConduitAPIRequest $request) { + $user = $request->getUser(); + $thread_id = $request->getValue('threadID'); + $thread_phid = $request->getValue('threadPHID'); + $limit = $request->getValue('limit'); + $offset = $request->getValue('offset'); + + $query = id(new ConpherenceThreadQuery()) + ->setViewer($user); + + if ($thread_id) { + $query->withIDs(array($thread_id)); + } else if ($thread_phid) { + $query->withPHIDs(array($thread_phid)); + } else { + throw new ConduitException('ERR_USAGE_NO_THREAD_ID'); + } + + $conpherence = $query->executeOne(); + + $query = id(new ConpherenceTransactionQuery()) + ->setViewer($user) + ->withObjectPHIDs(array($conpherence->getPHID())) + ->setLimit($limit) + ->setOffset($offset); + + $transactions = $query->execute(); + + $data = array(); + foreach ($transactions as $transaction) { + $comment = null; + $comment_obj = $transaction->getComment(); + if ($comment_obj) { + $comment = $comment_obj->getContent(); + } + $title = null; + $title_obj = $transaction->getTitle(); + if ($title_obj) { + $title = $title_obj->getHTMLContent(); + } + $id = $transaction->getID(); + $data[$id] = array( + 'transactionID' => $id, + 'transactionType' => $transaction->getTransactionType(), + 'transactionTitle' => $title, + 'transactionComment' => $comment, + 'transactionOldValue' => $transaction->getOldValue(), + 'transactionNewValue' => $transaction->getNewValue(), + 'transactionMetadata' => $transaction->getMetadata(), + 'authorPHID' => $transaction->getAuthorPHID(), + 'dateCreated' => $transaction->getDateCreated(), + 'conpherenceID' => $conpherence->getID(), + 'conpherencePHID' => $conpherence->getPHID()); + } + return $data; + } +}