Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/schema/PhabricatorConfigTableSchema.php
12256 views
1
<?php
2
3
final class PhabricatorConfigTableSchema
4
extends PhabricatorConfigStorageSchema {
5
6
private $collation;
7
private $engine;
8
private $columns = array();
9
private $keys = array();
10
private $persistenceType = self::PERSISTENCE_DATA;
11
12
const PERSISTENCE_DATA = 'data';
13
const PERSISTENCE_CACHE = 'cache';
14
const PERSISTENCE_INDEX = 'index';
15
16
public function addColumn(PhabricatorConfigColumnSchema $column) {
17
$key = $column->getName();
18
if (isset($this->columns[$key])) {
19
throw new Exception(
20
pht('Trying to add duplicate column "%s"!', $key));
21
}
22
$this->columns[$key] = $column;
23
return $this;
24
}
25
26
public function addKey(PhabricatorConfigKeySchema $key) {
27
$name = $key->getName();
28
if (isset($this->keys[$name])) {
29
throw new Exception(
30
pht('Trying to add duplicate key "%s"!', $name));
31
}
32
$key->setTable($this);
33
$this->keys[$name] = $key;
34
return $this;
35
}
36
37
public function getColumns() {
38
return $this->columns;
39
}
40
41
public function getColumn($key) {
42
return idx($this->getColumns(), $key);
43
}
44
45
public function getKeys() {
46
return $this->keys;
47
}
48
49
public function getKey($key) {
50
return idx($this->getKeys(), $key);
51
}
52
53
public function setPersistenceType($persistence_type) {
54
$this->persistenceType = $persistence_type;
55
return $this;
56
}
57
58
public function getPersistenceType() {
59
return $this->persistenceType;
60
}
61
62
public function getPersistenceTypeDisplayName() {
63
$map = array(
64
self::PERSISTENCE_DATA => pht('Data'),
65
self::PERSISTENCE_CACHE => pht('Cache'),
66
self::PERSISTENCE_INDEX => pht('Index'),
67
);
68
69
$type = $this->getPersistenceType();
70
71
return idx($map, $type, $type);
72
}
73
74
protected function getSubschemata() {
75
// NOTE: Keys and columns may have the same name, so make sure we return
76
// everything.
77
78
return array_merge(
79
array_values($this->columns),
80
array_values($this->keys));
81
}
82
83
public function setCollation($collation) {
84
$this->collation = $collation;
85
return $this;
86
}
87
88
public function getCollation() {
89
return $this->collation;
90
}
91
92
public function setEngine($engine) {
93
$this->engine = $engine;
94
return $this;
95
}
96
97
public function getEngine() {
98
return $this->engine;
99
}
100
101
protected function compareToSimilarSchema(
102
PhabricatorConfigStorageSchema $expect) {
103
104
$issues = array();
105
if ($this->getCollation() != $expect->getCollation()) {
106
$issues[] = self::ISSUE_COLLATION;
107
}
108
109
if ($this->getEngine() != $expect->getEngine()) {
110
$issues[] = self::ISSUE_ENGINE;
111
}
112
113
return $issues;
114
}
115
116
public function newEmptyClone() {
117
$clone = clone $this;
118
$clone->columns = array();
119
$clone->keys = array();
120
return $clone;
121
}
122
123
}
124
125