-
Notifications
You must be signed in to change notification settings - Fork 9
/
ding_library.install
331 lines (303 loc) · 8.13 KB
/
ding_library.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
<?php
/**
* @file
* Handles installation and un-installation for ding libraries.
*/
/**
* Implements hook_install().
*/
function ding_library_install() {
// Disable default OG member rules.
db_update('rules_config')
->fields(array('active' => 0))
->condition(db_or()
->condition('name', 'rules_og_member_active')
->condition('name', 'rules_og_member_pending')
->condition('name', 'rules_og_group_content_notification'))
->execute();
// Install node queue for libraries.
ding_library_install_nodequeue();
}
/**
* Implements hook_uninstall().
*/
function ding_library_uninstall() {
$queue = nodequeue_load_queue_by_name('ding_library_listing');
nodequeue_delete($queue->qid);
}
/**
* Helper function to create node queue used in groups listing pages.
*/
function ding_library_install_nodequeue() {
$nodequeue = new stdClass();
$nodequeue->name = 'ding_library_listing';
$nodequeue->title = 'Library listing';
$nodequeue->subqueue_title = '';
$nodequeue->owner = 'nodequeue';
$nodequeue->api_version = 2;
$nodequeue->link = 'Add to listing';
$nodequeue->link_remove = 'Remove from listing';
$nodequeue->show_in_ui = TRUE;
$nodequeue->show_in_tab = TRUE;
$nodequeue->show_in_links = FALSE;
$nodequeue->i18n = 0;
$nodequeue->roles = array();
$nodequeue->size = 0;
$nodequeue->reverse = 0;
$nodequeue->new = TRUE;
$nodequeue->types = array(
0 => 'ding_library',
);
$nodequeue->subqueues = array();
$nodequeue->submit = 'Submit';
$nodequeue->reverse = 0;
$nodequeue->reference = 0;
$nodequeue->add_subqueue = array(
$nodequeue->title,
);
nodequeue_save($nodequeue);
}
/**
* Implements hook_enable().
*/
function ding_library_enable() {
$path = array(
'source' => 'libraries',
'language' => 'und',
);
// Create Danish alias for libraries if needed.
if (!path_load($path)) {
$path['alias'] = 'biblioteker';
path_save($path);
}
}
/**
* Update blocks.
*/
function ding_library_update_7001() {
$default_theme = variable_get('theme_default', 'bartik');
// Delete menu_block menu, not needed anymore.
db_delete('block')
->condition('module', 'menu_block')
->condition('delta', 'ding_content-main-lvl1')
->condition('theme', $default_theme)
->execute();
// Delete any left over library_menus.
db_delete('block')
->condition('module', 'ding_library')
->condition('delta', 'library_menu')
->condition('theme', $default_theme)
->execute();
// Add the new ding_menu.
db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache', 'title'))->values(array(
'module' => 'ding_library',
'delta' => 'ding_menu',
'theme' => $default_theme,
'status' => 1,
'weight' => 1,
'region' => 'header',
'pages' => '',
'cache' => -1,
'title' => '<none>',
)
)->execute();
return t('Updated menu block.');
}
/**
* Disable default OG member rules.
*/
function ding_library_update_7002() {
db_update('rules_config')
->fields(array('active' => 0))
->condition(db_or()
->condition('name', 'rules_og_member_active')
->condition('name', 'rules_og_member_pending')
->condition('name', 'rules_og_group_content_notification'))
->execute();
}
/**
* Set OG user on library nodes to user 1.
*/
function ding_library_update_7003() {
$query = db_select('og', 'og');
$query->join('node', 'n', 'n.nid = og.etid');
$query->fields('og', array('etid'));
$query->addField('n', 'uid');
$rows = $query->execute();
foreach ($rows as $row) {
db_insert('og_membership')
->fields(array(
'type' => 'og_membership_type_default',
'etid' => $row->uid,
'entity_type' => 'user',
'gid' => $row->etid,
'state' => 1,
'created' => time(),
'group_type' => 'node',
'field_name' => 'og_user_node',
'language' => 'und',
))
->execute();
}
}
/**
* Updated OG permission roles.
*/
function ding_library_update_7004() {
$roles = array(
array(
'rid' => 1,
'permission' => 'subscribe',
'module' => 'og_ui',
),
array(
'rid' => 2,
'permission' => 'unsubscribe',
'module' => 'og_ui',
),
array(
'rid' => 3,
'permission' => 'add user',
'module' => 'og_ui',
),
array(
'rid' => 3,
'permission' => 'approve and deny subscription',
'module' => 'og_ui',
),
array(
'rid' => 3,
'permission' => 'manage members',
'module' => 'og_ui',
),
array(
'rid' => 3,
'permission' => 'manage permissions',
'module' => 'og_ui',
),
array(
'rid' => 3,
'permission' => 'manage roles',
'module' => 'og_ui',
),
);
foreach ($roles as $role) {
db_insert('og_role_permission')
->fields($role)
->execute();
}
}
/**
* Update group roles with type and bundle.
*/
function ding_library_update_7005() {
db_update('og_role')
->fields(array(
'group_type' => 'node',
'group_bundle' => 'ding_library',
))
->execute();
}
/**
* Ensure that the OG audience field is add to users.
*/
function ding_library_update_7006() {
// Get basic OG audience field information.
$og_field = og_fields_info(OG_AUDIENCE_FIELD);
$og_field['field']['settings']['target_type'] = 'node';
$og_field['instance']['label'] = t('Group membership');
// If the user entity type has multiple bundles, make sure to attach a field
// instance to all of them.
$entity_info = entity_get_info('user');
foreach (array_keys($entity_info['bundles']) as $user_bundle) {
og_create_field('og_user_node', 'user', $user_bundle, $og_field);
}
}
/**
* Add groups node queue if it do not exists.
*/
function ding_library_update_7007() {
$qids = nodequeue_get_qids('ding_library');
if (empty($qids)) {
ding_library_install_nodequeue();
}
}
/**
* Remove all old library links from the menus (news, event and about).
*/
function ding_library_update_7008() {
db_delete('menu_links')
->condition('menu_name', 'main-menu')
->condition('link_path', 'bibliotek%', 'LIKE')
->execute();
}
/**
* Move all other library custom links into OG menu.
*/
function ding_library_update_7009() {
// Find all library nid's.
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'ding_library')
->execute()
->fetchAllKeyed();
foreach (array_keys($nids) as $nid) {
// Get library mlid.
$mlid = db_select('menu_links', 'ml')
->fields('ml', array('mlid'))
->condition('link_path', 'node/' . $nid)
->execute()
->fetchField();
// Find every menu link with $mlid as plid.
$links = db_select('menu_links', 'ml')
->fields('ml', array('mlid', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'))
->condition('plid', $mlid)
->execute()
->fetchAllAssoc('mlid');
// Get OG menu mlid to get parent mlid.
foreach ($links as $link => $data) {
// Move menu link in to OG menu and remove the parents (library/name/)
db_update('menu_links')
->fields(array(
'menu_name' => 'menu-og-' . $nid,
'p1' => $data->p3,
'p2' => $data->p4,
'p3' => $data->p5,
'p4' => $data->p6,
'p5' => $data->p7,
'p6' => $data->p8,
'p7' => $data->p9,
'p8' => 0,
'p9' => 0,
))
->condition('mlid', $link)
->execute();
}
// Delete old library link.
db_delete('menu_links')
->condition('menu_name', 'main-menu')
->condition('link_path', 'node/' . $nid)
->execute();
}
}
/**
* Install menu position rule.
*/
function ding_library_update_7010() {
ding_library_install_menu_position();
}
/**
* Remove old library opening hours field.
*/
function ding_library_update_7011() {
field_delete_field('field_ding_library_opening_hours');
field_purge_batch(1000);
}
/**
* Remove old library path auto patterns.
*/
function ding_library_update_7012() {
variable_del('pathauto_node_ding_library_da_pattern');
variable_del('pathauto_node_ding_library_en_pattern');
variable_del('pathauto_node_ding_library_und_pattern');
}