1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Allow edge query filtering by destination PHIDs

Summary: See title. Adds features needed for D3136.

Test Plan:
Observe sanity (or run D3136 in a sandbox
and observe that voting works).

Reviewers: epriestley

Reviewed By: epriestley

CC: gmarcotte, aran, Korvin

Differential Revision: https://secure.phabricator.com/D3205
This commit is contained in:
Pieter Hooimeijer 2012-08-08 18:57:38 -07:00
parent eeb359bae6
commit 9debf779d6

View file

@ -38,6 +38,7 @@
final class PhabricatorEdgeQuery extends PhabricatorQuery {
private $sourcePHIDs;
private $destPHIDs;
private $edgeTypes;
private $resultSet;
@ -62,6 +63,19 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
}
/**
* Find edges terminating at one or more destination PHIDs.
*
* @param list List of destination PHIDs.
* @return this
*
*/
public function withDestinationPHIDs(array $dest_phids) {
$this->destPHIDs = $dest_phids;
return $this;
}
/**
* Find edges of specific types.
*
@ -110,6 +124,31 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
return array_keys($edges[$src_phid][$edge_type]);
}
/**
* Convenience method for loading a single edge's metadata for
* a given source, destination, and edge type. Returns null
* if the edge does not exist or does not have metadata. Builds
* and immediately executes a full query.
*
* @param phid Source PHID.
* @param const Edge type.
* @param phid Destination PHID.
* @return wild Edge annotation (or null).
*/
public static function loadSingleEdgeData($src_phid, $edge_type, $dest_phid) {
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($src_phid))
->withEdgeTypes(array($edge_type))
->withDestinationPHIDs(array($dest_phid))
->needEdgeData(true)
->execute();
if (isset($edges[$src_phid][$edge_type][$dest_phid]['data'])) {
return $edges[$src_phid][$edge_type][$dest_phid]['data'];
}
return null;
}
/**
* Load specified edges.
@ -262,6 +301,14 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
$this->edgeTypes);
}
if ($this->destPHIDs) {
// potentially complain if $this->edgeType was not set
$where[] = qsprintf(
$conn_r,
'edge.dst IN (%Ls)',
$this->destPHIDs);
}
return $this->formatWhereClause($where);
}