-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsl7_advantage.install
executable file
·325 lines (308 loc) · 9 KB
/
sl7_advantage.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
/**
* @author Semyon Dragunov <sam.dragunov@gmail.com>
* https://github.com/SemyonDragunov
*/
/**
* Implements hook_schema().
*/
function sl7_advantage_schema() {
$schema['sl7_advantage_block'] = array(
'description' => 'The base table for sl7_advantage_block entities.',
'fields' => array(
'bid' => array(
'description' => 'Primary Key: Image ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'sid' => array(
'description' => 'The {sl7_advantage_service}.sid reference.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'The {users}.uid that create this image; initially, this is the user that created it.',
),
'created' => array(
'description' => 'The Unix timestamp when the order was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the order was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'bid' => array('bid'),
),
'foreign keys' => array(
'users' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'sl7_gallery_album' => array(
'table' => 'sl7_advantage_service',
'columns' => array('sid' => 'sid'),
),
),
'primary key' => array('bid'),
);
$schema['sl7_advantage_service'] = array(
'description' => 'The base table for sl7_advantage_service entities.',
'fields' => array(
'sid' => array(
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
'description' => 'Primary Key: Album ID.',
),
'label' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
'description' => 'Title of item.',
),
'grid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Count grid to row.',
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'The {users}.uid that create this album; initially, this is the user that created it.',
),
'created' => array(
'description' => 'The Unix timestamp when the order was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the order was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'sid' => array('sid'),
),
'foreign keys' => array(
'users' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
'primary key' => array('sid'),
);
// Optional cache table for entitycache support.
$schema['cache_entity_sl7_advantage_block'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_entity_sl7_advantage_block']['description'] = 'Cache table used to sl7_advantage_block entity records.';
$schema['cache_entity_sl7_advantage_service'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_entity_sl7_advantage_service']['description'] = 'Cache table used to sl7_advantage_service entity records.';
return $schema;
}
/**
* Implements hook_install().
*/
function sl7_advantage_install() {
// Add foreign key BD level.
db_query('
ALTER TABLE {sl7_advantage_block}
ADD CONSTRAINT {sl7_advantage_service}
FOREIGN KEY (sid) REFERENCES {sl7_advantage_service} (sid)
ON DELETE CASCADE
');
// Create fields.
_sl7_advantage_install_field();
_sl7_advantage_install_instances();
}
function _sl7_advantage_install_field() {
$fields = array(
array(
'field_name' => 'sl7_advantage_title',
'type' => 'text',
'cardinality' => 1,
'module' => 'text',
),
array(
'field_name' => 'sl7_advantage_image',
'type' => 'image',
'cardinality' => 1,
'module' => 'image',
'settings' => array(
'uri_scheme' => 'public',
'default_image' => 0,
),
'foreign keys' => array(
'fid' => array(
'columns' => array(
'fid' => 'fid',
),
'table' => 'file_managed',
),
),
'indexes' => array(
'fid' => array(
0 => 'fid',
),
),
),
array(
'field_name' => 'sl7_advantage_body',
'type' => 'text_long',
'cardinality' => 1,
'translatable' => '1',
'module' => 'text',
'foreign keys' => array(
'format' => array(
'columns' => array(
'format' => 'format',
),
'table' => 'filter_format',
),
),
'indexes' => array(
'format' => array(
0 => 'format',
),
),
),
);
foreach ($fields as $field) {
$exists = db_query("SELECT id FROM {field_config} WHERE field_name=:field_name", array(':field_name' => $field['field_name']))->fetchField();
if (!$exists) {
field_create_field($field);
}
}
}
function _sl7_advantage_install_instances() {
$instances = array(
array(
'field_name' => 'sl7_advantage_title',
'entity_type' => 'sl7_advantage_block',
'bundle' => 'sl7_advantage_block',
'label' => 'Заголовок',
'widget' => array(
'type' => 'text_textfield',
'module' => 'text',
'weight' => 1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_plain',
'module' => 'text',
'weight' => 1,
),
),
),
array(
'field_name' => 'sl7_advantage_image',
'entity_type' => 'sl7_advantage_block',
'bundle' => 'sl7_advantage_block',
'label' => 'Изображение',
'settings' => array(
'max_filesize' => 1024*1024*5,
'file_extensions' => 'png gif jpg jpeg',
'file_directory' => 'sl7_advantage',
),
'widget' => array(
'type' => 'image_image',
'module' => 'image',
'weight' => 2,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'sl7_advantage_block'
),
'weight' => 2,
),
),
),
array(
'field_name' => 'sl7_advantage_body',
'entity_type' => 'sl7_advantage_block',
'bundle' => 'sl7_advantage_block',
'label' => 'Описание',
'format' => 'plain_text',
'widget' => array(
'settings' => array(
'rows' => '5',
),
'type' => 'text_textarea',
'weight' => 3,
),
'type' => 'text_long',
'display' => array(
'default' => array(
'label' => 'hidden',
'settings' => array(),
'type' => 'text_default',
'weight' => 3,
),
),
'settings' => array(
'text_processing' => 0,
'user_register_form' => FALSE,
),
),
);
foreach ($instances as $instance) {
$exists = db_query("SELECT id FROM {field_config_instance} WHERE field_name=:field_name AND entity_type=:entity_type AND bundle=:bundle", array(':field_name' => $instance['field_name'], ':entity_type' => $instance['entity_type'], ':bundle' => $instance['bundle']))->fetchField();
if (!$exists) {
field_create_instance($instance);
}
}
}
/**
* Implements hook_uninstall().
*/
function sl7_advantage_uninstall() {
db_query('
ALTER TABLE {sl7_advantage_block}
DROP FOREIGN KEY {sl7_advantage_service}
');
// Delete fields.
field_attach_delete_bundle('sl7_advantage_block', 'sl7_advantage_block');
field_attach_delete_bundle('sl7_advantage_service', 'sl7_advantage_service');
db_delete('field_config_instance')->condition('entity_type', 'sl7_advantage_block')->execute();
db_delete('field_config_instance')->condition('entity_type', 'sl7_advantage_service')->execute();
db_delete('field_config')->condition('field_name', 'sl7_advantage_%', 'LIKE')->execute();
// Delete views.
$views = array(
'sl7_advantage_service',
'sl7_advantage_block',
);
foreach ($views as $name) {
if ($view = views_get_view($name)) {
$view->delete();
}
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'sl7_advantage_%', 'LIKE')
->execute();
foreach ($result as $row) {
variable_del($row->name);
}
field_purge_batch(1000);
}