@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorRepositoryCommitHint>
5 */
6final class DiffusionCommitHintQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $repositoryPHIDs;
11 private $oldCommitIdentifiers;
12
13 private $commits;
14 private $commitMap;
15
16 public function withIDs(array $ids) {
17 $this->ids = $ids;
18 return $this;
19 }
20
21 public function withRepositoryPHIDs(array $phids) {
22 $this->repositoryPHIDs = $phids;
23 return $this;
24 }
25
26 public function withOldCommitIdentifiers(array $identifiers) {
27 $this->oldCommitIdentifiers = $identifiers;
28 return $this;
29 }
30
31 /**
32 * @param array<PhabricatorRepositoryCommit> $commits
33 */
34 public function withCommits(array $commits) {
35 assert_instances_of($commits, PhabricatorRepositoryCommit::class);
36
37 $repository_phids = array();
38 foreach ($commits as $commit) {
39 $repository_phids[] = $commit->getRepository()->getPHID();
40 }
41
42 $this->repositoryPHIDs = $repository_phids;
43 $this->oldCommitIdentifiers = mpull($commits, 'getCommitIdentifier');
44 $this->commits = $commits;
45
46 return $this;
47 }
48
49 public function getCommitMap() {
50 if ($this->commitMap === null) {
51 throw new PhutilInvalidStateException('execute');
52 }
53
54 return $this->commitMap;
55 }
56
57 public function newResultObject() {
58 return new PhabricatorRepositoryCommitHint();
59 }
60
61 protected function willExecute() {
62 $this->commitMap = array();
63 }
64
65 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
66 $where = parent::buildWhereClauseParts($conn);
67
68 if ($this->ids !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'id IN (%Ld)',
72 $this->ids);
73 }
74
75 if ($this->repositoryPHIDs !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'repositoryPHID IN (%Ls)',
79 $this->repositoryPHIDs);
80 }
81
82 if ($this->oldCommitIdentifiers !== null) {
83 $where[] = qsprintf(
84 $conn,
85 'oldCommitIdentifier IN (%Ls)',
86 $this->oldCommitIdentifiers);
87 }
88
89 return $where;
90 }
91
92 protected function didFilterPage(array $hints) {
93 if ($this->commits) {
94 $map = array();
95 foreach ($this->commits as $commit) {
96 $repository_phid = $commit->getRepository()->getPHID();
97 $identifier = $commit->getCommitIdentifier();
98 $map[$repository_phid][$identifier] = $commit->getPHID();
99 }
100
101 foreach ($hints as $hint) {
102 $repository_phid = $hint->getRepositoryPHID();
103 $identifier = $hint->getOldCommitIdentifier();
104 if (isset($map[$repository_phid][$identifier])) {
105 $commit_phid = $map[$repository_phid][$identifier];
106 $this->commitMap[$commit_phid] = $hint;
107 }
108 }
109 }
110
111 return $hints;
112 }
113
114 public function getQueryApplicationClass() {
115 return PhabricatorDiffusionApplication::class;
116 }
117
118}