-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting_entities.install
More file actions
234 lines (217 loc) · 6.04 KB
/
setting_entities.install
File metadata and controls
234 lines (217 loc) · 6.04 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* Implements hook_schema().
*/
function setting_entities_schema() {
$schema = array();
$schema['settings_entity'] = array(
'description' => 'The base table for settings.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for the setting entity.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The current {settings_entity_revisions}.vid version identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
),
'active' => array(
'description' => 'Wheter the entity is active',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'description' => 'The type (bundle) of this setting.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The title of the setting entity',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'ID of Drupal user creator.',
'type' => 'int',
'not null' => TRUE,
),
'created' => array(
'description' => 'The Unix timestamp when the settings entity was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the settings entity was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
'unique keys' => array(
'vid' => array('vid'),
),
'foreign keys' => array(
'entity_revision' => array(
'table' => 'settings_entity_revisions',
'columns' => array('vid' => 'vid'),
),
'entity_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
$schema['settings_entity_revisions'] = array(
'description' => 'The base table for settings.',
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The unique identifier for the setting entity.',
),
'vid' => array(
'description' => 'The current {settings_entity_revisions}.vid version identifier.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The {users}.uid that created this version.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'title' => array(
'description' => 'The title of this version.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'changed' => array(
'description' => 'The Unix timestamp when the example was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'id' => array('id'),
'uid' => array('uid'),
),
'primary key' => array('vid'),
'foreign keys' => array(
'versioned_entity' => array(
'table' => 'settings_entity',
'columns' => array('id' => 'id'),
),
'version_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
$schema['settings_entity_type'] = array(
'description' => 'Stores information about all defined setting types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique settings entity type ID.',
),
'type' => array(
'description' => 'The machine-readable name of this type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
) + entity_exportable_schema_fields(),
'primary key' => array('id'),
'unique keys' => array(
'type' => array('type'),
),
);
return $schema;
}
/**
* Create revision table.
*/
function setting_entities_update_7001() {
$name = 'settings_entity_revisions';
$schema = setting_entities_schema();
$table = $schema[$name];
db_create_table($name, $table);
}
/**
* Add version field.
*/
function setting_entities_update_7002() {
$field = array(
'description' => 'The current {settings_entity_revisions}.vid version identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$keys = array(
'foreign keys' => array(
'entity_revision' => array(
'table' => 'settings_entity_revisions',
'columns' => array('vid' => 'vid'),
),
),
);
db_add_field('settings_entity', 'vid', $field, $keys);
}
/**
* Update existing entities.
*/
function setting_entities_update_7003() {
$q = db_select('settings_entity', 's')
->fields('s', array());
$results = $q->execute()->fetchAllAssoc('id');
foreach ($results as $entity) {
drupal_write_record('settings_entity_revisions', $entity);
drupal_write_record('settings_entity', $entity, array('id'));
}
}
/**
* Modify version field.
*/
function setting_entities_update_7004() {
$schema = setting_entities_schema();
$field = $schema['settings_entity']['fields']['vid'];
$keys = array(
'unique keys' => array(
'vid' => array('vid'),
),
'foreign keys' => array(
'entity_revision' => array(
'table' => 'settings_entity_revisions',
'columns' => array('vid' => 'vid'),
),
),
);
db_change_field('settings_entity', 'vid', 'vid', $field, $keys);
}