Path: blob/master/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php
12256 views
<?php12final class DifferentialQueryConduitAPIMethod3extends DifferentialConduitAPIMethod {45public function getAPIMethodName() {6return 'differential.query';7}89public function getMethodDescription() {10return pht('Query Differential revisions which match certain criteria.');11}1213public function getMethodStatus() {14return self::METHOD_STATUS_FROZEN;15}1617public function getMethodStatusDescription() {18return pht(19'This method is frozen and will eventually be deprecated. New code '.20'should use "differential.revision.search" instead.');21}2223protected function defineParamTypes() {24$hash_types = ArcanistDifferentialRevisionHash::getTypes();25$hash_const = $this->formatStringConstants($hash_types);2627$status_types = DifferentialLegacyQuery::getAllConstants();28$status_const = $this->formatStringConstants($status_types);2930$order_types = array(31DifferentialRevisionQuery::ORDER_MODIFIED,32DifferentialRevisionQuery::ORDER_CREATED,33);34$order_const = $this->formatStringConstants($order_types);3536return array(37'authors' => 'optional list<phid>',38'ccs' => 'optional list<phid>',39'reviewers' => 'optional list<phid>',40'paths' => 'unsupported',41'commitHashes' => 'optional list<pair<'.$hash_const.', string>>',42'status' => 'optional '.$status_const,43'order' => 'optional '.$order_const,44'limit' => 'optional uint',45'offset' => 'optional uint',46'ids' => 'optional list<uint>',47'phids' => 'optional list<phid>',48'subscribers' => 'optional list<phid>',49'responsibleUsers' => 'optional list<phid>',50'branches' => 'optional list<string>',51);52}5354protected function defineReturnType() {55return 'list<dict>';56}5758protected function defineErrorTypes() {59return array(60'ERR-INVALID-PARAMETER' => pht('Missing or malformed parameter.'),61);62}6364protected function execute(ConduitAPIRequest $request) {65$authors = $request->getValue('authors');66$ccs = $request->getValue('ccs');67$reviewers = $request->getValue('reviewers');68$status = $request->getValue('status');69$order = $request->getValue('order');70$path_pairs = $request->getValue('paths');71$commit_hashes = $request->getValue('commitHashes');72$limit = $request->getValue('limit');73$offset = $request->getValue('offset');74$ids = $request->getValue('ids');75$phids = $request->getValue('phids');76$subscribers = $request->getValue('subscribers');77$responsible_users = $request->getValue('responsibleUsers');78$branches = $request->getValue('branches');7980$query = id(new DifferentialRevisionQuery())81->setViewer($request->getUser());8283if ($authors) {84$query->withAuthors($authors);85}86if ($ccs) {87$query->withCCs($ccs);88}89if ($reviewers) {90$query->withReviewers($reviewers);91}9293if ($path_pairs) {94throw new Exception(95pht(96'Parameter "paths" to Conduit API method "differential.query" is '.97'no longer supported. Use the "paths" constraint to '.98'"differential.revision.search" instead. See T13639.'));99}100101if ($commit_hashes) {102$hash_types = ArcanistDifferentialRevisionHash::getTypes();103foreach ($commit_hashes as $info) {104list($type, $hash) = $info;105if (empty($type) ||106!in_array($type, $hash_types) ||107empty($hash)) {108throw new ConduitException('ERR-INVALID-PARAMETER');109}110}111$query->withCommitHashes($commit_hashes);112}113114if ($status) {115$statuses = DifferentialLegacyQuery::getModernValues($status);116if ($statuses) {117$query->withStatuses($statuses);118}119}120if ($order) {121$query->setOrder($order);122}123if ($limit) {124$query->setLimit($limit);125}126if ($offset) {127$query->setOffset($offset);128}129if ($ids) {130$query->withIDs($ids);131}132if ($phids) {133$query->withPHIDs($phids);134}135if ($responsible_users) {136$query->withResponsibleUsers($responsible_users);137}138if ($subscribers) {139$query->withCCs($subscribers);140}141if ($branches) {142$query->withBranches($branches);143}144145$query->needReviewers(true);146$query->needCommitPHIDs(true);147$query->needDiffIDs(true);148$query->needActiveDiffs(true);149$query->needHashes(true);150151$revisions = $query->execute();152153$field_data = $this->loadCustomFieldsForRevisions(154$request->getUser(),155$revisions);156157if ($revisions) {158$ccs = id(new PhabricatorSubscribersQuery())159->withObjectPHIDs(mpull($revisions, 'getPHID'))160->execute();161} else {162$ccs = array();163}164165$results = array();166foreach ($revisions as $revision) {167$diff = $revision->getActiveDiff();168if (!$diff) {169continue;170}171172$id = $revision->getID();173$phid = $revision->getPHID();174175$result = array(176'id' => $id,177'phid' => $phid,178'title' => $revision->getTitle(),179'uri' => PhabricatorEnv::getProductionURI('/D'.$id),180'dateCreated' => $revision->getDateCreated(),181'dateModified' => $revision->getDateModified(),182'authorPHID' => $revision->getAuthorPHID(),183184// NOTE: For backward compatibility this is explicitly a string, like185// "2", even though the value of the string is an integer. See PHI14.186'status' => (string)$revision->getLegacyRevisionStatus(),187188'statusName' => $revision->getStatusDisplayName(),189'properties' => $revision->getProperties(),190'branch' => $diff->getBranch(),191'summary' => $revision->getSummary(),192'testPlan' => $revision->getTestPlan(),193'lineCount' => $revision->getLineCount(),194'activeDiffPHID' => $diff->getPHID(),195'diffs' => $revision->getDiffIDs(),196'commits' => $revision->getCommitPHIDs(),197'reviewers' => $revision->getReviewerPHIDs(),198'ccs' => idx($ccs, $phid, array()),199'hashes' => $revision->getHashes(),200'auxiliary' => idx($field_data, $phid, array()),201'repositoryPHID' => $diff->getRepositoryPHID(),202);203204// TODO: This is a hacky way to put permissions on this field until we205// have first-class support, see T838.206if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {207$result['sourcePath'] = $diff->getSourcePath();208}209210$results[] = $result;211}212213return $results;214}215216}217218219