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