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