mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
2c855a8993
Summary: Ref T6822. Test Plan: Visual inspection. These methods are only called from within the `PhabricatorConfigStorageSchema` class. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6822 Differential Revision: https://secure.phabricator.com/D11247
83 lines
1.8 KiB
PHP
83 lines
1.8 KiB
PHP
<?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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|