1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install file for menu_token module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_schema().
|
10 |
|
|
*/
|
11 |
|
|
function menu_token_schema() {
|
12 |
|
|
$schema['menu_token'] = array(
|
13 |
|
|
'description' => t('Menu token properties'),
|
14 |
|
|
'fields' => array (
|
15 |
|
|
'mlid' => array (
|
16 |
|
|
'description' => t('The menu link {menu_links}.mlid'),
|
17 |
|
|
'type' => 'int',
|
18 |
|
|
'unsigned' => TRUE,
|
19 |
|
|
'not null' => TRUE,
|
20 |
|
|
),
|
21 |
|
|
'link_path' => array (
|
22 |
|
|
'description' => t('The actual path with tokens'),
|
23 |
|
|
'type' => 'varchar',
|
24 |
|
|
'length' => 255,
|
25 |
|
|
'not null' => TRUE,
|
26 |
|
|
'default' => '',
|
27 |
|
|
),
|
28 |
|
|
),
|
29 |
|
|
|
30 |
|
|
'primary key' => array('mlid'),
|
31 |
|
|
);
|
32 |
|
|
|
33 |
|
|
return $schema;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Implements hook_update_N().
|
38 |
|
|
*/
|
39 |
|
|
function menu_token_update_7000(&$sandbox) {
|
40 |
|
|
if (!db_table_exists('menu_token')) {
|
41 |
|
|
$schema['menu_token'] = array(
|
42 |
|
|
'description' => t('Menu token properties'),
|
43 |
|
|
'fields' => array (
|
44 |
|
|
'mlid' => array (
|
45 |
|
|
'description' => t('The menu link {menu_links}.mlid'),
|
46 |
|
|
'type' => 'int',
|
47 |
|
|
'unsigned' => TRUE,
|
48 |
|
|
'not null' => TRUE,
|
49 |
|
|
),
|
50 |
|
|
'link_path' => array (
|
51 |
|
|
'description' => t('The actual path with tokens'),
|
52 |
|
|
'type' => 'varchar',
|
53 |
|
|
'length' => 255,
|
54 |
|
|
'not null' => TRUE,
|
55 |
|
|
'default' => '',
|
56 |
|
|
),
|
57 |
|
|
),
|
58 |
|
|
|
59 |
|
|
'primary key' => array('mlid'),
|
60 |
|
|
);
|
61 |
|
|
|
62 |
|
|
db_create_table('menu_token', $schema['menu_token']);
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Implements hook_update_N().
|
68 |
|
|
*/
|
69 |
|
|
function menu_token_update_7001(&$sandbox) {
|
70 |
|
|
|
71 |
|
|
// Initializing sandbox variables.
|
72 |
|
|
if (!isset($sandbox['progress'])) {
|
73 |
|
|
// Preparing array of menu items for batch insert.
|
74 |
|
|
foreach (variable_get('menu_token_enabled', array()) as $mlid => $link_path) {
|
75 |
|
|
$sandbox['items'][] = array('mlid' => $mlid, 'link_path' => $link_path);
|
76 |
|
|
}
|
77 |
|
|
$sandbox['progress'] = 0;
|
78 |
|
|
$sandbox['max'] = count($sandbox['items']);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
// Insert current record.
|
82 |
|
|
if (!empty($sandbox['max'])) {
|
83 |
|
|
db_merge('menu_token')
|
84 |
|
|
->key(array('mlid' => $sandbox['items'][$sandbox['progress']]['mlid']))
|
85 |
|
|
->fields(array('link_path' => $sandbox['items'][$sandbox['progress']]['link_path']))
|
86 |
|
|
->execute();
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
$sandbox['progress']++;
|
90 |
|
|
|
91 |
|
|
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
|
92 |
|
|
|
93 |
|
|
// Delete variable in case of all queries were executed
|
94 |
|
|
if ($sandbox['#finished']) {
|
95 |
|
|
variable_del('menu_token_enabled');
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Implements hook_update_N().
|
101 |
|
|
*/
|
102 |
|
|
function menu_token_update_7002(&$sandbox) {
|
103 |
|
|
if (!isset($sandbox['progress'])) {
|
104 |
|
|
$sandbox['progress'] = 0;
|
105 |
|
|
if (db_table_exists('menu_token')) {
|
106 |
|
|
$sandbox['max'] = db_select('menu_token', 'mt')->countQuery()->execute()->fetchField();
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if (!empty($sandbox['max'])) {
|
111 |
|
|
$tokens = db_select('menu_token', 'mt')
|
112 |
|
|
->fields('mt', array('mlid', 'link_path'))
|
113 |
|
|
->orderBy('mlid')
|
114 |
|
|
->range($sandbox['progress'], 10)
|
115 |
|
|
->execute()
|
116 |
|
|
->fetchAllKeyed();
|
117 |
|
|
|
118 |
|
|
if (!empty($tokens)) {
|
119 |
|
|
$links = db_select('menu_links', 'ml')
|
120 |
|
|
->fields('ml', array('mlid', 'options'))
|
121 |
|
|
->condition('mlid', array_keys($tokens))
|
122 |
|
|
->execute()
|
123 |
|
|
->fetchAllKeyed();
|
124 |
|
|
|
125 |
|
|
foreach ($links as $mlid => $options) {
|
126 |
|
|
$options = unserialize($options);
|
127 |
|
|
$options['menu_token_link_path'] = $tokens[$mlid];
|
128 |
|
|
$options['menu_token_link_data'] = array();
|
129 |
|
|
|
130 |
|
|
db_update('menu_links')
|
131 |
|
|
->fields(array('options' => serialize($options)))
|
132 |
|
|
->condition('mlid', $mlid)
|
133 |
|
|
->execute();
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
$sandbox['progress'] += 10;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
|
141 |
|
|
|
142 |
|
|
if ($sandbox['#finished'] >= 1) {
|
143 |
|
|
$sandbox['#finished'] = 1;
|
144 |
|
|
|
145 |
|
|
// Drop the deprecated menu_token table if it exists.
|
146 |
|
|
if (db_table_exists('menu_token')) {
|
147 |
|
|
db_drop_table('menu_token');
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
return t('The Menu Token module has been updated successfully.');
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
/**
|
155 |
|
|
* Drop the deprecated menu_token table if it exists.
|
156 |
|
|
*/
|
157 |
|
|
function menu_token_update_7003() {
|
158 |
|
|
if (db_table_exists('menu_token')) {
|
159 |
|
|
db_drop_table('menu_token');
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
/**
|
164 |
|
|
* Migrate menu items link path, from '<front>' to 'menutoken/[uuid]'.
|
165 |
|
|
*/
|
166 |
|
|
function menu_token_update_7004() {
|
167 |
|
|
$result = db_select('menu_links', 'm')
|
168 |
|
|
->fields('m', array('mlid', 'options'))
|
169 |
|
|
->condition('link_path', '<front>')
|
170 |
|
|
->execute();
|
171 |
|
|
|
172 |
|
|
foreach ($result as $menu_link) {
|
173 |
|
|
$options = unserialize($menu_link->options);
|
174 |
|
|
if (isset($options['menu_token_data'])) {
|
175 |
|
|
db_update('menu_links')
|
176 |
|
|
->fields(array(
|
177 |
|
|
'link_path' => 'menutoken/' . uniqid(),
|
178 |
|
|
'router_path' => 'menutoken/%',
|
179 |
|
|
))
|
180 |
|
|
->condition('mlid', $menu_link->mlid)
|
181 |
|
|
->execute();
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
/**
|
187 |
|
|
* Implements hook_uninstall().
|
188 |
|
|
*/
|
189 |
|
|
function menu_token_uninstall() {
|
190 |
|
|
$result = db_select('variable', 'v')
|
191 |
|
|
->fields('v', array('name'))
|
192 |
|
|
->condition('name', 'menu_token_%', '=')
|
193 |
|
|
->execute();
|
194 |
|
|
|
195 |
|
|
foreach ($result as $row) {
|
196 |
|
|
variable_del($row->name);
|
197 |
|
|
}
|
198 |
|
|
} |