3 final class PhabricatorRepositoryRefCursorQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
8 private $repositoryPHIDs;
11 private $datasourceQuery;
12 private $needPositions;
14 public function withIDs(array $ids) {
19 public function withPHIDs(array $phids) {
20 $this->phids
= $phids;
24 public function withRepositoryPHIDs(array $phids) {
25 $this->repositoryPHIDs
= $phids;
29 public function withRefTypes(array $types) {
30 $this->refTypes
= $types;
34 public function withRefNames(array $names) {
35 $this->refNames
= $names;
39 public function withDatasourceQuery($query) {
40 $this->datasourceQuery
= $query;
44 public function needPositions($need) {
45 $this->needPositions
= $need;
49 public function newResultObject() {
50 return new PhabricatorRepositoryRefCursor();
53 protected function willFilterPage(array $refs) {
54 $repository_phids = mpull($refs, 'getRepositoryPHID');
56 $repositories = id(new PhabricatorRepositoryQuery())
57 ->setViewer($this->getViewer())
58 ->setParentQuery($this)
59 ->withPHIDs($repository_phids)
61 $repositories = mpull($repositories, null, 'getPHID');
63 foreach ($refs as $key => $ref) {
64 $repository = idx($repositories, $ref->getRepositoryPHID());
66 $this->didRejectResult($ref);
70 $ref->attachRepository($repository);
77 if ($this->needPositions
) {
78 $positions = id(new PhabricatorRepositoryRefPosition())->loadAllWhere(
80 mpull($refs, 'getID'));
81 $positions = mgroup($positions, 'getCursorID');
83 foreach ($refs as $key => $ref) {
84 $ref_positions = idx($positions, $ref->getID(), array());
85 $ref->attachPositions($ref_positions);
92 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
93 $where = parent
::buildWhereClauseParts($conn);
95 if ($this->ids
!== null) {
102 if ($this->phids
!== null) {
109 if ($this->repositoryPHIDs
!== null) {
112 'repositoryPHID IN (%Ls)',
113 $this->repositoryPHIDs
);
116 if ($this->refTypes
!== null) {
123 if ($this->refNames
!== null) {
124 $name_hashes = array();
125 foreach ($this->refNames
as $name) {
126 $name_hashes[] = PhabricatorHash
::digestForIndex($name);
131 'refNameHash IN (%Ls)',
135 if ($this->datasourceQuery
!== null && strlen($this->datasourceQuery
)) {
138 'refNameRaw LIKE %>',
139 $this->datasourceQuery
);
145 public function getQueryApplicationClass() {
146 return 'PhabricatorDiffusionApplication';