diff --git a/src/applications/config/schema/PhabricatorConfigColumnSchema.php b/src/applications/config/schema/PhabricatorConfigColumnSchema.php index dc60353233..091b5caef9 100644 --- a/src/applications/config/schema/PhabricatorConfigColumnSchema.php +++ b/src/applications/config/schema/PhabricatorConfigColumnSchema.php @@ -1,162 +1,162 @@ <?php final class PhabricatorConfigColumnSchema extends PhabricatorConfigStorageSchema { private $characterSet; private $collation; private $columnType; private $dataType; private $nullable; private $autoIncrement; public function setAutoIncrement($auto_increment) { $this->autoIncrement = $auto_increment; return $this; } public function getAutoIncrement() { return $this->autoIncrement; } public function setNullable($nullable) { $this->nullable = $nullable; return $this; } public function getNullable() { return $this->nullable; } public function setColumnType($column_type) { $this->columnType = $column_type; return $this; } public function getColumnType() { return $this->columnType; } protected function getSubschemata() { return array(); } public function setDataType($data_type) { $this->dataType = $data_type; return $this; } public function getDataType() { return $this->dataType; } public function setCollation($collation) { $this->collation = $collation; return $this; } public function getCollation() { return $this->collation; } public function setCharacterSet($character_set) { $this->characterSet = $character_set; return $this; } public function getCharacterSet() { return $this->characterSet; } public function getKeyByteLength($prefix = null) { $type = $this->getColumnType(); $matches = null; if (preg_match('/^(?:var)?char\((\d+)\)$/', $type, $matches)) { // For utf8mb4, each character requires 4 bytes. $size = (int)$matches[1]; if ($prefix && $prefix < $size) { $size = $prefix; } return $size * 4; } $matches = null; if (preg_match('/^(?:var)?binary\((\d+)\)$/', $type, $matches)) { // binary()/varbinary() store fixed-length binary data, so their size // is always the column size. $size = (int)$matches[1]; if ($prefix && $prefix < $size) { $size = $prefix; } return $size; } // The "long..." types are arbitrarily long, so just use a big number to // get the point across. In practice, these should always index only a // prefix. if ($type == 'longtext') { $size = (1 << 16); if ($prefix && $prefix < $size) { $size = $prefix; } return $size * 4; } if ($type == 'longblob') { $size = (1 << 16); if ($prefix && $prefix < $size) { $size = $prefix; } return $size * 1; } switch ($type) { case 'int(10) unsigned': return 4; } // TODO: Build this out to catch overlong indexes. return 0; } - public function compareToSimilarSchema( + protected function compareToSimilarSchema( PhabricatorConfigStorageSchema $expect) { $issues = array(); $type_unknown = PhabricatorConfigSchemaSpec::DATATYPE_UNKNOWN; if ($expect->getColumnType() == $type_unknown) { $issues[] = self::ISSUE_UNKNOWN; } else { if ($this->getCharacterSet() != $expect->getCharacterSet()) { $issues[] = self::ISSUE_CHARSET; } if ($this->getCollation() != $expect->getCollation()) { $issues[] = self::ISSUE_COLLATION; } if ($this->getColumnType() != $expect->getColumnType()) { $issues[] = self::ISSUE_COLUMNTYPE; } if ($this->getNullable() !== $expect->getNullable()) { $issues[] = self::ISSUE_NULLABLE; } if ($this->getAutoIncrement() !== $expect->getAutoIncrement()) { $issues[] = self::ISSUE_AUTOINCREMENT; } } return $issues; } public function newEmptyClone() { $clone = clone $this; return $clone; } } diff --git a/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php b/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php index f67d062c27..bf0af3f480 100644 --- a/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php +++ b/src/applications/config/schema/PhabricatorConfigDatabaseSchema.php @@ -1,71 +1,71 @@ <?php final class PhabricatorConfigDatabaseSchema extends PhabricatorConfigStorageSchema { private $characterSet; private $collation; private $tables = array(); public function addTable(PhabricatorConfigTableSchema $table) { $key = $table->getName(); if (isset($this->tables[$key])) { throw new Exception( pht('Trying to add duplicate table "%s"!', $key)); } $this->tables[$key] = $table; return $this; } public function getTables() { return $this->tables; } public function getTable($key) { return idx($this->tables, $key); } protected function getSubschemata() { return $this->getTables(); } - public function compareToSimilarSchema( + protected function compareToSimilarSchema( PhabricatorConfigStorageSchema $expect) { $issues = array(); if ($this->getCharacterSet() != $expect->getCharacterSet()) { $issues[] = self::ISSUE_CHARSET; } if ($this->getCollation() != $expect->getCollation()) { $issues[] = self::ISSUE_COLLATION; } return $issues; } public function newEmptyClone() { $clone = clone $this; $clone->tables = array(); return $clone; } public function setCollation($collation) { $this->collation = $collation; return $this; } public function getCollation() { return $this->collation; } public function setCharacterSet($character_set) { $this->characterSet = $character_set; return $this; } public function getCharacterSet() { return $this->characterSet; } } diff --git a/src/applications/config/schema/PhabricatorConfigKeySchema.php b/src/applications/config/schema/PhabricatorConfigKeySchema.php index 5fe11842de..b30a3641e9 100644 --- a/src/applications/config/schema/PhabricatorConfigKeySchema.php +++ b/src/applications/config/schema/PhabricatorConfigKeySchema.php @@ -1,114 +1,114 @@ <?php final class PhabricatorConfigKeySchema extends PhabricatorConfigStorageSchema { const MAX_INNODB_KEY_LENGTH = 767; private $columnNames; private $unique; private $table; private $indexType; public function setIndexType($index_type) { $this->indexType = $index_type; return $this; } public function getIndexType() { return $this->indexType; } public function setProperty($property) { $this->property = $property; return $this; } public function getProperty() { return $this->property; } public function setUnique($unique) { $this->unique = $unique; return $this; } public function getUnique() { return $this->unique; } public function setTable(PhabricatorConfigTableSchema $table) { $this->table = $table; return $this; } public function getTable() { return $this->table; } public function setColumnNames(array $column_names) { $this->columnNames = array_values($column_names); return $this; } public function getColumnNames() { return $this->columnNames; } protected function getSubschemata() { return array(); } public function getKeyColumnAndPrefix($column_name) { $matches = null; if (preg_match('/^(.*)\((\d+)\)\z/', $column_name, $matches)) { return array($matches[1], (int)$matches[2]); } else { return array($column_name, null); } } public function getKeyByteLength() { $size = 0; foreach ($this->getColumnNames() as $column_spec) { list($column_name, $prefix) = $this->getKeyColumnAndPrefix($column_spec); $column = $this->getTable()->getColumn($column_name); if (!$column) { $size = 0; break; } $size += $column->getKeyByteLength($prefix); } return $size; } - public function compareToSimilarSchema( + protected function compareToSimilarSchema( PhabricatorConfigStorageSchema $expect) { $issues = array(); if ($this->getColumnNames() !== $expect->getColumnNames()) { $issues[] = self::ISSUE_KEYCOLUMNS; } if ($this->getUnique() !== $expect->getUnique()) { $issues[] = self::ISSUE_UNIQUE; } // A fulltext index can be of any length. if ($this->getIndexType() != 'FULLTEXT') { if ($this->getKeyByteLength() > self::MAX_INNODB_KEY_LENGTH) { $issues[] = self::ISSUE_LONGKEY; } } return $issues; } public function newEmptyClone() { $clone = clone $this; $this->table = null; return $clone; } } diff --git a/src/applications/config/schema/PhabricatorConfigServerSchema.php b/src/applications/config/schema/PhabricatorConfigServerSchema.php index 2f3557fe6f..b8b21fe919 100644 --- a/src/applications/config/schema/PhabricatorConfigServerSchema.php +++ b/src/applications/config/schema/PhabricatorConfigServerSchema.php @@ -1,41 +1,41 @@ <?php final class PhabricatorConfigServerSchema extends PhabricatorConfigStorageSchema { private $databases = array(); public function addDatabase(PhabricatorConfigDatabaseSchema $database) { $key = $database->getName(); if (isset($this->databases[$key])) { throw new Exception( pht('Trying to add duplicate database "%s"!', $key)); } $this->databases[$key] = $database; return $this; } public function getDatabases() { return $this->databases; } public function getDatabase($key) { return idx($this->getDatabases(), $key); } protected function getSubschemata() { return $this->getDatabases(); } - public function compareToSimilarSchema( + protected function compareToSimilarSchema( PhabricatorConfigStorageSchema $expect) { return array(); } public function newEmptyClone() { $clone = clone $this; $clone->databases = array(); return $clone; } } diff --git a/src/applications/config/schema/PhabricatorConfigTableSchema.php b/src/applications/config/schema/PhabricatorConfigTableSchema.php index c7b0888705..b05e7e1e8e 100644 --- a/src/applications/config/schema/PhabricatorConfigTableSchema.php +++ b/src/applications/config/schema/PhabricatorConfigTableSchema.php @@ -1,83 +1,83 @@ <?php final class PhabricatorConfigTableSchema extends PhabricatorConfigStorageSchema { private $collation; private $columns = array(); private $keys = array(); public function addColumn(PhabricatorConfigColumnSchema $column) { $key = $column->getName(); if (isset($this->columns[$key])) { throw new Exception( pht('Trying to add duplicate column "%s"!', $key)); } $this->columns[$key] = $column; return $this; } public function addKey(PhabricatorConfigKeySchema $key) { $name = $key->getName(); if (isset($this->keys[$name])) { throw new Exception( pht('Trying to add duplicate key "%s"!', $name)); } $key->setTable($this); $this->keys[$name] = $key; return $this; } public function getColumns() { return $this->columns; } public function getColumn($key) { return idx($this->getColumns(), $key); } public function getKeys() { return $this->keys; } public function getKey($key) { return idx($this->getKeys(), $key); } protected function getSubschemata() { // NOTE: Keys and columns may have the same name, so make sure we return // everything. return array_merge( array_values($this->columns), array_values($this->keys)); } public function setCollation($collation) { $this->collation = $collation; return $this; } public function getCollation() { return $this->collation; } - public function compareToSimilarSchema( + protected function compareToSimilarSchema( PhabricatorConfigStorageSchema $expect) { $issues = array(); if ($this->getCollation() != $expect->getCollation()) { $issues[] = self::ISSUE_COLLATION; } return $issues; } public function newEmptyClone() { $clone = clone $this; $clone->columns = array(); $clone->keys = array(); return $clone; } }