@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 173 lines 4.5 kB view raw
1<?php 2 3final class PhabricatorConfigClusterNotificationsController 4 extends PhabricatorConfigServicesController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $title = pht('Notification Servers'); 8 $doc_href = PhabricatorEnv::getDoclink('Cluster: Notifications'); 9 $button = id(new PHUIButtonView()) 10 ->setIcon('fa-book') 11 ->setHref($doc_href) 12 ->setTag('a') 13 ->setText(pht('Documentation')); 14 15 $header = $this->buildHeaderView($title, $button); 16 17 $notification_status = $this->buildClusterNotificationStatus(); 18 $status = $this->buildConfigBoxView( 19 pht('Notifications Status'), 20 $notification_status); 21 22 $crumbs = $this->newCrumbs() 23 ->addTextCrumb($title); 24 25 $content = id(new PHUITwoColumnView()) 26 ->setHeader($header) 27 ->setFooter($status); 28 29 $nav = $this->newNavigation('notification-servers'); 30 31 return $this->newPage() 32 ->setTitle($title) 33 ->setCrumbs($crumbs) 34 ->setNavigation($nav) 35 ->appendChild($content); 36 } 37 38 private function buildClusterNotificationStatus() { 39 $viewer = $this->getViewer(); 40 41 $servers = PhabricatorNotificationServerRef::newRefs(); 42 Javelin::initBehavior('phabricator-tooltips'); 43 44 $rows = array(); 45 foreach ($servers as $server) { 46 if ($server->isAdminServer()) { 47 $type_icon = 'fa-database sky'; 48 $type_tip = pht('Admin Server'); 49 } else { 50 $type_icon = 'fa-bell sky'; 51 $type_tip = pht('Client Server'); 52 } 53 54 $type_icon = id(new PHUIIconView()) 55 ->setIcon($type_icon) 56 ->addSigil('has-tooltip') 57 ->setMetadata( 58 array( 59 'tip' => $type_tip, 60 )); 61 62 $messages = array(); 63 64 $details = array(); 65 if ($server->isAdminServer()) { 66 try { 67 $details = $server->loadServerStatus(); 68 $status_icon = 'fa-exchange green'; 69 $status_label = pht('Version %s', idx($details, 'version')); 70 } catch (Exception $ex) { 71 $status_icon = 'fa-times red'; 72 $status_label = pht('Connection Error'); 73 $messages[] = $ex->getMessage(); 74 } 75 } else { 76 try { 77 $server->testClient(); 78 $status_icon = 'fa-exchange green'; 79 $status_label = pht('Connected'); 80 } catch (Exception $ex) { 81 $status_icon = 'fa-times red'; 82 $status_label = pht('Connection Error'); 83 $messages[] = $ex->getMessage(); 84 } 85 } 86 87 if ($details) { 88 $uptime = idx($details, 'uptime'); 89 $uptime = $uptime / 1000; 90 $uptime = phutil_format_relative_time_detailed($uptime); 91 92 $clients = pht( 93 '%s Active / %s Total', 94 new PhutilNumber(idx($details, 'clients.active')), 95 new PhutilNumber(idx($details, 'clients.total'))); 96 97 $stats = pht( 98 '%s In / %s Out', 99 new PhutilNumber(idx($details, 'messages.in')), 100 new PhutilNumber(idx($details, 'messages.out'))); 101 102 if (idx($details, 'history.size')) { 103 $history = pht( 104 '%s Held / %sms', 105 new PhutilNumber(idx($details, 'history.size')), 106 new PhutilNumber(idx($details, 'history.age'))); 107 } else { 108 $history = pht('No Messages'); 109 } 110 111 } else { 112 $uptime = null; 113 $clients = null; 114 $stats = null; 115 $history = null; 116 } 117 118 $status_view = array( 119 id(new PHUIIconView())->setIcon($status_icon), 120 ' ', 121 $status_label, 122 ); 123 124 $messages = phutil_implode_html(phutil_tag('br'), $messages); 125 126 $rows[] = array( 127 $type_icon, 128 $server->getProtocol(), 129 $server->getHost(), 130 $server->getPort(), 131 $status_view, 132 $uptime, 133 $clients, 134 $stats, 135 $history, 136 $messages, 137 ); 138 } 139 140 $table = id(new AphrontTableView($rows)) 141 ->setNoDataString( 142 pht('No notification servers are configured.')) 143 ->setHeaders( 144 array( 145 null, 146 pht('Proto'), 147 pht('Host'), 148 pht('Port'), 149 pht('Status'), 150 pht('Uptime'), 151 pht('Clients'), 152 pht('Messages'), 153 pht('History'), 154 null, 155 )) 156 ->setColumnClasses( 157 array( 158 null, 159 null, 160 null, 161 null, 162 null, 163 null, 164 null, 165 null, 166 null, 167 'wide', 168 )); 169 170 return $table; 171 } 172 173}