Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/query/DifferentialHunkQuery.php
12256 views
1
<?php
2
3
final class DifferentialHunkQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $changesets;
7
private $shouldAttachToChangesets;
8
9
public function withChangesets(array $changesets) {
10
assert_instances_of($changesets, 'DifferentialChangeset');
11
$this->changesets = $changesets;
12
return $this;
13
}
14
15
public function needAttachToChangesets($attach) {
16
$this->shouldAttachToChangesets = $attach;
17
return $this;
18
}
19
20
protected function willExecute() {
21
// If we fail to load any hunks at all (for example, because all of
22
// the requested changesets are directories or empty files and have no
23
// hunks) we'll never call didFilterPage(), and thus never have an
24
// opportunity to attach hunks. Attach empty hunk lists now so that we
25
// end up with the right result.
26
if ($this->shouldAttachToChangesets) {
27
foreach ($this->changesets as $changeset) {
28
$changeset->attachHunks(array());
29
}
30
}
31
}
32
33
public function newResultObject() {
34
return new DifferentialHunk();
35
}
36
37
protected function willFilterPage(array $hunks) {
38
$changesets = mpull($this->changesets, null, 'getID');
39
foreach ($hunks as $key => $hunk) {
40
$changeset = idx($changesets, $hunk->getChangesetID());
41
if (!$changeset) {
42
unset($hunks[$key]);
43
}
44
$hunk->attachChangeset($changeset);
45
}
46
47
return $hunks;
48
}
49
50
protected function didFilterPage(array $hunks) {
51
if ($this->shouldAttachToChangesets) {
52
$hunk_groups = mgroup($hunks, 'getChangesetID');
53
foreach ($this->changesets as $changeset) {
54
$hunks = idx($hunk_groups, $changeset->getID(), array());
55
$changeset->attachHunks($hunks);
56
}
57
}
58
59
return $hunks;
60
}
61
62
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
63
$where = parent::buildWhereClauseParts($conn);
64
65
if (!$this->changesets) {
66
throw new Exception(
67
pht(
68
'You must load hunks via changesets, with %s!',
69
'withChangesets()'));
70
}
71
72
$where[] = qsprintf(
73
$conn,
74
'changesetID IN (%Ld)',
75
mpull($this->changesets, 'getID'));
76
77
return $where;
78
}
79
80
public function getQueryApplicationClass() {
81
return 'PhabricatorDifferentialApplication';
82
}
83
84
protected function getDefaultOrderVector() {
85
// TODO: Do we need this?
86
return array('-id');
87
}
88
89
}
90
91