Path: blob/master/src/applications/diffusion/query/DiffusionCommitHintQuery.php
12242 views
<?php12final class DiffusionCommitHintQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $repositoryPHIDs;7private $oldCommitIdentifiers;89private $commits;10private $commitMap;1112public function withIDs(array $ids) {13$this->ids = $ids;14return $this;15}1617public function withRepositoryPHIDs(array $phids) {18$this->repositoryPHIDs = $phids;19return $this;20}2122public function withOldCommitIdentifiers(array $identifiers) {23$this->oldCommitIdentifiers = $identifiers;24return $this;25}2627public function withCommits(array $commits) {28assert_instances_of($commits, 'PhabricatorRepositoryCommit');2930$repository_phids = array();31foreach ($commits as $commit) {32$repository_phids[] = $commit->getRepository()->getPHID();33}3435$this->repositoryPHIDs = $repository_phids;36$this->oldCommitIdentifiers = mpull($commits, 'getCommitIdentifier');37$this->commits = $commits;3839return $this;40}4142public function getCommitMap() {43if ($this->commitMap === null) {44throw new PhutilInvalidStateException('execute');45}4647return $this->commitMap;48}4950public function newResultObject() {51return new PhabricatorRepositoryCommitHint();52}5354protected function willExecute() {55$this->commitMap = array();56}5758protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {59$where = parent::buildWhereClauseParts($conn);6061if ($this->ids !== null) {62$where[] = qsprintf(63$conn,64'id IN (%Ld)',65$this->ids);66}6768if ($this->repositoryPHIDs !== null) {69$where[] = qsprintf(70$conn,71'repositoryPHID IN (%Ls)',72$this->repositoryPHIDs);73}7475if ($this->oldCommitIdentifiers !== null) {76$where[] = qsprintf(77$conn,78'oldCommitIdentifier IN (%Ls)',79$this->oldCommitIdentifiers);80}8182return $where;83}8485protected function didFilterPage(array $hints) {86if ($this->commits) {87$map = array();88foreach ($this->commits as $commit) {89$repository_phid = $commit->getRepository()->getPHID();90$identifier = $commit->getCommitIdentifier();91$map[$repository_phid][$identifier] = $commit->getPHID();92}9394foreach ($hints as $hint) {95$repository_phid = $hint->getRepositoryPHID();96$identifier = $hint->getOldCommitIdentifier();97if (isset($map[$repository_phid][$identifier])) {98$commit_phid = $map[$repository_phid][$identifier];99$this->commitMap[$commit_phid] = $hint;100}101}102}103104return $hints;105}106107public function getQueryApplicationClass() {108return 'PhabricatorDiffusionApplication';109}110111}112113114