-
Notifications
You must be signed in to change notification settings - Fork 0
/
sl7_gallery.install
executable file
·343 lines (326 loc) · 9.75 KB
/
sl7_gallery.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/**
* Implements hook_schema().
*/
function sl7_gallery_schema() {
$schema['sl7_gallery_image'] = array(
'description' => 'The base table for sl7_gallery_image entities.',
'fields' => array(
'iid' => array(
'description' => 'Primary Key: Image ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'cover' => array(
'description' => 'The boolean option cover of album.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'aid' => array(
'description' => 'The {sl7_gallery_image}.aid 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(
'iid' => array('iid'),
'aid' => array('aid'),
'uid' => array('uid'),
'created' => array('created'),
),
'foreign keys' => array(
'users' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'sl7_gallery_album' => array(
'table' => 'sl7_gallery_album',
'columns' => array('aid' => 'aid'),
),
),
'primary key' => array('iid'),
);
$schema['sl7_gallery_album'] = array(
'description' => 'The base table for sl7_gallery_album entities.',
'fields' => array(
'aid' => 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.',
),
'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(
'aid' => array('aid'),
'uid' => array('uid'),
'created' => array('created'),
),
'foreign keys' => array(
'users' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
'primary key' => array('aid'),
);
// Optional cache table for entitycache support.
$schema['cache_entity_sl7_gallery_image'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_entity_sl7_gallery_image']['description'] = 'Cache table used to sl7_gallery_image entity records.';
$schema['cache_entity_sl7_gallery_album'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_entity_sl7_gallery_album']['description'] = 'Cache table used to sl7_gallery_album entity records.';
return $schema;
}
/**
* Implements hook_install().
*/
function sl7_gallery_install() {
// Add foreign key BD level.
db_query('
ALTER TABLE {sl7_gallery_image}
ADD CONSTRAINT {sl7_gallery_album}
FOREIGN KEY (aid) REFERENCES {sl7_gallery_album} (aid)
ON DELETE CASCADE
');
// Добавляем права.
if ($role_manager = user_role_load_by_name('manager')) {
$editor_permissions = array(
'sl7_gallery_album create' => TRUE,
'sl7_gallery_album own edit' => TRUE,
'sl7_gallery_album own delete' => TRUE,
'sl7_gallery_image create' => TRUE,
'sl7_gallery_image own edit' => TRUE,
'sl7_gallery_image own delete' => TRUE,
);
user_role_change_permissions($role_manager->rid, $editor_permissions);
}
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('sl7_gallery view'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('sl7_gallery view'));
// Set path breadcrumbs settings.
variable_set('path_breadcrumbs_home_link_title', 'Главная');
// Create fields
$fields = array(
array(
'field_name' => 'sl7_gallery_image',
'type' => 'image',
'cardinality' => 1,
'module' => 'image',
'locked' => TRUE,
'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_gallery_body',
'type' => 'text_long',
'cardinality' => 1,
'translatable' => '1',
'module' => 'text',
'locked' => TRUE,
'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);
}
}
// Create instances for fields
$instances = array(
array(
'field_name' => 'sl7_gallery_image',
'entity_type' => 'sl7_gallery_image',
'bundle' => 'sl7_gallery_image',
'required' => TRUE,
'label' => 'Изображение',
'settings' => array(
'max_filesize' => 1024*1024*5,
'file_extensions' => 'png gif jpg jpeg',
'file_directory' => 'sl7_gallery',
),
'widget' => array(
'type' => 'image_image',
'module' => 'image',
'weight' => 2,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail'
),
'weight' => 2,
),
),
),
array(
'field_name' => 'sl7_gallery_body',
'entity_type' => 'sl7_gallery_album',
'bundle' => 'sl7_gallery_album',
'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,
),
),
array(
'field_name' => 'sl7_gallery_body',
'entity_type' => 'sl7_gallery_image',
'bundle' => 'sl7_gallery_image',
'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_gallery_uninstall() {
db_query('
ALTER TABLE {sl7_gallery_image}
DROP FOREIGN KEY {sl7_gallery_album}
');
// Удаление полей
field_attach_delete_bundle('sl7_gallery_album', 'sl7_gallery_album');
field_attach_delete_bundle('sl7_gallery_image', 'sl7_gallery_image');
db_delete('field_config_instance')->condition('entity_type', 'sl7_gallery_album')->execute();
db_delete('field_config_instance')->condition('entity_type', 'sl7_gallery_image')->execute();
db_delete('field_config')->condition('field_name', 'sl7_gallery_%', 'LIKE')->execute();
// Удаление views
$views = array(
'sl7_gallery_image',
'sl7_gallery_album',
);
foreach ($views as $name) {
if ($view = views_get_view($name)) {
$view->delete();
}
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'sl7_gallery_%', 'LIKE')
->execute();
foreach ($result as $row) {
variable_del($row->name);
}
field_purge_batch(1000);
}