Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/controller/DiffusionLastModifiedController.php
12242 views
1
<?php
2
3
final class DiffusionLastModifiedController extends DiffusionController {
4
5
public function shouldAllowPublic() {
6
return true;
7
}
8
9
public function handleRequest(AphrontRequest $request) {
10
$response = $this->loadDiffusionContext();
11
if ($response) {
12
return $response;
13
}
14
15
$viewer = $this->getViewer();
16
$drequest = $this->getDiffusionRequest();
17
18
$paths = $request->getStr('paths');
19
20
try {
21
$paths = phutil_json_decode($paths);
22
} catch (PhutilJSONParserException $ex) {
23
return new Aphront400Response();
24
}
25
26
$modified_map = $this->callConduitWithDiffusionRequest(
27
'diffusion.lastmodifiedquery',
28
array(
29
'paths' => array_fill_keys($paths, $drequest->getCommit()),
30
));
31
32
if ($modified_map) {
33
$commit_map = id(new DiffusionCommitQuery())
34
->setViewer($viewer)
35
->withRepository($drequest->getRepository())
36
->withIdentifiers(array_values($modified_map))
37
->needCommitData(true)
38
->needIdentities(true)
39
->execute();
40
$commit_map = mpull($commit_map, null, 'getCommitIdentifier');
41
} else {
42
$commit_map = array();
43
}
44
45
$commits = array();
46
foreach ($paths as $path) {
47
$modified_at = idx($modified_map, $path);
48
if ($modified_at) {
49
$commit = idx($commit_map, $modified_at);
50
if ($commit) {
51
$commits[$path] = $commit;
52
}
53
}
54
}
55
56
$branch = $drequest->loadBranch();
57
if ($branch && $commits) {
58
$lint_query = id(new DiffusionLintCountQuery())
59
->withBranchIDs(array($branch->getID()))
60
->withPaths(array_keys($commits));
61
62
if ($drequest->getLint()) {
63
$lint_query->withCodes(array($drequest->getLint()));
64
}
65
66
$lint = $lint_query->execute();
67
} else {
68
$lint = array();
69
}
70
71
$output = array();
72
foreach ($commits as $path => $commit) {
73
$prequest = clone $drequest;
74
$prequest->setPath($path);
75
76
$output[$path] = $this->renderColumns(
77
$prequest,
78
$commit,
79
idx($lint, $path));
80
}
81
82
return id(new AphrontAjaxResponse())->setContent($output);
83
}
84
85
private function renderColumns(
86
DiffusionRequest $drequest,
87
PhabricatorRepositoryCommit $commit = null,
88
$lint = null) {
89
$viewer = $this->getViewer();
90
91
if ($commit) {
92
$epoch = $commit->getEpoch();
93
$modified = DiffusionView::linkCommit(
94
$drequest->getRepository(),
95
$commit->getCommitIdentifier());
96
$date = $viewer->formatShortDateTime($epoch);
97
} else {
98
$modified = '';
99
$date = '';
100
}
101
102
$data = $commit->getCommitData();
103
$details = DiffusionView::linkDetail(
104
$drequest->getRepository(),
105
$commit->getCommitIdentifier(),
106
$data->getSummary());
107
$details = AphrontTableView::renderSingleDisplayLine($details);
108
109
$return = array(
110
'commit' => $modified,
111
'date' => $date,
112
'details' => $details,
113
);
114
115
if ($lint !== null) {
116
$return['lint'] = phutil_tag(
117
'a',
118
array(
119
'href' => $drequest->generateURI(array(
120
'action' => 'lint',
121
'lint' => null,
122
)),
123
),
124
number_format($lint));
125
}
126
127
// The client treats these results as markup, so make sure they have been
128
// escaped correctly.
129
foreach ($return as $key => $value) {
130
$return[$key] = hsprintf('%s', $value);
131
}
132
133
return $return;
134
}
135
136
}
137
138