30 if (!$this->hasTable($table)) {
34 $prefix = $this->getAdapter()->getOption(
'table_prefix');
35 $row = $this->fetchRow(
" 36 SELECT count(DISTINCT site_guid) as count 37 FROM {$prefix}{$table} 40 if ($row && $row[
'count'] > 1) {
41 throw new InstallationException(
"Multiple sites detected in table: '{$prefix}{$table}'. Can't upgrade the database.");
49 public function up() {
53 if ($this->hasTable(
'access_collections')) {
54 $table = $this->table(
'access_collections');
56 if (
$table->hasIndexByName(
'site_guid')) {
57 $table->removeIndexByName(
'site_guid')->save();
60 if (
$table->hasColumn(
'site_guid')) {
61 $table->removeColumn(
'site_guid')->save();
65 if ($this->hasTable(
'api_users')) {
66 $table = $this->table(
'api_users');
68 if (
$table->hasColumn(
'site_guid')) {
69 $table->removeColumn(
'site_guid')->save();
73 if ($this->hasTable(
'config')) {
74 $prefix = $this->getAdapter()->getOption(
'table_prefix');
75 $this->query(
"ALTER TABLE {$prefix}config DROP PRIMARY KEY, ADD PRIMARY KEY(name)");
76 $table = $this->table(
'config');
78 if (
$table->hasIndexByName(
'site_guid')) {
79 $table->removeIndexByName(
'site_guid')->save();
82 if (
$table->hasColumn(
'site_guid')) {
83 $table->removeColumn(
'site_guid')->save();
87 if ($this->hasTable(
'entities')) {
88 $table = $this->table(
'entities');
90 if (
$table->hasIndexByName(
'site_guid')) {
91 $table->removeIndexByName(
'site_guid')->save();
94 if (
$table->hasColumn(
'site_guid')) {
95 $table->removeColumn(
'site_guid')->save();
99 if ($this->hasTable(
'users_apisessions')) {
100 $table = $this->table(
'users_apisessions');
102 if (
$table->hasIndexByName(
'site_guid')) {
103 $table->removeIndexByName(
'site_guid')->save();
106 $prefix = $this->getAdapter()->getOption(
'table_prefix');
107 $this->query(
"ALTER TABLE {$prefix}users_apisessions DROP KEY user_guid, ADD UNIQUE KEY user_guid(user_guid)");
109 if (
$table->hasColumn(
'site_guid')) {
110 $table->removeColumn(
'site_guid')->save();
113 if (
$table->hasIndexByName(
'user_guid')) {
114 $table->removeIndexByName(
'user_guid')->save();
117 $table->addIndex([
'user_guid'], [
118 'name' =>
"user_guid",
123 if ($this->hasTable(
'entity_relationships')) {
125 $prefix = $this->getAdapter()->getOption(
'table_prefix');
127 DELETE FROM {$prefix}entity_relationships 128 WHERE relationship = 'member_of_site' 139 if ($this->hasTable(
'access_collections')) {
140 $table = $this->table(
'access_collections');
142 if (!
$table->hasColumn(
'site_guid')) {
143 $table->addColumn(
'site_guid',
'integer', [
145 'limit' => MysqlAdapter::INT_BIG,
151 if (!
$table->hasIndexByName(
'site_guid')) {
152 $table->addIndex([
'site_guid'], [
153 'name' =>
'site_guid',
158 $prefix = $this->getAdapter()->getOption(
'table_prefix');
160 UPDATE {$prefix}access_collections 166 if ($this->hasTable(
'api_users')) {
167 $table = $this->table(
'api_users');
169 if (!
$table->hasColumn(
'site_guid')) {
170 $table->addColumn(
'site_guid',
'integer', [
172 'limit' => MysqlAdapter::INT_BIG,
178 $prefix = $this->getAdapter()->getOption(
'table_prefix');
180 UPDATE {$prefix}api_users 186 if ($this->hasTable(
'config')) {
187 $table = $this->table(
'config', [
194 if (!
$table->hasColumn(
'site_guid')) {
195 $table->addColumn(
'site_guid',
'integer', [
197 'limit' => MysqlAdapter::INT_BIG,
203 if (!
$table->hasIndexByName(
'site_guid')) {
204 $table->addIndex([
'site_guid'], [
205 'name' =>
'site_guid',
210 $prefix = $this->getAdapter()->getOption(
'table_prefix');
212 UPDATE {$prefix}config 218 if ($this->hasTable(
'entities')) {
220 $table = $this->table(
'entities');
222 if (!
$table->hasColumn(
'site_guid')) {
223 $table->addColumn(
'site_guid',
'integer', [
225 'limit' => MysqlAdapter::INT_BIG,
231 if (!
$table->hasIndexByName(
'site_guid')) {
232 $table->addIndex([
'site_guid'], [
233 'name' =>
'site_guid',
238 $prefix = $this->getAdapter()->getOption(
'table_prefix');
240 UPDATE {$prefix}entities 245 if ($this->hasTable(
'entity_relationships')) {
246 $rows = $this->fetchAll(
" 247 SELECT guid FROM {$prefix}entities 251 foreach (
$rows as $row) {
252 $this->table(
'entity_relationships')->insert([[
253 'guid_one' => $row[
'guid'],
254 'relationship' =>
'member_of_site',
256 'time_created' => time(),
262 if ($this->hasTable(
'users_apisessions')) {
264 $table = $this->table(
'users_apisessions');
266 if (
$table->hasIndexByName(
'site_guid')) {
267 $table->removeIndexByName(
'site_guid')->save();
270 if (!
$table->hasColumn(
'site_guid')) {
271 $table->addColumn(
'site_guid',
'integer', [
273 'limit' => MysqlAdapter::INT_BIG,
279 if (
$table->hasIndexByName(
'user_guid')) {
280 $table->removeIndexByName(
'user_guid')->save();
287 'name' =>
"user_guid",
291 $prefix = $this->getAdapter()->getOption(
'table_prefix');
293 UPDATE {$prefix}users_apisessions
validate()
Ensure that legacy schema only has 1 site entity Refuse to upgrade if it doesn't. ...
down()
Add site_guid column and index.
Updates the basic settings for the primary site object.
Thrown when there is a major problem with the installation.
up()
Removes site guid from legacy 2.x tables.
Removes multisite support from 2.x schema.