[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhabricatorConfigStorageSchema extends Phobject { 4 5 const ISSUE_MISSING = 'missing'; 6 const ISSUE_MISSINGKEY = 'missingkey'; 7 const ISSUE_SURPLUS = 'surplus'; 8 const ISSUE_SURPLUSKEY = 'surpluskey'; 9 const ISSUE_CHARSET = 'charset'; 10 const ISSUE_COLLATION = 'collation'; 11 const ISSUE_COLUMNTYPE = 'columntype'; 12 const ISSUE_NULLABLE = 'nullable'; 13 const ISSUE_KEYCOLUMNS = 'keycolumns'; 14 const ISSUE_UNIQUE = 'unique'; 15 const ISSUE_LONGKEY = 'longkey'; 16 const ISSUE_SUBWARN = 'subwarn'; 17 const ISSUE_SUBFAIL = 'subfail'; 18 const ISSUE_AUTOINCREMENT = 'autoincrement'; 19 const ISSUE_UNKNOWN = 'unknown'; 20 21 const STATUS_OKAY = 'okay'; 22 const STATUS_WARN = 'warn'; 23 const STATUS_FAIL = 'fail'; 24 25 private $issues = array(); 26 private $name; 27 28 abstract public function newEmptyClone(); 29 abstract protected function compareToSimilarSchema( 30 PhabricatorConfigStorageSchema $expect); 31 abstract protected function getSubschemata(); 32 33 public function compareTo(PhabricatorConfigStorageSchema $expect) { 34 if (get_class($expect) != get_class($this)) { 35 throw new Exception(pht('Classes must match to compare schemata!')); 36 } 37 38 if ($this->getName() != $expect->getName()) { 39 throw new Exception(pht('Names must match to compare schemata!')); 40 } 41 42 return $this->compareToSimilarSchema($expect); 43 } 44 45 public function setName($name) { 46 $this->name = $name; 47 return $this; 48 } 49 50 public function getName() { 51 return $this->name; 52 } 53 54 public function setIssues(array $issues) { 55 $this->issues = array_fuse($issues); 56 return $this; 57 } 58 59 public function getIssues() { 60 $issues = $this->issues; 61 62 foreach ($this->getSubschemata() as $sub) { 63 switch ($sub->getStatus()) { 64 case self::STATUS_WARN: 65 $issues[self::ISSUE_SUBWARN] = self::ISSUE_SUBWARN; 66 break; 67 case self::STATUS_FAIL: 68 $issues[self::ISSUE_SUBFAIL] = self::ISSUE_SUBFAIL; 69 break; 70 } 71 } 72 73 return $issues; 74 } 75 76 public function getLocalIssues() { 77 return $this->issues; 78 } 79 80 public function hasIssue($issue) { 81 return (bool)idx($this->getIssues(), $issue); 82 } 83 84 public function getAllIssues() { 85 $issues = $this->getIssues(); 86 foreach ($this->getSubschemata() as $sub) { 87 $issues += $sub->getAllIssues(); 88 } 89 return $issues; 90 } 91 92 public function getStatus() { 93 $status = self::STATUS_OKAY; 94 foreach ($this->getAllIssues() as $issue) { 95 $issue_status = self::getIssueStatus($issue); 96 $status = self::getStrongestStatus($status, $issue_status); 97 } 98 return $status; 99 } 100 101 public static function getIssueName($issue) { 102 switch ($issue) { 103 case self::ISSUE_MISSING: 104 return pht('Missing'); 105 case self::ISSUE_MISSINGKEY: 106 return pht('Missing Key'); 107 case self::ISSUE_SURPLUS: 108 return pht('Surplus'); 109 case self::ISSUE_SURPLUSKEY: 110 return pht('Surplus Key'); 111 case self::ISSUE_CHARSET: 112 return pht('Better Character Set Available'); 113 case self::ISSUE_COLLATION: 114 return pht('Better Collation Available'); 115 case self::ISSUE_COLUMNTYPE: 116 return pht('Wrong Column Type'); 117 case self::ISSUE_NULLABLE: 118 return pht('Wrong Nullable Setting'); 119 case self::ISSUE_KEYCOLUMNS: 120 return pht('Key on Wrong Columns'); 121 case self::ISSUE_UNIQUE: 122 return pht('Key has Wrong Uniqueness'); 123 case self::ISSUE_LONGKEY: 124 return pht('Key is Too Long'); 125 case self::ISSUE_SUBWARN: 126 return pht('Subschemata Have Warnings'); 127 case self::ISSUE_SUBFAIL: 128 return pht('Subschemata Have Failures'); 129 case self::ISSUE_AUTOINCREMENT: 130 return pht('Column has Wrong Autoincrement'); 131 case self::ISSUE_UNKNOWN: 132 return pht('Column Has No Specification'); 133 default: 134 throw new Exception(pht('Unknown schema issue "%s"!', $issue)); 135 } 136 } 137 138 public static function getIssueDescription($issue) { 139 switch ($issue) { 140 case self::ISSUE_MISSING: 141 return pht('This schema is expected to exist, but does not.'); 142 case self::ISSUE_MISSINGKEY: 143 return pht('This key is expected to exist, but does not.'); 144 case self::ISSUE_SURPLUS: 145 return pht('This schema is not expected to exist.'); 146 case self::ISSUE_SURPLUSKEY: 147 return pht('This key is not expected to exist.'); 148 case self::ISSUE_CHARSET: 149 return pht('This schema can use a better character set.'); 150 case self::ISSUE_COLLATION: 151 return pht('This schema can use a better collation.'); 152 case self::ISSUE_COLUMNTYPE: 153 return pht('This schema can use a better column type.'); 154 case self::ISSUE_NULLABLE: 155 return pht('This schema has the wrong nullable setting.'); 156 case self::ISSUE_KEYCOLUMNS: 157 return pht('This key is on the wrong columns.'); 158 case self::ISSUE_UNIQUE: 159 return pht('This key has the wrong uniqueness setting.'); 160 case self::ISSUE_LONGKEY: 161 return pht('This key is too long for utf8mb4.'); 162 case self::ISSUE_SUBWARN: 163 return pht('Subschemata have setup warnings.'); 164 case self::ISSUE_SUBFAIL: 165 return pht('Subschemata have setup failures.'); 166 case self::ISSUE_AUTOINCREMENT: 167 return pht('This column has the wrong autoincrement setting.'); 168 case self::ISSUE_UNKNOWN: 169 return pht('This column is missing a type specification.'); 170 default: 171 throw new Exception(pht('Unknown schema issue "%s"!', $issue)); 172 } 173 } 174 175 public static function getIssueStatus($issue) { 176 switch ($issue) { 177 case self::ISSUE_MISSING: 178 case self::ISSUE_SURPLUS: 179 case self::ISSUE_NULLABLE: 180 case self::ISSUE_SUBFAIL: 181 case self::ISSUE_UNKNOWN: 182 return self::STATUS_FAIL; 183 case self::ISSUE_SUBWARN: 184 case self::ISSUE_COLUMNTYPE: 185 case self::ISSUE_CHARSET: 186 case self::ISSUE_COLLATION: 187 case self::ISSUE_MISSINGKEY: 188 case self::ISSUE_SURPLUSKEY: 189 case self::ISSUE_UNIQUE: 190 case self::ISSUE_KEYCOLUMNS: 191 case self::ISSUE_LONGKEY: 192 case self::ISSUE_AUTOINCREMENT: 193 return self::STATUS_WARN; 194 default: 195 throw new Exception(pht('Unknown schema issue "%s"!', $issue)); 196 } 197 } 198 199 public static function getStatusSeverity($status) { 200 switch ($status) { 201 case self::STATUS_FAIL: 202 return 2; 203 case self::STATUS_WARN: 204 return 1; 205 case self::STATUS_OKAY: 206 return 0; 207 default: 208 throw new Exception(pht('Unknown schema status "%s"!', $status)); 209 } 210 } 211 212 public static function getStrongestStatus($u, $v) { 213 $u_sev = self::getStatusSeverity($u); 214 $v_sev = self::getStatusSeverity($v); 215 216 if ($u_sev >= $v_sev) { 217 return $u; 218 } else { 219 return $v; 220 } 221 } 222 223 224 }
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 |