@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Generate reasonable expected schemata for Audit and Auth

Summary: Ref T1191. This fills in some more features and gets audit and auth nearly generating reasonable expected schemata.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D10500

+229 -20
+4
src/__phutil_library_map__.php
··· 1189 1189 'PhabricatorAuditManagementWorkflow' => 'applications/audit/management/PhabricatorAuditManagementWorkflow.php', 1190 1190 'PhabricatorAuditPreviewController' => 'applications/audit/controller/PhabricatorAuditPreviewController.php', 1191 1191 'PhabricatorAuditReplyHandler' => 'applications/audit/mail/PhabricatorAuditReplyHandler.php', 1192 + 'PhabricatorAuditSchemaSpec' => 'applications/audit/storage/PhabricatorAuditSchemaSpec.php', 1192 1193 'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php', 1193 1194 'PhabricatorAuditTransaction' => 'applications/audit/storage/PhabricatorAuditTransaction.php', 1194 1195 'PhabricatorAuditTransactionComment' => 'applications/audit/storage/PhabricatorAuditTransactionComment.php', ··· 1233 1234 'PhabricatorAuthProviderConfigTransactionQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigTransactionQuery.php', 1234 1235 'PhabricatorAuthRegisterController' => 'applications/auth/controller/PhabricatorAuthRegisterController.php', 1235 1236 'PhabricatorAuthRevokeTokenController' => 'applications/auth/controller/PhabricatorAuthRevokeTokenController.php', 1237 + 'PhabricatorAuthSchemaSpec' => 'applications/auth/storage/PhabricatorAuthSchemaSpec.php', 1236 1238 'PhabricatorAuthSession' => 'applications/auth/storage/PhabricatorAuthSession.php', 1237 1239 'PhabricatorAuthSessionEngine' => 'applications/auth/engine/PhabricatorAuthSessionEngine.php', 1238 1240 'PhabricatorAuthSessionGarbageCollector' => 'applications/auth/garbagecollector/PhabricatorAuthSessionGarbageCollector.php', ··· 4069 4071 'PhabricatorAuditManagementWorkflow' => 'PhabricatorManagementWorkflow', 4070 4072 'PhabricatorAuditPreviewController' => 'PhabricatorAuditController', 4071 4073 'PhabricatorAuditReplyHandler' => 'PhabricatorMailReplyHandler', 4074 + 'PhabricatorAuditSchemaSpec' => 'PhabricatorConfigSchemaSpec', 4072 4075 'PhabricatorAuditTransaction' => 'PhabricatorApplicationTransaction', 4073 4076 'PhabricatorAuditTransactionComment' => 'PhabricatorApplicationTransactionComment', 4074 4077 'PhabricatorAuditTransactionQuery' => 'PhabricatorApplicationTransactionQuery', ··· 4113 4116 'PhabricatorAuthProviderConfigTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 4114 4117 'PhabricatorAuthRegisterController' => 'PhabricatorAuthController', 4115 4118 'PhabricatorAuthRevokeTokenController' => 'PhabricatorAuthController', 4119 + 'PhabricatorAuthSchemaSpec' => 'PhabricatorConfigSchemaSpec', 4116 4120 'PhabricatorAuthSession' => array( 4117 4121 'PhabricatorAuthDAO', 4118 4122 'PhabricatorPolicyInterface',
+11
src/applications/audit/storage/PhabricatorAuditSchemaSpec.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuditSchemaSpec extends PhabricatorConfigSchemaSpec { 4 + 5 + public function buildSchemata() { 6 + $this->buildTransactionSchema( 7 + new PhabricatorAuditTransaction(), 8 + new PhabricatorAuditTransactionComment()); 9 + } 10 + 11 + }
+16
src/applications/audit/storage/PhabricatorAuditTransactionComment.php
··· 22 22 return ($this->getTransactionPHID() != null); 23 23 } 24 24 25 + public function getConfiguration() { 26 + $config = parent::getConfiguration(); 27 + $config[self::CONFIG_COLUMN_SCHEMA] = array( 28 + 'commitPHID' => 'phid?', 29 + 'pathID' => 'id?', 30 + 'isNewFile' => 'bool', 31 + 'lineNumber' => 'uint32', 32 + 'lineLength' => 'uint32', 33 + 'fixedState' => 'text12?', 34 + 'hasReplies' => 'bool', 35 + 'replyToCommentPHID' => 'phid?', 36 + 'legacyCommentID' => 'id?', 37 + ) + $config[self::CONFIG_COLUMN_SCHEMA]; 38 + return $config; 39 + } 40 + 25 41 }
+5
src/applications/auth/storage/PhabricatorAuthFactorConfig.php
··· 14 14 'properties' => self::SERIALIZATION_JSON, 15 15 ), 16 16 self::CONFIG_AUX_PHID => true, 17 + self::CONFIG_COLUMN_SCHEMA => array( 18 + 'factorKey' => 'text64', 19 + 'factorName' => 'text', 20 + 'factorSecret' => 'text', 21 + ), 17 22 ) + parent::getConfiguration(); 18 23 } 19 24
+8
src/applications/auth/storage/PhabricatorAuthProviderConfig.php
··· 29 29 self::CONFIG_SERIALIZATION => array( 30 30 'properties' => self::SERIALIZATION_JSON, 31 31 ), 32 + self::CONFIG_COLUMN_SCHEMA => array( 33 + 'isEnabled' => 'bool', 34 + 'shouldAllowLogin' => 'bool', 35 + 'shouldAllowRegistration' => 'bool', 36 + 'shouldAllowLink' => 'bool', 37 + 'shouldAllowUnlink' => 'bool', 38 + 'shouldTrustEmails' => 'bool', 39 + ), 32 40 ) + parent::getConfiguration(); 33 41 } 34 42
+11
src/applications/auth/storage/PhabricatorAuthSchemaSpec.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthSchemaSpec extends PhabricatorConfigSchemaSpec { 4 + 5 + public function buildSchemata() { 6 + $this->buildLiskSchemata('PhabricatorAuthDAO'); 7 + $this->buildTransactionSchema( 8 + new PhabricatorAuthProviderConfigTransaction()); 9 + } 10 + 11 + }
+10
src/applications/auth/storage/PhabricatorAuthTemporaryToken.php
··· 14 14 public function getConfiguration() { 15 15 return array( 16 16 self::CONFIG_TIMESTAMPS => false, 17 + self::CONFIG_COLUMN_SCHEMA => array( 18 + 'tokenType' => 'text64', 19 + 'tokenExpires' => 'epoch', 20 + 'tokenCode' => 'text64', 21 + ), 22 + self::CONFIG_KEY_SCHEMA => array( 23 + 'key_token' => array( 24 + 'columns' => array('objectPHID', 'tokenType', 'tokenCode'), 25 + ), 26 + ), 17 27 ) + parent::getConfiguration(); 18 28 } 19 29
+5 -2
src/applications/config/controller/PhabricatorConfigController.php
··· 11 11 12 12 $nav = new AphrontSideNavFilterView(); 13 13 $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 14 - $nav->addLabel(pht('Site Configuration')); 15 - $nav->addFilter('/', pht('Option Groups')); 14 + $nav->addLabel(pht('Configuration')); 15 + $nav->addFilter('/', pht('Browse Settings')); 16 16 $nav->addFilter('all/', pht('All Settings')); 17 + $nav->addLabel(pht('Setup')); 17 18 $nav->addFilter('issue/', pht('Setup Issues')); 19 + $nav->addLabel(pht('Database')); 18 20 $nav->addFilter('database/', pht('Database Status')); 21 + $nav->addLabel(pht('Welcome')); 19 22 $nav->addFilter('welcome/', pht('Welcome Screen')); 20 23 21 24 return $nav;
+22
src/applications/config/controller/PhabricatorConfigDatabaseController.php
··· 525 525 $actual_coltype = $actual_column->getColumnType(); 526 526 $actual_charset = $actual_column->getCharacterSet(); 527 527 $actual_collation = $actual_column->getCollation(); 528 + $actual_nullable = $actual_column->getNullable(); 528 529 } else { 529 530 $actual_coltype = null; 530 531 $actual_charset = null; 531 532 $actual_collation = null; 533 + $actual_nullable = null; 532 534 } 533 535 534 536 if ($expect_column) { ··· 536 538 $expect_coltype = $expect_column->getColumnType(); 537 539 $expect_charset = $expect_column->getCharacterSet(); 538 540 $expect_collation = $expect_column->getCollation(); 541 + $expect_nullable = $expect_column->getNullable(); 539 542 } else { 540 543 $data_type = null; 541 544 $expect_coltype = null; 542 545 $expect_charset = null; 543 546 $expect_collation = null; 547 + $expect_nullable = null; 544 548 } 545 549 546 550 ··· 579 583 array( 580 584 pht('Expected Collation'), 581 585 $expect_collation, 586 + ), 587 + array( 588 + pht('Nullable'), 589 + $this->getNullableString($actual_nullable), 590 + ), 591 + array( 592 + pht('Expected Nullable'), 593 + $this->getNullableString($expect_nullable), 582 594 ), 583 595 ), 584 596 $column->getIssues()); ··· 745 757 $view->addProperty(pht('Schema Status'), $status_view); 746 758 747 759 return $view; 760 + } 761 + 762 + private function getNullableString($value) { 763 + if ($value === null) { 764 + return ''; 765 + } else if ($value === true) { 766 + return pht('Yes'); 767 + } else { 768 + return pht('No'); 769 + } 748 770 } 749 771 750 772 }
+9
src/applications/config/schema/PhabricatorConfigColumnSchema.php
··· 67 67 return ((int)$matches[1]) * 4; 68 68 } 69 69 70 + switch ($type) { 71 + case 'int(10) unsigned': 72 + return 4; 73 + } 74 + 70 75 // TODO: Build this out to catch overlong indexes. 71 76 72 77 return 0; ··· 86 91 87 92 if ($this->getColumnType() != $expect->getColumnType()) { 88 93 $issues[] = self::ISSUE_COLUMNTYPE; 94 + } 95 + 96 + if ($this->getNullable() !== $expect->getNullable()) { 97 + $issues[] = self::ISSUE_NULLABLE; 89 98 } 90 99 91 100 return $issues;
+1 -1
src/applications/config/schema/PhabricatorConfigKeySchema.php
··· 6 6 private $columnNames; 7 7 8 8 public function setColumnNames(array $column_names) { 9 - $this->columnNames = $column_names; 9 + $this->columnNames = array_values($column_names); 10 10 return $this; 11 11 } 12 12
+75 -15
src/applications/config/schema/PhabricatorConfigSchemaSpec.php
··· 42 42 ->loadObjects(); 43 43 44 44 foreach ($objects as $object) { 45 - $database = $this->getDatabase($object->getApplicationName()); 45 + $this->buildLiskObjectSchema($object); 46 + } 47 + } 48 + 49 + protected function buildTransactionSchema( 50 + PhabricatorApplicationTransaction $xaction, 51 + PhabricatorApplicationTransactionComment $comment = null) { 52 + 53 + $this->buildLiskObjectSchema($xaction); 54 + if ($comment) { 55 + $this->buildLiskObjectSchema($comment); 56 + } 57 + } 46 58 47 - $table = $this->newTable($object->getTableName()); 59 + private function buildLiskObjectSchema(PhabricatorLiskDAO $object) { 60 + $database = $this->getDatabase($object->getApplicationName()); 48 61 49 - $cols = $object->getSchemaColumns(); 50 - foreach ($cols as $name => $type) { 51 - $details = $this->getDetailsForDataType($type); 52 - list($column_type, $charset, $collation) = $details; 62 + $table = $this->newTable($object->getTableName()); 53 63 54 - $column = $this->newColumn($name) 55 - ->setDataType($type) 56 - ->setColumnType($column_type) 57 - ->setCharacterSet($charset) 58 - ->setCollation($collation); 64 + $cols = $object->getSchemaColumns(); 65 + foreach ($cols as $name => $type) { 66 + $details = $this->getDetailsForDataType($type); 67 + list($column_type, $charset, $collation, $nullable) = $details; 59 68 60 - $table->addColumn($column); 61 - } 69 + $column = $this->newColumn($name) 70 + ->setDataType($type) 71 + ->setColumnType($column_type) 72 + ->setCharacterSet($charset) 73 + ->setCollation($collation) 74 + ->setNullable($nullable); 62 75 63 - $database->addTable($table); 76 + $table->addColumn($column); 64 77 } 78 + 79 + $keys = $object->getSchemaKeys(); 80 + foreach ($keys as $key_name => $key_spec) { 81 + $key = $this->newKey($key_name) 82 + ->setColumnNames(idx($key_spec, 'columns', array())); 83 + 84 + $table->addKey($key); 85 + } 86 + 87 + $database->addTable($table); 65 88 } 66 89 67 90 protected function buildEdgeSchemata(PhabricatorLiskDAO $object) {} ··· 101 124 ->setName($name); 102 125 } 103 126 127 + protected function newKey($name) { 128 + return id(new PhabricatorConfigKeySchema()) 129 + ->setName($name); 130 + } 131 + 104 132 private function getDetailsForDataType($data_type) { 105 133 $column_type = null; 106 134 $charset = null; 107 135 $collation = null; 108 136 137 + // If the type ends with "?", make the column nullable. 138 + $nullable = false; 139 + if (preg_match('/\?$/', $data_type)) { 140 + $nullable = true; 141 + $data_type = substr($data_type, 0, -1); 142 + } 143 + 109 144 switch ($data_type) { 110 145 case 'id': 111 146 case 'epoch': 147 + case 'uint32': 112 148 $column_type = 'int(10) unsigned'; 113 149 break; 114 150 case 'phid': 151 + case 'policy'; 115 152 $column_type = 'varchar(64)'; 116 153 $charset = 'binary'; 117 154 $collation = 'binary'; ··· 121 158 $charset = 'binary'; 122 159 $collation = 'binary'; 123 160 break; 161 + case 'text128': 162 + $column_type = 'varchar(128)'; 163 + $charset = $this->getUTF8Charset(); 164 + $collation = $this->getUTF8Collation(); 165 + break; 166 + case 'text64': 167 + $column_type = 'varchar(64)'; 168 + $charset = $this->getUTF8Charset(); 169 + $collation = $this->getUTF8Collation(); 170 + break; 171 + case 'text32': 172 + $column_type = 'varchar(32)'; 173 + $charset = $this->getUTF8Charset(); 174 + $collation = $this->getUTF8Collation(); 175 + break; 176 + case 'text12': 177 + $column_type = 'varchar(12)'; 178 + $charset = $this->getUTF8Charset(); 179 + $collation = $this->getUTF8Collation(); 180 + break; 124 181 case 'text': 125 182 $column_type = 'longtext'; 126 183 $charset = $this->getUTF8Charset(); 127 184 $collation = $this->getUTF8Collation(); 128 185 break; 186 + case 'bool': 187 + $column_type = 'tinyint(1)'; 188 + break; 129 189 default: 130 190 $column_type = pht('<unknown>'); 131 191 $charset = pht('<unknown>'); ··· 133 193 break; 134 194 } 135 195 136 - return array($column_type, $charset, $collation); 196 + return array($column_type, $charset, $collation, $nullable); 137 197 } 138 198 139 199 }
+3 -2
src/applications/config/schema/PhabricatorConfigStorageSchema.php
··· 95 95 case self::ISSUE_SURPLUS: 96 96 return pht('Surplus'); 97 97 case self::ISSUE_CHARSET: 98 - return pht('Wrong Character Set'); 98 + return pht('Better Character Set Available'); 99 99 case self::ISSUE_COLLATION: 100 - return pht('Wrong Collation'); 100 + return pht('Better Collation Available'); 101 101 case self::ISSUE_COLUMNTYPE: 102 102 return pht('Wrong Column Type'); 103 103 case self::ISSUE_NULLABLE: ··· 149 149 case self::ISSUE_COLUMNTYPE: 150 150 case self::ISSUE_SUBWARN: 151 151 case self::ISSUE_KEYCOLUMNS: 152 + case self::ISSUE_NULLABLE: 152 153 return self::STATUS_WARN; 153 154 default: 154 155 throw new Exception(pht('Unknown schema issue "%s"!', $issue));
+6
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 107 107 'newValue' => self::SERIALIZATION_JSON, 108 108 'metadata' => self::SERIALIZATION_JSON, 109 109 ), 110 + self::CONFIG_COLUMN_SCHEMA => array( 111 + 'commentPHID' => 'phid?', 112 + 'commentVersion' => 'uint32', 113 + 'contentSource' => 'text', 114 + 'transactionType' => 'text32', 115 + ), 110 116 ) + parent::getConfiguration(); 111 117 } 112 118
+12
src/applications/transactions/storage/PhabricatorApplicationTransactionComment.php
··· 28 28 public function getConfiguration() { 29 29 return array( 30 30 self::CONFIG_AUX_PHID => true, 31 + self::CONFIG_COLUMN_SCHEMA => array( 32 + 'transactionPHID' => 'phid?', 33 + 'commentVersion' => 'uint32', 34 + 'content' => 'text', 35 + 'contentSource' => 'text', 36 + 'isDeleted' => 'bool', 37 + ), 38 + self::CONFIG_KEY_SCHEMA => array( 39 + 'key_version' => array( 40 + 'columns' => array('transactionPHID', 'commentVersion'), 41 + ), 42 + ), 31 43 ) + parent::getConfiguration(); 32 44 } 33 45
+31
src/infrastructure/storage/lisk/LiskDAO.php
··· 170 170 const CONFIG_SERIALIZATION = 'col-serialization'; 171 171 const CONFIG_BINARY = 'binary'; 172 172 const CONFIG_COLUMN_SCHEMA = 'col-schema'; 173 + const CONFIG_KEY_SCHEMA = 'key-schema'; 173 174 174 175 const SERIALIZATION_NONE = 'id'; 175 176 const SERIALIZATION_JSON = 'json'; ··· 346 347 * 347 348 * CONFIG_COLUMN_SCHEMA 348 349 * Provide a map of columns to schema column types. 350 + * 351 + * CONFIG_KEY_SCHEMA 352 + * Provide a map of key names to key specifications. 349 353 * 350 354 * @return dictionary Map of configuration options to values. 351 355 * ··· 1736 1740 $builtin = array( 1737 1741 'id' => 'id', 1738 1742 'phid' => 'phid', 1743 + 'viewPolicy' => 'policy', 1744 + 'editPolicy' => 'policy', 1739 1745 'dateCreated' => 'epoch', 1740 1746 'dateModified' => 'epoch', 1741 1747 ); ··· 1783 1789 } 1784 1790 1785 1791 return $map; 1792 + } 1793 + 1794 + public function getSchemaKeys() { 1795 + $custom_map = $this->getConfigOption(self::CONFIG_KEY_SCHEMA); 1796 + if (!$custom_map) { 1797 + $custom_map = array(); 1798 + } 1799 + 1800 + $default_map = array(); 1801 + foreach ($this->getAllLiskProperties() as $property) { 1802 + switch ($property) { 1803 + case 'id': 1804 + $default_map['PRIMARY'] = array( 1805 + 'columns' => array('id'), 1806 + ); 1807 + break; 1808 + case 'phid': 1809 + $default_map['key_phid'] = array( 1810 + 'columns' => array('phid'), 1811 + ); 1812 + break; 1813 + } 1814 + } 1815 + 1816 + return $custom_map + $default_map; 1786 1817 } 1787 1818 1788 1819 }