[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhabricatorSetupCheck { 4 5 private $issues; 6 7 abstract protected function executeChecks(); 8 9 public function getExecutionOrder() { 10 return 1; 11 } 12 13 final protected function newIssue($key) { 14 $issue = id(new PhabricatorSetupIssue()) 15 ->setIssueKey($key); 16 $this->issues[$key] = $issue; 17 18 return $issue; 19 } 20 21 final public function getIssues() { 22 return $this->issues; 23 } 24 25 final public function runSetupChecks() { 26 $this->issues = array(); 27 $this->executeChecks(); 28 } 29 30 final public static function getOpenSetupIssueCount() { 31 $cache = PhabricatorCaches::getSetupCache(); 32 return $cache->getKey('phabricator.setup.issues'); 33 } 34 35 final public static function setOpenSetupIssueCount($count) { 36 $cache = PhabricatorCaches::getSetupCache(); 37 $cache->setKey('phabricator.setup.issues', $count); 38 } 39 40 final public static function countUnignoredIssues(array $all_issues) { 41 assert_instances_of($all_issues, 'PhabricatorSetupIssue'); 42 $count = 0; 43 foreach ($all_issues as $issue) { 44 if (!$issue->getIsIgnored()) { 45 $count++; 46 } 47 } 48 return $count; 49 } 50 51 final public static function getConfigNeedsRepair() { 52 $cache = PhabricatorCaches::getSetupCache(); 53 return $cache->getKey('phabricator.setup.needs-repair'); 54 } 55 56 final public static function setConfigNeedsRepair($needs_repair) { 57 $cache = PhabricatorCaches::getSetupCache(); 58 $cache->setKey('phabricator.setup.needs-repair', $needs_repair); 59 } 60 61 final public static function deleteSetupCheckCache() { 62 $cache = PhabricatorCaches::getSetupCache(); 63 $cache->deleteKeys( 64 array( 65 'phabricator.setup.needs-repair', 66 'phabricator.setup.issues', 67 )); 68 } 69 70 final public static function willProcessRequest() { 71 $issue_count = self::getOpenSetupIssueCount(); 72 if ($issue_count === null) { 73 $issues = self::runAllChecks(); 74 foreach ($issues as $issue) { 75 if ($issue->getIsFatal()) { 76 $view = id(new PhabricatorSetupIssueView()) 77 ->setIssue($issue); 78 return id(new PhabricatorConfigResponse()) 79 ->setView($view); 80 } 81 } 82 self::setOpenSetupIssueCount(self::countUnignoredIssues($issues)); 83 } 84 85 // Try to repair configuration unless we have a clean bill of health on it. 86 // We need to keep doing this on every page load until all the problems 87 // are fixed, which is why it's separate from setup checks (which run 88 // once per restart). 89 $needs_repair = self::getConfigNeedsRepair(); 90 if ($needs_repair !== false) { 91 $needs_repair = self::repairConfig(); 92 self::setConfigNeedsRepair($needs_repair); 93 } 94 } 95 96 final public static function runAllChecks() { 97 $symbols = id(new PhutilSymbolLoader()) 98 ->setAncestorClass('PhabricatorSetupCheck') 99 ->setConcreteOnly(true) 100 ->selectAndLoadSymbols(); 101 102 $checks = array(); 103 foreach ($symbols as $symbol) { 104 $checks[] = newv($symbol['name'], array()); 105 } 106 107 $checks = msort($checks, 'getExecutionOrder'); 108 109 $issues = array(); 110 foreach ($checks as $check) { 111 $check->runSetupChecks(); 112 foreach ($check->getIssues() as $key => $issue) { 113 if (isset($issues[$key])) { 114 throw new Exception( 115 "Two setup checks raised an issue with key '{$key}'!"); 116 } 117 $issues[$key] = $issue; 118 if ($issue->getIsFatal()) { 119 break 2; 120 } 121 } 122 } 123 124 foreach (PhabricatorEnv::getEnvConfig('config.ignore-issues') 125 as $ignorable => $derp) { 126 if (isset($issues[$ignorable])) { 127 $issues[$ignorable]->setIsIgnored(true); 128 } 129 } 130 131 return $issues; 132 } 133 134 final public static function repairConfig() { 135 $needs_repair = false; 136 137 $options = PhabricatorApplicationConfigOptions::loadAllOptions(); 138 foreach ($options as $option) { 139 try { 140 $option->getGroup()->validateOption( 141 $option, 142 PhabricatorEnv::getEnvConfig($option->getKey())); 143 } catch (PhabricatorConfigValidationException $ex) { 144 PhabricatorEnv::repairConfig($option->getKey(), $option->getDefault()); 145 $needs_repair = true; 146 } 147 } 148 149 return $needs_repair; 150 } 151 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |