1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Install, update and uninstall functions for the menu_attributes module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_install().
|
10
|
*/
|
11
|
function menu_attributes_install() {
|
12
|
db_update('system')
|
13
|
->fields(array(
|
14
|
'weight' => 10,
|
15
|
))
|
16
|
->condition('type', 'module')
|
17
|
->condition('name', 'menu_attributes')
|
18
|
->execute();
|
19
|
}
|
20
|
|
21
|
/**
|
22
|
* Implements hook_uninstall().
|
23
|
*/
|
24
|
function menu_attributes_uninstall() {
|
25
|
drupal_load('module', 'menu_attributes');
|
26
|
$attributes = menu_attributes_menu_attribute_info();
|
27
|
foreach (array_keys($attributes) as $attribute) {
|
28
|
variable_del("menu_attributes_{$attribute}_enable");
|
29
|
variable_del("menu_attributes_{$attribute}_default");
|
30
|
}
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Update the module weight.
|
35
|
*/
|
36
|
function menu_attributes_update_1() {
|
37
|
db_update('system')
|
38
|
->fields(array(
|
39
|
'weight' => 10,
|
40
|
))
|
41
|
->condition('type', 'module')
|
42
|
->condition('name', 'menu_attributes')
|
43
|
->execute();
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Fix any menu links that had the class attribute saved as an string.
|
48
|
*/
|
49
|
function menu_attributes_update_7000(&$sandbox) {
|
50
|
if (!isset($sandbox['progress'])) {
|
51
|
$sandbox['progress'] = 0;
|
52
|
$sandbox['current_mlid'] = 0;
|
53
|
// Only count links that possibly have a key class with a string value in
|
54
|
// its serialized options array.
|
55
|
$sandbox['max'] = db_query("SELECT COUNT(DISTINCT mlid) FROM {menu_links} WHERE options LIKE '%s:5:\"class\";s:%'")->fetchField();
|
56
|
}
|
57
|
|
58
|
// Process twenty links at a time.
|
59
|
$limit = 20;
|
60
|
|
61
|
$links = db_query_range("SELECT mlid, options FROM {menu_links} WHERE mlid > :mlid AND options LIKE '%s:5:\"class\";s:%' ORDER BY mlid", 0, $limit, array(':mlid' => $sandbox['current_mlid']))->fetchAllKeyed();
|
62
|
foreach ($links as $mlid => $options) {
|
63
|
$options = unserialize($options);
|
64
|
|
65
|
if (isset($options['attributes']['class']) && is_string($options['attributes']['class'])) {
|
66
|
// Convert classes to an array.
|
67
|
$options['attributes']['class'] = explode(' ', $options['attributes']['class']);
|
68
|
db_update('menu_links')
|
69
|
->fields(array(
|
70
|
'options' => serialize($options),
|
71
|
))
|
72
|
->condition('mlid', $mlid)
|
73
|
->execute();
|
74
|
}
|
75
|
|
76
|
$sandbox['progress']++;
|
77
|
$sandbox['current_mlid'] = $mlid;
|
78
|
}
|
79
|
|
80
|
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
|
81
|
|
82
|
// To display a message to the user when the update is completed, return it.
|
83
|
// If you do not want to display a completion message, simply return nothing.
|
84
|
return t('All menu links with non-array value for class attribute have been fixed.');
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Grant the 'administer menu attributes' permission to roles that currently
|
89
|
* have the 'administer menu' permission.
|
90
|
*/
|
91
|
function menu_attributes_update_7001() {
|
92
|
$roles = user_roles(FALSE, 'administer menu');
|
93
|
foreach ($roles as $rid => $role) {
|
94
|
user_role_grant_permissions($rid, array('administer menu attributes'));
|
95
|
}
|
96
|
|
97
|
return t("Every role with the 'administer menu' permission has also received the 'administer menu attributes' permission.");
|
98
|
}
|