Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/controller/DifferentialRevisionAffectedPathsController.php
12256 views
1
<?php
2
3
final class DifferentialRevisionAffectedPathsController
4
extends DifferentialController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
$id = $request->getURIData('id');
9
10
$revision = id(new DifferentialRevisionQuery())
11
->withIDs(array($id))
12
->setViewer($viewer)
13
->executeOne();
14
if (!$revision) {
15
return new Aphront404Response();
16
}
17
18
$table = new DifferentialAffectedPath();
19
$conn = $table->establishConnection('r');
20
21
$paths = queryfx_all(
22
$conn,
23
'SELECT * FROM %R WHERE revisionID = %d',
24
$table,
25
$revision->getID());
26
27
$repository_ids = array();
28
$path_ids = array();
29
30
foreach ($paths as $path) {
31
$repository_id = $path['repositoryID'];
32
$path_id = $path['pathID'];
33
34
$repository_ids[] = $repository_id;
35
$path_ids[] = $path_id;
36
}
37
38
$repository_ids = array_fuse($repository_ids);
39
40
if ($repository_ids) {
41
$repositories = id(new PhabricatorRepositoryQuery())
42
->setViewer($viewer)
43
->withIDs($repository_ids)
44
->execute();
45
$repositories = mpull($repositories, null, 'getID');
46
} else {
47
$repositories = array();
48
}
49
50
$handles = $viewer->loadHandles(mpull($repositories, 'getPHID'));
51
52
$path_ids = array_fuse($path_ids);
53
if ($path_ids) {
54
$path_names = id(new DiffusionPathQuery())
55
->withPathIDs($path_ids)
56
->execute();
57
} else {
58
$path_names = array();
59
}
60
61
$rows = array();
62
foreach ($paths as $path) {
63
$repository_id = $path['repositoryID'];
64
$path_id = $path['pathID'];
65
66
$repository = idx($repositories, $repository_id);
67
if ($repository) {
68
$repository_phid = $repository->getPHID();
69
$repository_link = $handles[$repository_phid]->renderLink();
70
} else {
71
$repository_link = null;
72
}
73
74
$path_name = idx($path_names, $path_id);
75
if ($path_name !== null) {
76
$path_view = $path_name['path'];
77
} else {
78
$path_view = null;
79
}
80
81
$rows[] = array(
82
$repository_id,
83
$repository_link,
84
$path_id,
85
$path_view,
86
);
87
}
88
89
// Sort rows by path name.
90
$rows = isort($rows, 3);
91
92
$table_view = id(new AphrontTableView($rows))
93
->setNoDataString(pht('This revision has no indexed affected paths.'))
94
->setHeaders(
95
array(
96
pht('Repository ID'),
97
pht('Repository'),
98
pht('Path ID'),
99
pht('Path'),
100
))
101
->setColumnClasses(
102
array(
103
null,
104
null,
105
null,
106
'wide',
107
));
108
109
$box_view = id(new PHUIObjectBoxView())
110
->setHeaderText(pht('Affected Path Index'))
111
->setTable($table_view);
112
113
$crumbs = $this->buildApplicationCrumbs()
114
->addTextCrumb($revision->getMonogram(), $revision->getURI())
115
->addTextCrumb(pht('Affected Path Index'));
116
117
return $this->newPage()
118
->setCrumbs($crumbs)
119
->setTitle(
120
array(
121
$revision->getMonogram(),
122
pht('Affected Path Index'),
123
))
124
->appendChild($box_view);
125
}
126
127
}
128
129