2014-09-18 17:22:18 +02:00
|
|
|
<?php
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
final class PhabricatorConfigTableSchema
|
|
|
|
extends PhabricatorConfigStorageSchema {
|
2014-09-18 17:22:18 +02:00
|
|
|
|
|
|
|
private $collation;
|
|
|
|
private $columns = array();
|
2014-09-18 17:32:21 +02:00
|
|
|
private $keys = array();
|
2014-09-18 17:22:18 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:32:21 +02:00
|
|
|
public function addKey(PhabricatorConfigKeySchema $key) {
|
|
|
|
$name = $key->getName();
|
|
|
|
if (isset($this->keys[$name])) {
|
|
|
|
throw new Exception(
|
|
|
|
pht('Trying to add duplicate key "%s"!', $name));
|
|
|
|
}
|
|
|
|
$this->keys[$name] = $key;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:18 +02:00
|
|
|
public function getColumns() {
|
|
|
|
return $this->columns;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
public function getColumn($key) {
|
|
|
|
return idx($this->getColumns(), $key);
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:32:21 +02:00
|
|
|
public function getKeys() {
|
|
|
|
return $this->keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getKey($key) {
|
|
|
|
return idx($this->getKeys(), $key);
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
protected function getSubschemata() {
|
2014-09-18 17:32:21 +02:00
|
|
|
return array_merge($this->getColumns(), $this->getKeys());
|
2014-09-18 17:22:54 +02:00
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:18 +02:00
|
|
|
public function setCollation($collation) {
|
|
|
|
$this->collation = $collation;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCollation() {
|
|
|
|
return $this->collation;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
public function compareToSimilarSchema(
|
|
|
|
PhabricatorConfigStorageSchema $expect) {
|
|
|
|
|
|
|
|
$issues = array();
|
|
|
|
if ($this->getCollation() != $expect->getCollation()) {
|
|
|
|
$issues[] = self::ISSUE_COLLATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $issues;
|
2014-09-18 17:22:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-18 17:22:54 +02:00
|
|
|
public function newEmptyClone() {
|
|
|
|
$clone = clone $this;
|
|
|
|
$clone->columns = array();
|
2014-09-18 17:32:21 +02:00
|
|
|
$clone->keys = array();
|
2014-09-18 17:22:54 +02:00
|
|
|
return $clone;
|
2014-09-18 17:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|