Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/conduit/method/differential/query/ConduitAPI_differential_query_Method.php b/src/applications/conduit/method/differential/query/ConduitAPI_differential_query_Method.php
index 3a1427c37a..fb9202340f 100644
--- a/src/applications/conduit/method/differential/query/ConduitAPI_differential_query_Method.php
+++ b/src/applications/conduit/method/differential/query/ConduitAPI_differential_query_Method.php
@@ -1,144 +1,163 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group conduit
*/
class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
public function getMethodDescription() {
return "Query Differential revisions which match certain criteria.";
}
public function defineParamTypes() {
$status_types = array(
DifferentialRevisionQuery::STATUS_ANY,
DifferentialRevisionQuery::STATUS_OPEN,
);
$status_types = implode(', ', $status_types);
$order_types = array(
DifferentialRevisionQuery::ORDER_MODIFIED,
DifferentialRevisionQuery::ORDER_CREATED,
);
$order_types = implode(', ', $order_types);
return array(
- 'authors' => 'optional list<phid>',
- 'ccs' => 'optional list<phid>',
- 'reviewers' => 'optional list<phid>',
- 'paths' => 'optional list<string>',
- 'status' => 'optional enum<'.$status_types.'>',
- 'order' => 'optional enum<'.$order_types.'>',
- 'limit' => 'optional uint',
- 'offset' => 'optional uint',
- 'ids' => 'optional list<uint>',
- 'phids' => 'optional list<phid>',
+ 'authors' => 'optional list<phid>',
+ 'ccs' => 'optional list<phid>',
+ 'reviewers' => 'optional list<phid>',
+ // TODO: Implement this, it needs to accept a repository ID in addition
+ // to a path so the signature needs to be a little more complicated.
+ // 'paths' => 'optional list<pair<...>>',
+ 'status' => 'optional enum<'.$status_types.'>',
+ 'order' => 'optional enum<'.$order_types.'>',
+ 'limit' => 'optional uint',
+ 'offset' => 'optional uint',
+ 'ids' => 'optional list<uint>',
+ 'phids' => 'optional list<phid>',
+ 'subscribers' => 'optional list<phid>',
+ 'responsibleUsers' => 'optional list<phid>',
);
}
public function defineReturnType() {
return 'list<dict>';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
- $authors = $request->getValue('authors');
- $ccs = $request->getValue('ccs');
- $reviewers = $request->getValue('reviewers');
- $paths = $request->getValue('paths');
- $status = $request->getValue('status');
- $order = $request->getValue('order');
- $limit = $request->getValue('limit');
- $offset = $request->getValue('offset');
- $ids = $request->getValue('ids');
- $phids = $request->getValue('phids');
+ $authors = $request->getValue('authors');
+ $ccs = $request->getValue('ccs');
+ $reviewers = $request->getValue('reviewers');
+ $status = $request->getValue('status');
+ $order = $request->getValue('order');
+ $limit = $request->getValue('limit');
+ $offset = $request->getValue('offset');
+ $ids = $request->getValue('ids');
+ $phids = $request->getValue('phids');
+ $subscribers = $request->getValue('subscribers');
+ $responsible_users = $request->getValue('responsibleUsers');
$query = new DifferentialRevisionQuery();
- $query->withAuthors($authors);
+ if ($authors) {
+ $query->withAuthors($authors);
+ }
if ($ccs) {
$query->withCCs($ccs);
}
if ($reviewers) {
$query->withReviewers($reviewers);
}
+/* TODO: Implement.
+ $paths = $request->getValue('paths');
if ($paths) {
foreach ($paths as $path) {
- $query->withPath($path);
+
+ // (Lookup the repository IDs.)
+
+ $query->withPath($repository_id, $path);
}
}
+*/
if ($status) {
$query->withStatus($status);
}
if ($order) {
$query->setOrder($order);
}
if ($limit) {
$query->setLimit($limit);
}
if ($offset) {
$query->setOffset($offset);
}
if ($ids) {
$query->withIDs($ids);
}
if ($phids) {
$query->withPHIDs($phids);
}
+ if ($responsible_users) {
+ $query->withResponsibleUsers($responsible_users);
+ }
+ if ($subscribers) {
+ $query->withSubscribers($subscribers);
+ }
$revisions = $query->execute();
$results = array();
foreach ($revisions as $revision) {
$diff = $revision->loadActiveDiff();
if (!$diff) {
continue;
}
$revision->loadRelationships();
$id = $revision->getID();
$results[] = array(
'id' => $id,
'phid' => $revision->getPHID(),
'title' => $revision->getTitle(),
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
'dateCreated' => $revision->getDateCreated(),
'authorPHID' => $revision->getAuthorPHID(),
'status' => $revision->getStatus(),
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
$revision->getStatus()),
'sourcePath' => $diff->getSourcePath(),
'summary' => $revision->getSummary(),
'testPlan' => $revision->getTestPlan(),
'lineCount' => $revision->getLineCount(),
'diffs' => array_keys($revision->loadDiffs()),
'commits' => $revision->loadCommitPHIDs(),
'reviewers' => array_values($revision->getReviewers()),
'ccs' => array_values($revision->getCCPHIDs()),
);
}
return $results;
}
}
diff --git a/src/applications/differential/query/revision/DifferentialRevisionQuery.php b/src/applications/differential/query/revision/DifferentialRevisionQuery.php
index 39d44332e5..bc80898e75 100644
--- a/src/applications/differential/query/revision/DifferentialRevisionQuery.php
+++ b/src/applications/differential/query/revision/DifferentialRevisionQuery.php
@@ -1,461 +1,497 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Flexible query API for Differential revisions. Example:
*
* // Load open revisions
* $revisions = id(new DifferentialRevisionQuery())
* ->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
* ->execute();
*
* @task config Query Configuration
* @task exec Query Execution
* @task internal Internals
*/
final class DifferentialRevisionQuery {
// TODO: Replace DifferentialRevisionListData with this class.
private $pathIDs = array();
private $status = 'status-any';
const STATUS_ANY = 'status-any';
const STATUS_OPEN = 'status-open';
private $authors = array();
private $ccs = array();
private $reviewers = array();
private $revIDs = array();
private $phids = array();
+ private $subscribers = array();
+ private $responsibles = array();
private $order = 'order-modified';
const ORDER_MODIFIED = 'order-modified';
const ORDER_CREATED = 'order-created';
/**
* This is essentially a denormalized copy of the revision modified time that
* should perform better for path queries with a LIMIT. Critically, when you
* browse "/", every revision in that repository for all time will match so
* the query benefits from being able to stop before fully materializing the
* result set.
*/
const ORDER_PATH_MODIFIED = 'order-path-modified';
private $limit = 1000;
private $offset = 0;
private $needRelationships = false;
/* -( Query Configuration )------------------------------------------------ */
/**
* Filter results to revisions which affect a Diffusion path ID in a given
* repository. You can call this multiple times to select revisions for
* several paths.
*
* @param int Diffusion repository ID.
* @param int Diffusion path ID.
* @return this
* @task config
*/
public function withPath($repository_id, $path_id) {
$this->pathIDs[] = array(
'repositoryID' => $repository_id,
'pathID' => $path_id,
);
return $this;
}
- /**
- * Filter results to revisions authored by a given PHID.
- *
- * @param phid Author PHID
- * @return this
- * @task config
- */
- public function withAuthor($author_phid) {
- $this->authors[] = $author_phid;
- return $this;
- }
-
/**
* Filter results to revisions authored by one of the given PHIDs.
*
* @param array List of PHIDs of authors
* @return this
* @task config
*/
- public function withAuthors(array $author_list) {
- $this->authors = $author_list;
+ public function withAuthors(array $author_phids) {
+ $this->authors = $author_phids;
return $this;
}
/**
* Filter results to revisions which CC one of the listed people. Calling this
- * function will clear anything set by previous calls to withCCs or withCC.
+ * function will clear anything set by previous calls to @{method:withCCs}.
*
* @param array List of PHIDs of subscribers
* @return this
* @task config
*/
public function withCCs(array $cc_phids) {
$this->ccs = $cc_phids;
return $this;
}
- /**
- * Filter results to include revisions which CC the given PHID.
- *
- * @param phid CC PHID
- * @return this
- * @task config
- */
- public function withCC($cc) {
- $this->ccs[] = $cc;
- return $this;
- }
/**
* Filter results to revisions that have one of the provided PHIDs as
* reviewers. Calling this function will clear anything set by previous calls
- * to withReviewers or withReviewer.
+ * to @{method:withReviewers}.
*
* @param array List of PHIDs of reviewers
* @return this
* @task config
*/
public function withReviewers(array $reviewer_phids) {
$this->reviewers = $reviewer_phids;
return $this;
}
- /**
- * Filter results to include revisions which have the given PHID as a
- * reviewer.
- *
- * @param phid reviewer PHID
- * @return this
- * @task config
- */
- public function withReviewer($reviewer) {
- $this->reviewers[] = $reviewer;
- return $this;
- }
/**
* Filter results to revisions with a given status. Provide a class constant,
* such as ##DifferentialRevisionQuery::STATUS_OPEN##.
*
* @param const Class STATUS constant, like STATUS_OPEN.
* @return this
* @task config
*/
public function withStatus($status_constant) {
$this->status = $status_constant;
return $this;
}
/**
* Filter results to only return revisions whose ids are in the given set.
*
* @param array List of revision ids
* @return this
* @task config
*/
public function withIDs(array $ids) {
$this->revIDs = $ids;
return $this;
}
/**
* Filter results to only return revisions whose PHIDs are in the given set.
*
* @param array List of revision PHIDs
* @return this
* @task config
*/
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
+ /**
+ * Given a set of users, filter results to return only revisions they are
+ * responsible for (i.e., they are either authors or reviewers).
+ *
+ * @param array List of user PHIDs.
+ * @return this
+ * @task config
+ */
+ public function withResponsibleUsers(array $responsible_phids) {
+ $this->responsibles = $responsible_phids;
+ return $this;
+ }
+
+
+ /**
+ * Filter results to only return revisions with a given set of subscribers
+ * (i.e., they are authors, reviewers or CC'd).
+ *
+ * @param array List of user PHIDs.
+ * @return this
+ * @task config
+ */
+ public function withSubscribers(array $subscriber_phids) {
+ $this->subscribers = $subscriber_phids;
+ return $this;
+ }
+
+
/**
* Set result ordering. Provide a class constant, such as
* ##DifferentialRevisionQuery::ORDER_CREATED##.
*
* @task config
*/
public function setOrder($order_constant) {
$this->order = $order_constant;
return $this;
}
/**
* Set result limit. If unspecified, defaults to 1000.
*
* @param int Result limit.
* @return this
* @task config
*/
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
/**
* Set result offset. If unspecified, defaults to 0.
*
* @param int Result offset.
* @return this
* @task config
*/
public function setOffset($offset) {
$this->offset = $offset;
return $this;
}
/**
* Set whether or not the query will load and attach relationships.
*
* @param bool True to load and attach relationships.
* @return this
* @task config
*/
public function needRelationships($need_relationships) {
$this->needRelationships = $need_relationships;
return $this;
}
/* -( Query Execution )---------------------------------------------------- */
/**
* Execute the query as configured, returning matching
* @{class:DifferentialRevision} objects.
*
* @return list List of matching DifferentialRevision objects.
* @task exec
*/
public function execute() {
$table = new DifferentialRevision();
$conn_r = $table->establishConnection('r');
$select = qsprintf(
$conn_r,
'SELECT r.* FROM %T r',
$table->getTableName());
$joins = $this->buildJoinsClause($conn_r);
$where = $this->buildWhereClause($conn_r);
$group_by = $this->buildGroupByClause($conn_r);
$order_by = $this->buildOrderByClause($conn_r);
$limit = qsprintf(
$conn_r,
'LIMIT %d, %d',
(int)$this->offset,
$this->limit);
$data = queryfx_all(
$conn_r,
'%Q %Q %Q %Q %Q %Q',
$select,
$joins,
$where,
$group_by,
$order_by,
$limit);
$revisions = $table->loadAllFromArray($data);
if ($revisions && $this->needRelationships) {
$relationships = queryfx_all(
$conn_r,
'SELECT * FROM %T WHERE revisionID in (%Ld) ORDER BY sequence',
DifferentialRevision::RELATIONSHIP_TABLE,
mpull($revisions, 'getID'));
$relationships = igroup($relationships, 'revisionID');
foreach ($revisions as $revision) {
$revision->attachRelationships(
idx(
$relationships,
$revision->getID(),
array()));
}
}
return $revisions;
}
/* -( Internals )---------------------------------------------------------- */
/**
* @task internal
*/
private function buildJoinsClause($conn_r) {
$joins = array();
if ($this->pathIDs) {
$path_table = new DifferentialAffectedPath();
$joins[] = qsprintf(
$conn_r,
'JOIN %T p ON p.revisionID = r.id',
$path_table->getTableName());
}
if ($this->ccs) {
$joins[] = qsprintf(
$conn_r,
- 'JOIN %T rel ON rel.revisionID = r.id '.
- 'AND rel.relation = %s AND rel.objectPHID in (%Ls)',
+ 'JOIN %T cc_rel ON cc_rel.revisionID = r.id '.
+ 'AND cc_rel.relation = %s '.
+ 'AND cc_rel.objectPHID in (%Ls)',
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_SUBSCRIBED,
$this->ccs);
}
if ($this->reviewers) {
$joins[] = qsprintf(
$conn_r,
- 'JOIN %T rel ON rel.revisionID = r.id '.
- 'AND rel.relation = %s AND rel.objectPHID in (%Ls)',
+ 'JOIN %T reviewer_rel ON reviewer_rel.revisionID = r.id '.
+ 'AND reviewer_rel.relation = %s '.
+ 'AND reviewer_rel.objectPHID in (%Ls)',
DifferentialRevision::RELATIONSHIP_TABLE,
DifferentialRevision::RELATION_REVIEWER,
$this->reviewers);
}
+ if ($this->subscribers) {
+ $joins[] = qsprintf(
+ $conn_r,
+ 'JOIN %T sub_rel ON sub_rel.revisionID = r.id '.
+ 'AND sub_rel.relation IN (%Ls) '.
+ 'AND sub_rel.objectPHID in (%Ls)',
+ DifferentialRevision::RELATIONSHIP_TABLE,
+ array(
+ DifferentialRevision::RELATION_SUBSCRIBED,
+ DifferentialRevision::RELATION_REVIEWER,
+ ),
+ $this->subscribers);
+ }
+
+ if ($this->responsibles) {
+ $joins[] = qsprintf(
+ $conn_r,
+ 'LEFT JOIN %T responsibles_rel ON responsibles_rel.revisionID = r.id '.
+ 'AND responsibles_rel.relation = %s '.
+ 'AND responsibles_rel.objectPHID in (%Ls)',
+ DifferentialRevision::RELATIONSHIP_TABLE,
+ DifferentialRevision::RELATION_REVIEWER,
+ $this->responsibles);
+ }
+
$joins = implode(' ', $joins);
return $joins;
}
/**
* @task internal
*/
private function buildWhereClause($conn_r) {
$where = array();
if ($this->pathIDs) {
$path_clauses = array();
$repo_info = igroup($this->pathIDs, 'repositoryID');
foreach ($repo_info as $repository_id => $paths) {
$path_clauses[] = qsprintf(
$conn_r,
'(repositoryID = %d AND pathID IN (%Ld))',
$repository_id,
ipull($paths, 'pathID'));
}
$path_clauses = '('.implode(' OR ', $path_clauses).')';
$where[] = $path_clauses;
}
if ($this->authors) {
$where[] = qsprintf(
$conn_r,
'authorPHID IN (%Ls)',
$this->authors);
}
if ($this->revIDs) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->revIDs);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
+ if ($this->responsibles) {
+ $where[] = qsprintf(
+ $conn_r,
+ '(responsibles_rel.objectPHID IS NOT NULL OR r.authorPHID IN (%Ls))',
+ $this->responsibles);
+ }
+
switch ($this->status) {
case self::STATUS_ANY:
break;
case self::STATUS_OPEN:
$where[] = qsprintf(
$conn_r,
'status IN (%Ld)',
array(
DifferentialRevisionStatus::NEEDS_REVIEW,
DifferentialRevisionStatus::NEEDS_REVISION,
DifferentialRevisionStatus::ACCEPTED,
));
break;
default:
throw new Exception(
"Unknown revision status filter constant '{$this->status}'!");
}
if ($where) {
$where = 'WHERE '.implode(' AND ', $where);
} else {
$where = '';
}
return $where;
}
/**
* @task internal
*/
private function buildGroupByClause($conn_r) {
- $needs_distinct = (count($this->pathIDs) > 1);
+ $join_triggers = array_merge(
+ $this->pathIDs,
+ $this->ccs,
+ $this->reviewers,
+ $this->subscribers,
+ $this->responsibles);
+
+ $needs_distinct = (count($join_triggers) > 1);
if ($needs_distinct) {
return 'GROUP BY r.id';
} else {
return '';
}
}
/**
* @task internal
*/
private function buildOrderByClause($conn_r) {
switch ($this->order) {
case self::ORDER_MODIFIED:
return 'ORDER BY r.dateModified DESC';
case self::ORDER_CREATED:
return 'ORDER BY r.dateCreated DESC';
case self::ORDER_PATH_MODIFIED:
if (!$this->pathIDs) {
throw new Exception(
"To use ORDER_PATH_MODIFIED, you must specify withPath().");
}
return 'ORDER BY p.epoch DESC';
default:
throw new Exception("Unknown query order constant '{$this->order}'.");
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jul 2, 4:46 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
164693
Default Alt Text
(20 KB)

Event Timeline