Differential D18614 Diff 44694 src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/query/PhabricatorRepositoryRefCursorQuery.php
| <?php | <?php | ||||
| final class PhabricatorRepositoryRefCursorQuery | final class PhabricatorRepositoryRefCursorQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $repositoryPHIDs; | private $repositoryPHIDs; | ||||
| private $refTypes; | private $refTypes; | ||||
| private $refNames; | private $refNames; | ||||
| private $datasourceQuery; | private $datasourceQuery; | ||||
| private $needPositions; | |||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| Show All 15 Lines | public function withRefNames(array $names) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withDatasourceQuery($query) { | public function withDatasourceQuery($query) { | ||||
| $this->datasourceQuery = $query; | $this->datasourceQuery = $query; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needPositions($need) { | |||||
| $this->needPositions = $need; | |||||
| return $this; | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorRepositoryRefCursor(); | return new PhabricatorRepositoryRefCursor(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| Show All 12 Lines | foreach ($refs as $key => $ref) { | ||||
| if (!$repository) { | if (!$repository) { | ||||
| $this->didRejectResult($ref); | $this->didRejectResult($ref); | ||||
| unset($refs[$key]); | unset($refs[$key]); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $ref->attachRepository($repository); | $ref->attachRepository($repository); | ||||
| } | } | ||||
| if (!$refs) { | |||||
| return $refs; | |||||
| } | |||||
| if ($this->needPositions) { | |||||
| $positions = id(new PhabricatorRepositoryRefPosition())->loadAllWhere( | |||||
| 'cursorID IN (%Ld)', | |||||
| mpull($refs, 'getID')); | |||||
| $positions = mgroup($positions, 'getCursorID'); | |||||
| foreach ($refs as $key => $ref) { | |||||
| $ref_positions = idx($positions, $ref->getID(), array()); | |||||
| $ref->attachPositions($ref_positions); | |||||
| } | |||||
| } | |||||
| return $refs; | return $refs; | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| ▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines | |||||