forked from backdrop-contrib/og
-
Notifications
You must be signed in to change notification settings - Fork 0
/
og.install
464 lines (444 loc) · 13.4 KB
/
og.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php
/**
* @file
* Install, update, and uninstall functions for the Organic groups module.
*/
/**
* Implements hook_install().
*/
function og_install() {
// Add "User request" to the default group membership type.
$field_name = OG_MEMBERSHIP_REQUEST_FIELD;
if (!field_info_field($field_name)) {
$field = array(
'field_name' => $field_name,
'type' => 'text_long',
'entity_types' => array('og_membership'),
'cardinality' => 1,
// Although we would prefer to not allow deleting this field, we can not
// lock it, as it will not allow adding it to other bundles.
'locked' => FALSE,
);
$field = field_create_field($field);
}
if (!field_info_instance('og_membership', $field_name, OG_MEMBERSHIP_TYPE_DEFAULT)) {
$instance = array(
'field_name' => $field_name,
'bundle' => OG_MEMBERSHIP_TYPE_DEFAULT,
'entity_type' => 'og_membership',
'label' => t('Request message'),
'description' => t('This is the text a user may send to the group administrators.'),
'required' => FALSE,
);
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall().
*/
function og_uninstall() {
// Delete OG-core fields.
$og_fields = array(
'group_group',
'og_description',
'og_membership_request',
);
foreach (field_info_instances() as $bundles) {
foreach ($bundles as $instances) {
foreach ($instances as $instance) {
if (in_array($instance['field_name'], $og_fields)) {
field_delete_instance($instance);
}
else {
$field = field_info_field($instance['field_name']);
if ($field['type'] == 'entityreference' && ($field['settings']['handler'] == 'og' || strpos($field['settings']['handler'], 'og_') === 0)) {
// Last instance will take care also of deleting the field itself.
field_delete_instance($instance);
}
}
}
}
}
}
/**
* Implements hook_schema().
*/
function og_schema() {
$schema = array();
$schema['og_role_permission'] = array(
'description' => 'Stores the permissions assigned to user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Foreign Key: {role}.rid.',
),
'permission' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'A single permission granted to the role identified by rid.',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The module declaring the permission.",
),
),
'primary key' => array('rid', 'permission'),
'indexes' => array(
'permission' => array('permission'),
),
'foreign keys' => array(
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
),
);
$schema['og_role'] = array(
'description' => 'Stores user roles per group.',
'fields' => array(
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique role ID.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
),
'group_bundle' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's bundle name.",
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Unique role name per group.',
),
),
'primary key' => array('rid'),
'indexes' => array(
'lookup' => array('group_type', 'group_bundle', 'gid'),
),
);
$schema['og_users_roles'] = array(
'description' => 'Maps users to roles.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {users}.uid for user.',
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: {og_role}.rid for role.',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The group's entity type.",
),
),
'primary key' => array('uid', 'rid', 'gid'),
'indexes' => array(
'rid' => array('rid'),
),
'foreign keys' => array(
'user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'og_role' => array(
'table' => 'og_role',
'columns' => array('rid' => 'rid'),
),
),
);
$schema['og_membership_type'] = array(
'description' => 'The group membership type.',
'fields' => array(
// Although the "name" should be enough as the primary key, the numeric ID
// is required for the internal use of entity API.
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Numeric group membership type ID.',
),
'name' => array(
'description' => 'The unified identifier for a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'Description for this group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// This is equivilent to ENTITY_CUSTOM.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'language' => array(
'description' => 'The {languages}.language of this membership type.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['og_membership'] = array(
'description' => 'The group membership table.',
'fields' => array(
'id' => array(
'description' => "The group membership's unique ID.",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Reference to a group membership type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'etid' => array(
'description' => "The entity ID.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => "The entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'gid' => array(
'description' => "The group's unique ID.",
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
),
'group_type' => array(
'description' => "The group's entity type (e.g. node, comment, etc').",
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'field_name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
),
'language' => array(
'description' => 'The {languages}.language of this membership.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('id'),
'indexes' => array(
// Entity index; When searching for an entity, we use both the id and type.
'entity' => array('etid', 'entity_type'),
'group' => array('gid', 'group_type'),
'group_type' => array('group_type'),
),
'foreign keys' => array(
'og_membership_type' => array(
'table' => 'og_membership_type',
'columns' => array('name' => 'name'),
),
'group' => array(
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
// Cache bins for Entity-cache module.
$cache_schema = backdrop_get_schema_unprocessed('system', 'cache');
$types = array(
'og_membership_type',
'og_membership',
);
foreach ($types as $type) {
$schema["cache_entity_$type"] = $cache_schema;
$schema["cache_entity_$type"]['description'] = "Cache table used to store $type entity records.";
}
return $schema;
}
/**
* Implements hook_field_schema().
*/
function og_field_schema($field) {
$columns = array(
'gid' => array(
'description' => 'The group unique ID.',
'type' => 'float',
'unsigned' => TRUE,
'not null' => FALSE,
),
// This columns should be deprecated and removed, as the group membership
// entity takes care of it. However, there is currently no way to remove
// them.
'state' => array(
'description' => 'The state of the group content.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the group content was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
);
return array(
'columns' => $columns,
'indexes' => array(
'gid' => array('gid'),
),
'foreign keys' => array(
'og' => array(
'table' => 'og',
'columns' => array('gid' => 'gid'),
),
),
);
}
/**
* Implements hook_update_last_removed().
*/
function og_update_last_removed() {
return 7205;
}
/**
* Implements hook_update_N().
*/
function og_update_1000() {
$config = config('og.settings');
$config->set('og_7000_add_field', update_variable_get('og_7000_add_field', 'FALSE'));
$config->set('og_7200_ogur_roles', update_variable_get('og_7200_ogur_roles', 'FALSE'));
$config->set('og_node_access_strict', update_variable_get('og_node_access_strict', 'TRUE'));
$config->set('og_use_queue', update_variable_get('og_use_queue', 'FALSE'));
$config->set('og_orphans_delete', update_variable_get('og_orphans_delete', 'FALSE'));
$config->set('og_group_manager_full_access', update_variable_get('og_group_manager_full_access', 'TRUE'));
$config->set('og_maintain_overridden_roles', update_variable_get('og_maintain_overridden_roles', 'TRUE'));
$config->set('og_features_ignore_og_fields', update_variable_get('og_features_ignore_og_fields', 'FALSE'));
$config->save();
update_variable_del('og_7000_add_field');
update_variable_del('og_7200_ogur_roles');
update_variable_del('og_node_access_strict');
update_variable_del('og_use_queue');
update_variable_del('og_orphans_delete');
update_variable_del('og_group_manager_full_access');
update_variable_del('og_maintain_overridden_roles');
update_variable_del('og_features_ignore_og_fields');
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_group_manager_default_rids_%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, array()));
update_variable_del($name);
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_is_group_default_access__%__%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, 'TRUE'));
update_variable_del($name);
}
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'og_is_group__%__%', 'LIKE')
->execute()
->fetchCol();
foreach($result as $name) {
$config->set($name, update_variable_get($name, 'FALSE'));
update_variable_del($name);
}
$config->save();
if (db_index_exists('og_role', 'lookup')) {
db_drop_index('og_role', 'lookup');
}
db_add_index('og_role', 'lookup', array('group_type', 'group_bundle', 'gid'));
}