-
Notifications
You must be signed in to change notification settings - Fork 2
/
unl_multisite.install
135 lines (127 loc) · 3.36 KB
/
unl_multisite.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
use Drupal\Core\Database\Database;
function unl_multisite_schema() {
$schema = array();
$schema['unl_sites'] = array(
'description' => 'Multisite installations.',
'fields' => array(
'site_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'd7_site_id' => array(
'type' => 'varchar',
'length' => 255,
'default' => null,
),
'site_path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'installed' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('site_id'),
'unique keys' => array(
'site_path' => array('site_path'),
'uri' => array('uri'),
),
);
$schema['unl_sites_aliases'] = array(
'description' => 'Table of URL aliases for multisite sites.',
'fields' => array(
'site_alias_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'site_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'base_uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'installed' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('site_alias_id'),
'unique keys' => array(
'alias_uri' => array('base_uri', 'path'),
),
'foreign keys' => array(
'aliased_site' => array(
'table' => 'unl_sites',
'columns' => array('site_id' => 'site_id'),
),
),
);
return $schema;
}
/**
* Adds the 'd7_site_id' and 'd7_site_path' fields to the unl_sites table.
*/
function unl_multisite_update_8001() {
$d7_site_id = [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => NULL,
];
$d7_site_path = [
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => NULL,
];
$schema = Database::getConnection()->schema();
$schema->addField('unl_sites', 'd7_site_id', $d7_site_id);
$schema->addField('unl_sites', 'd7_site_path', $d7_site_path);
}
/**
* Implements hook_update_N().
* Remove 'd7_site_path' field from 'unl_sites' table
*/
function unl_multisite_update_8002() {
$schema = \Drupal::database()->schema();
$table_name = 'unl_sites';
$field_name = 'd7_site_path';
// Check if the field exists before attempting to drop it.
if ($schema->fieldExists($table_name, $field_name)) {
// Drop the field.
$schema->dropField($table_name, $field_name);
\Drupal::messenger()->addMessage(t('Field @field has been successfully removed from @table.', [
'@field' => $field_name,
'@table' => $table_name,
]));
}
else {
\Drupal::messenger()->addMessage(t('Field @field does not exist in @table.', [
'@field' => $field_name,
'@table' => $table_name,
]), 'warning');
}
}