Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionRefTableController.php
blob8a4e2748195f02333440b39087ff71973cd70a64
1 <?php
3 final class DiffusionRefTableController extends DiffusionController {
5 public function shouldAllowPublic() {
6 return true;
9 public function handleRequest(AphrontRequest $request) {
10 $response = $this->loadDiffusionContext();
11 if ($response) {
12 return $response;
15 $viewer = $this->getViewer();
16 $drequest = $this->getDiffusionRequest();
17 $repository = $drequest->getRepository();
19 if (!$drequest->supportsBranches()) {
20 return $this->newDialog()
21 ->setTitle(pht('No Ref Support'))
22 ->appendParagraph(
23 pht(
24 'The version control system this repository uses does not '.
25 'support named references, so you can not resolve or list '.
26 'repository refs in this repository.'))
27 ->addCancelButton($repository->getURI());
30 $ref_name = $drequest->getBranch();
32 $cache_query = id(new DiffusionCachedResolveRefsQuery())
33 ->setRepository($repository);
34 if ($ref_name !== null) {
35 $cache_query->withRefs(array($ref_name));
37 $cache_refs = $cache_query->execute();
39 $vcs_refs = DiffusionQuery::callConduitWithDiffusionRequest(
40 $viewer,
41 $drequest,
42 'diffusion.resolverefs',
43 array(
44 'refs' => array($ref_name),
45 ));
47 $all = array();
48 foreach ($cache_refs as $ref => $results) {
49 foreach ($results as $result) {
50 $id = $result['type'].'/'.$result['identifier'];
51 $all[$ref][$id]['cache'] = $result;
55 foreach ($vcs_refs as $ref => $results) {
56 foreach ($results as $result) {
57 $id = $result['type'].'/'.$result['identifier'];
58 $all[$ref][$id]['vcs'] = $result;
62 $rows = array();
63 foreach ($all as $ref => $results) {
64 foreach ($results as $info) {
65 $cache = idx($info, 'cache', array());
66 $vcs = idx($info, 'vcs', array());
68 $type = idx($vcs, 'type');
69 if (!$type) {
70 $type = idx($cache, 'type');
73 $hash = idx($vcs, 'identifier');
74 if ($hash !== null) {
75 $hash = DiffusionView::linkCommit(
76 $repository,
77 $hash);
80 $cached_hash = idx($cache, 'identifier');
81 if ($cached_hash !== null) {
82 $cached_hash = DiffusionView::linkCommit(
83 $repository,
84 $cached_hash);
87 $closed = idx($vcs, 'closed', false);
88 if (!$vcs) {
89 $state = null;
90 } else {
91 $state = $closed ? pht('Closed') : pht('Open');
94 $cached_closed = idx($cache, 'closed', false);
95 if (!$cache) {
96 $cached_state = null;
97 } else {
98 $cached_state = $cached_closed ? pht('Closed') : pht('Open');
101 $alternate = idx($vcs, 'alternate');
102 if ($alternate !== null) {
103 $alternate = DiffusionView::linkCommit(
104 $repository,
105 $alternate);
108 $rows[] = array(
109 $ref,
110 $type,
111 $hash,
112 $cached_hash,
113 $state,
114 $cached_state,
115 $alternate,
120 $table = id(new AphrontTableView($rows))
121 ->setHeaders(
122 array(
123 pht('Ref'),
124 pht('Type'),
125 pht('Hash'),
126 pht('Cached Hash'),
127 pht('State'),
128 pht('Cached State'),
129 pht('Alternate'),
132 $content = id(new PHUIObjectBoxView())
133 ->setHeaderText(pht('Ref "%s"', $ref_name))
134 ->setTable($table);
136 $crumbs = $this->buildCrumbs(array());
137 $crumbs->addTextCrumb(pht('Refs'));
139 return $this->newPage()
140 ->setTitle(
141 array(
142 $ref_name,
143 pht('Ref'),
144 $repository->getDisplayName(),
146 ->setCrumbs($crumbs)
147 ->appendChild($content);