-
Notifications
You must be signed in to change notification settings - Fork 3
/
taxonomy_menu.install
181 lines (164 loc) · 5.48 KB
/
taxonomy_menu.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
<?php
/**
* @file
* Install and uninstall all required databases. Also do incremental database updates.
*/
/**
* Implements hook_schema().
*/
function taxonomy_menu_schema() {
$schema['taxonomy_menu'] = array(
'description' => 'Links a taxonomy term to a menu item.',
'fields' => array(
'mlid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Menu link ID.',
),
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Term ID that is linked to the menu.',
),
'vocabulary' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The vocabulary machine name to which each term is assigned.',
),
),
'primary key' => array('mlid', 'tid'),
'indexes' => array(
'vocabulary' => array('vocabulary'),
),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function taxonomy_menu_uninstall() {
// Remove menu items.
db_delete('menu_links')->condition('module', 'taxonomy_menu', '=')->execute();
// Rebuild the menus.
state_set('menu_rebuild_needed', TRUE);
// Gets array of more specific variables set by Taxonomy Menu module.
$variable_prefixes = array(
'taxonomy_menu_vocab_menu_',
'taxonomy_menu_vocab_parent_',
'taxonomy_menu_display_num_',
'taxonomy_menu_hide_empty_terms_',
'taxonomy_menu_expanded_',
'taxonomy_menu_rebuild_',
'taxonomy_menu_sync_',
'taxonomy_menu_flat_',
'taxonomy_menu_max_depth_',
'taxonomy_menu_term_item_description_',
);
// Delete variables.
$query = db_select('variable', 'v')
->fields('v', array('name', 'value'))
->condition('name', '%' . db_like('taxonomy_menu') . '%', 'LIKE')
->execute();
$variables = $query->fetchAll();
foreach ($variables as $variable) {
foreach ($variable_prefixes as $prefix) {
if (strpos($variable->name, $prefix) !== FALSE) {
variable_del($variable->name);
}
}
}
}
/**
* Implements hook_update_dependencies().
*/
function taxonomy_menu_update_dependencies() {
// Do not allow taxonomy module to drop vid column until after we have
// updated our table in taxonomy_menu_update_7000().
$dependencies['taxonomy'][1001] = array(
'taxonomy_menu' => 1000,
);
return $dependencies;
}
/**
* Implements hook_update_last_removed().
*/
function taxonomy_menu_update_last_removed() {
// The last Drupal 7 update that needs to run before upgrading to Backdrop.
return 7000;
}
/**
* Convert vocabulary ids into vocabulary machine names.
*/
function taxonomy_menu_update_1000() {
// Remove the old vid index.
db_drop_index('taxonomy_menu', 'vid');
// Update the taxonomy_menu table 'vid' column should be varchar 255 'vocabulary'.
$spec = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The vocabulary machine name to which each term is assigned.',
);
db_change_field('taxonomy_menu', 'vid', 'vocabulary', $spec);
// Add the new vocabulary index.
db_add_index('taxonomy_menu', 'vocabulary', array('vocabulary'));
// Remove unsupported variables.
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_path_%'");
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_voc_item_%'");
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_voc_name_%'");
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_voc_item_description_%'");
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_end_all_%'");
db_query("DELETE from {variable} WHERE name LIKE 'taxonomy_menu_display_descendants_%'");
// Gets array of specific variables set by Taxonomy Menu module.
$variable_prefixes = array(
'taxonomy_menu_vocab_menu_',
'taxonomy_menu_vocab_parent_',
'taxonomy_menu_display_num_',
'taxonomy_menu_hide_empty_terms_',
'taxonomy_menu_expanded_',
'taxonomy_menu_rebuild_',
'taxonomy_menu_sync_',
'taxonomy_menu_flat_',
'taxonomy_menu_max_depth_',
'taxonomy_menu_term_item_description_',
);
$result = db_query("SELECT * FROM {taxonomy_vocabulary}");
foreach ($result as $row) {
$vocabulary_data = (array) $row;
$vid = $vocabulary_data['vid'];
$machine = $vocabulary_data['machine_name'];
$label = $vocabulary_data['name'];
// Update vids to vocabularies in taxonomy_menu table.
db_query("UPDATE {taxonomy_menu} SET vocabulary = :vocab WHERE vocabulary = :vid",
array(':vocab' => $machine, ':vid' => $vid));
// Switch from variables to config.
$config = config('taxonomy_menu.vocabulary.' . $machine);
$config->set('name', $machine);
$config->set('label', $label);
$empty = TRUE;
foreach ($variable_prefixes as $prefix) {
$value = update_variable_get($prefix . $machine, NULL);
if ($value !== NULL) {
// Remove the module name.
$key = str_replace('taxonomy_menu_', '', $prefix);
// Remove the vocabulary name.
$key = str_replace('_' . $machine, '', $key);
// Set the config value.
$config->set($key, $value);
// Indicate that we are going to save this config file.
$empty = FALSE;
}
}
if (!$empty) {
$config->save();
}
}
return t('Taxonomy menu database table updated, and variables converted to config.');
}