@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 upstream/main 135 lines 5.6 kB view raw
1<?php 2 3final class PhabricatorSystemReadOnlyController 4 extends PhabricatorController { 5 6 public function shouldRequireLogin() { 7 return false; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $this->getViewer(); 12 $reason = $request->getURIData('reason'); 13 14 $body = array(); 15 switch ($reason) { 16 case PhabricatorEnv::READONLY_CONFIG: 17 $title = pht('Administrative Read-Only Mode'); 18 $body[] = pht( 19 'An Administrator has placed this server into read-only mode.'); 20 $body[] = pht( 21 'This mode may be used to perform temporary maintenance, test '. 22 'configuration, or archive an installation permanently.'); 23 $body[] = pht( 24 'Read-only mode was enabled by the explicit action of a human '. 25 'administrator, so you can get more information about why it '. 26 'has been turned on by rolling your chair away from your desk and '. 27 'yelling "Hey! Why is %s in read-only mode??!" using '. 28 'your very loudest outside voice.', 29 PlatformSymbols::getPlatformServerName()); 30 $body[] = pht( 31 'This mode is active because it is enabled in the configuration '. 32 'option "%s".', 33 phutil_tag('tt', array(), 'cluster.read-only')); 34 $button = pht('Wait Patiently'); 35 break; 36 case PhabricatorEnv::READONLY_MASTERLESS: 37 $title = pht('No Writable Database'); 38 $body[] = pht( 39 'This server is currently configured with no writable ("master") '. 40 'database, so it can not write new information anywhere. '. 41 'This server will run in read-only mode until an administrator '. 42 'reconfigures it with a writable database.'); 43 $body[] = pht( 44 'This usually occurs when an administrator is actively working on '. 45 'fixing a temporary configuration or deployment problem.'); 46 $body[] = pht( 47 'This mode is active because no database has a "%s" role in '. 48 'the configuration option "%s".', 49 phutil_tag('tt', array(), 'master'), 50 phutil_tag('tt', array(), 'cluster.databases')); 51 $button = pht('Wait Patiently'); 52 break; 53 case PhabricatorEnv::READONLY_UNREACHABLE: 54 $title = pht('Unable to Reach Master'); 55 $body[] = pht( 56 'This server was unable to connect to the writable ("master") '. 57 'database while handling this request, and automatically degraded '. 58 'into read-only mode.'); 59 $body[] = pht( 60 'This may happen if there is a temporary network anomaly on the '. 61 'server side, like cosmic radiation or spooky ghosts. If this '. 62 'failure was caused by a transient service interruption, '. 63 'this server will recover momentarily.'); 64 $body[] = pht( 65 'This may also indicate that a more serious failure has occurred. '. 66 'If this interruption does not resolve on its own, this server '. 67 'will soon detect the persistent disruption and degrade into '. 68 'read-only mode until the issue is resolved.'); 69 $button = pht('Quite Unsettling'); 70 break; 71 case PhabricatorEnv::READONLY_SEVERED: 72 $title = pht('Severed From Master'); 73 $body[] = pht( 74 'This server has consistently been unable to reach the writable '. 75 '("master") database while processing recent requests.'); 76 $body[] = pht( 77 'This likely indicates a severe misconfiguration or major service '. 78 'interruption.'); 79 $body[] = pht( 80 'This server will periodically retry the connection and recover '. 81 'once service is restored. Most causes of persistent service '. 82 'interruption will require administrative intervention in order '. 83 'to restore service.'); 84 $body[] = pht( 85 'Although this may be the result of a misconfiguration or '. 86 'operational error, this is also the state you reach if a '. 87 'meteor recently obliterated a datacenter.'); 88 $button = pht('Panic!'); 89 break; 90 default: 91 return new Aphront404Response(); 92 } 93 94 switch ($reason) { 95 case PhabricatorEnv::READONLY_UNREACHABLE: 96 case PhabricatorEnv::READONLY_SEVERED: 97 $body[] = pht( 98 'This request was served from a replica database. Replica '. 99 'databases may lag behind the master, so very recent activity '. 100 'may not be reflected in the UI. This data will be restored if '. 101 'the master database is restored, but may have been lost if the '. 102 'master database has been reduced to a pile of ash.'); 103 break; 104 } 105 106 $body[] = pht( 107 'In read-only mode you can read existing information, but you will not '. 108 'be able to edit objects or create new objects until this mode is '. 109 'disabled.'); 110 111 if ($viewer->getIsAdmin()) { 112 $body[] = pht( 113 'As an Administrator, you can review status information from the '. 114 '%s control panel. This may provide more information about the '. 115 'current state of affairs.', 116 phutil_tag( 117 'a', 118 array( 119 'href' => '/config/cluster/databases/', 120 ), 121 pht('Cluster Database Status'))); 122 } 123 124 $dialog = $this->newDialog() 125 ->setTitle($title) 126 ->setWidth(AphrontDialogView::WIDTH_FORM) 127 ->addCancelButton('/', $button); 128 129 foreach ($body as $paragraph) { 130 $dialog->appendParagraph($paragraph); 131 } 132 133 return $dialog; 134 } 135}