/[drupal]/contributions/modules/hierarchical_select/hierarchical_select.install
ViewVC logotype

Contents of /contributions/modules/hierarchical_select/hierarchical_select.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Sat Jul 18 12:02:01 2009 UTC (4 months, 1 week ago) by wimleers
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +41 -2 lines
File MIME type: text/x-php
#451038 by artedemingo and myself: OG Vocabulary compatibility
1 <?php
2 // $Id: hierarchical_select.install,v 1.11 2008/08/07 22:46:50 wimleers Exp $
3
4 /**
5 * @file
6 * Install file for the Hierarchical Select module.
7 */
8
9
10 /**
11 * Implementation of hook_install().
12 */
13 function hierarchical_select_install() {
14 // Ensure the Hierarchical Select module runs after the Taxonomy and Content
15 // Taxonomy modules! This should not be necessary to do, but apparently some
16 // idiot module developer is changing the weight of the Taxonomy module...
17 $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
18 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'content_taxonomy'")));
19 // Also ensure the Hierarchical Select module runs after the i18ntaxonomy
20 // module.
21 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'i18ntaxonomy'")));
22 // Also ensure the Hierarchical Select module runs after the og_vocab module.
23 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'og_vocab'")));
24 // If none of these modules was already enabled, the weight will still be
25 // incorrect. Therefore, let's make the minimum weight of Hierarchical
26 // Select 15.
27 $weight = max($weight, 15);
28
29 // Set the weight one higher than the highest weight we've encountered, so
30 // that Hierarchical Select will run after it.
31 $weight++;
32
33 db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'hierarchical_select');
34 }
35
36
37 //----------------------------------------------------------------------------
38 // Schema updates.
39
40 // Update module weight.
41 function hierarchical_select_update_1() {
42 $ret = array();
43
44 // Ensure the Hierarchical Select module runs after the Taxonomy and Content
45 // Taxonomy modules! This should not be necessary to do, but apparently some
46 // idiot module developer is changing the weight of the Taxonomy module...
47 $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
48 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'content_taxonomy'")));
49 $weight++;
50 $ret[] = update_sql("UPDATE {system} SET weight = $weight WHERE name = 'hierarchical_select'");
51
52 return $ret;
53 }
54
55 // Update module weight again, this time for i18ntaxonomy compatibility.
56 function hierarchical_select_update_2() {
57 $ret = array();
58
59 $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
60 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'content_taxonomy'")));
61 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'i18ntaxonomy'")));
62 $weight++;
63 $ret[] = update_sql("UPDATE {system} SET weight = $weight WHERE name = 'hierarchical_select'");
64
65 return $ret;
66 }
67
68 // Helper function for update 3.
69 function hierarchical_select_update_3_taxonomy_hierarchical_select_get_depth($vid) {
70 $tree = taxonomy_get_tree($vid);
71 foreach ($tree as $term) {
72 if ($term->depth > $depth) {
73 $depth = $term->depth;
74 }
75 }
76 return $depth;
77 }
78
79 // Convert the Hierarchical Select settings for each vocabulary to the
80 // standardized format.
81 function hierarchical_select_update_3() {
82 $ret = array();
83
84 $vocabularies = taxonomy_get_vocabularies();
85 foreach ($vocabularies as $vid => $vocabulary) {
86 $config = array();
87
88 // Generate the config_id.
89 $config['config_id'] = "taxonomy-$vid";
90
91 // save_lineage and enforce_deepest settings.
92 foreach (array('save_lineage', 'enforce_deepest') as $setting) {
93 $var = "hierarchical_select_{$setting}_{$vid}";
94 $config[$setting] = (int) variable_get($var, 0);
95 variable_del($var);
96 }
97
98 // Level labels.
99 $var = "hierarchical_select_level_labels_status_{$vid}";
100 $config['level_labels']['status'] = variable_get($var, 0);
101 variable_del($var);
102 $config['level_labels']['labels'] = array();
103 for ($depth = 0; $depth < hierarchical_select_update_3_taxonomy_hierarchical_select_get_depth($vid); $depth++) {
104 $var = "hierarchical_select_level_{$depth}_{$vid}";
105 $config['level_labels']['labels'][$depth] = variable_get($var, '');
106 variable_del($var);
107 }
108
109 // Dropbox settings.
110 $var = "hierarchical_select_multiple_{$vid}";
111 $config['dropbox']['status'] = variable_get($var, 0);
112 variable_del($var);
113 foreach (array('title', 'limit') as $setting) {
114 $var = "hierarchical_select_dropbox_{$setting}_{$vid}";
115 $config['dropbox'][$setting] = variable_get($var, 0);
116 variable_del($var);
117 }
118 $config['dropbox']['reset_hs'] = 1;
119 variable_set('hierarchical_select_config_'. $config['config_id'], $config);
120
121 // Rename the variable that indicates if a vocabulary is using
122 // Hierarchical Select or not.
123 $var = "hierarchical_select_status_$vid";
124 variable_set("taxonomy_hierarchical_select_$vid", variable_get($var, 0));
125 variable_del($var);
126
127 drupal_set_message('Migrated Hierarchical Select settings for vocabulary '. $vid .'.');
128 }
129
130 return $ret;
131 }
132
133 // Shorter prefix for storing the config variables.
134 function hierarchical_select_update_4() {
135 $ret = array();
136
137 // Single query that could do the same, if it weren't for "Currently, you
138 // cannot update a table and select from the same table in a subquery."
139 // source: http://dev.mysql.com/doc/refman/5.0/en/update.html
140 // UPDATE `variable` SET name = CONCAT('hs_config_', SUBSTRING(name, 28)) WHERE name IN (SELECT name FROM `variable` WHERE name LIKE 'hierarchical_select_config_%')
141
142 $result = db_query("SELECT SUBSTRING(name, 28) AS config_id FROM {variable} WHERE name LIKE 'hierarchical_select_config_%'");
143 while ($row = db_fetch_object($result)) {
144 $config_id = $row->config_id;
145 $value = variable_get("hierarchical_select_config_$config_id", serialize(array()));
146 variable_set("hs_config_$config_id", $value);
147 variable_del("hierarchical_select_config_$config_id");
148 }
149
150 return $ret;
151 }
152
153 // Increase the length of the "name" field in the "variable" table to 128. The
154 // Hierarchical Select module needs this for some of its variables. This does
155 // NOT break updates to Drupal 6!
156 // See http://drupal.org/node/259962.
157 function hierarchical_select_update_5() {
158 $ret = array();
159
160 $ret[] = update_sql("ALTER TABLE {variable} MODIFY name varchar(128) NOT NULL default ''");
161
162 return $ret;
163 }
164
165 // Several modules were renamed for consistency. Only one of these needs a
166 // change in its config variables.
167 function hierarchical_select_update_6() {
168 $ret = array();
169
170 // hs_views_taxonomy -> hs_taxonomy_views
171 $result = db_query("SELECT SUBSTRING(name, 26) AS config_id FROM {variable} WHERE name LIKE 'hs_config_views-taxonomy_%'");
172 while ($row = db_fetch_object($result)) {
173 $config_id = $row->config_id;
174 $value = variable_get("hs_config_views-taxonomy_$config_id", serialize(array()));
175 variable_set("hs_config_taxonomy-views_$config_id", $value);
176 variable_del("hs_config_views-taxonomy_$config_id");
177 }
178
179 return $ret;
180 }
181
182 // Rename 'node_count' as 'entity_count'.
183 function hierarchical_select_update_7() {
184 $ret = array();
185
186 $result = db_query("SELECT name AS config_id, value AS config FROM {variable} WHERE name LIKE 'hs_config_%'");
187 while ($row = db_fetch_object($result)) {
188 $config_id = $row->config_id;
189 $config = unserialize($row->config);
190 if (isset($config['node_count'])) {
191 $config['entity_count'] = $config['node_count'];
192 unset($config['node_count']);
193 db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", serialize($config), $config_id);
194 }
195 }
196
197 return $ret;
198 }
199
200 // Update module weight again, this time for og_vocab compatibility.
201 function hierarchical_select_update_8() {
202 $ret = array();
203
204 // Ensure the Hierarchical Select module runs after the Taxonomy and Content
205 // Taxonomy modules! This should not be necessary to do, but apparently some
206 // idiot module developer is changing the weight of the Taxonomy module...
207 $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
208 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'content_taxonomy'")));
209 // Also ensure the Hierarchical Select module runs after the i18ntaxonomy
210 // module.
211 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'i18ntaxonomy'")));
212 // Also ensure the Hierarchical Select module runs after the og_vocab module.
213 $weight = max($weight, db_result(db_query("SELECT weight FROM {system} WHERE name = 'og_vocab'")));
214 // If none of these modules was already enabled, the weight will still be
215 // incorrect. Therefore, let's make the minimum weight of Hierarchical
216 // Select 15.
217 $weight = max($weight, 15);
218
219 // Set the weight one higher than the highest weight we've encountered, so
220 // that Hierarchical Select will run after it.
221 $weight++;
222
223 $ret[] = update_sql("UPDATE {system} SET weight = $weight WHERE name = 'hierarchical_select'");
224
225 return $ret;
226 }

  ViewVC Help
Powered by ViewVC 1.1.2