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

Contents of /contributions/modules/weblinks/weblinks.install

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


Revision 1.16 - (show annotations) (download) (as text)
Mon Jul 20 16:52:34 2009 UTC (4 months, 1 week ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.15: +405 -29 lines
File MIME type: text/x-php
Update HEAD to start 7.x
1 <?php
2 // $Id: weblinks.install,v 1.15.2.17.2.13 2009/07/14 23:23:06 nancyw Exp $
3
4 /**
5 * @file
6 */
7
8 /**
9 * Implementation of hook_install().
10 */
11 function weblinks_install() {
12 $result = drupal_install_schema('weblinks');
13
14 if ($result['0']['success']) {
15 drupal_set_message(t('weblinks module installed.'));
16 }
17 else {
18 drupal_set_message(t('weblinks table creation failed. Please "uninstall" the module and retry.'));
19 module_disable('weblinks');
20 }
21
22 // On a new install, mark it as though the latest update has run.
23 variable_set('weblinks_6113', TRUE);
24
25 }
26
27 /**
28 * Implementation of hook_schema().
29 */
30 function weblinks_schema() {
31 $schema['weblinks'] = array(
32 'module' => 'Web Links',
33 'description' => 'Extra node information for the weblinks content type.',
34 'fields' => array(
35 'nid' => array(
36 'description' => 'Node identifier',
37 'type' => 'int',
38 'unsigned' => TRUE,
39 'not null' => TRUE,
40 'default' => 0,
41 ),
42 'vid' => array(
43 'description' => 'Version identifier',
44 'type' => 'int',
45 'unsigned' => TRUE,
46 'not null' => TRUE,
47 'default' => 0,
48 ),
49 'click_count' => array(
50 'description' => 'Click counter',
51 'type' => 'int',
52 'unsigned' => TRUE,
53 'not null' => TRUE,
54 'default' => 0,
55 ),
56 'last_click' => array(
57 'description' => 'Date/time of the last click',
58 'type' => 'datetime',
59 ),
60 'last_status' => array(
61 'description' => 'Status from the last validity check',
62 'type' => 'char',
63 'length' => 4,
64 'default' => '200',
65 ),
66 'last_status_info' => array(
67 'description' => 'When the status changed (either the date or number of cron runs ago)',
68 'type' => 'int',
69 'unsigned' => TRUE,
70 'not null' => FALSE,
71 'default' => NULL,
72 ),
73 'last_checked' => array(
74 'description' => 'Date/time of the last validity check',
75 'type' => 'datetime',
76 ),
77 'urlhash' => array(
78 'description' => 'The hashed value of the URL',
79 'type' => 'char',
80 'length' => 32,
81 'not null' => TRUE,
82 'default' => '',
83 ),
84 'url' => array(
85 'description' => 'The actual URL',
86 'type' => 'text',
87 'not null' => TRUE,
88 ),
89 'reciprocal' => array(
90 'description' => 'A reciprocal URL for matching referers',
91 'type' => 'text',
92 'not null' => FALSE,
93 ),
94 ),
95 'indexes' => array(
96 'last_checked' => array('last_checked'),
97 'urlhash' => array('urlhash'),
98 ),
99 'primary key' => array('nid', 'vid'),
100 );
101 return $schema;
102 }
103
104 /**
105 * Implementation of hook_update_N().
106 * Change url to text; add an index on it.
107 */
108 function weblinks_update_6100() {
109 $ret = array();
110 db_change_field($ret, 'weblinks', 'url', 'url', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
111 return $ret;
112 }
113
114 /**
115 * Implementation of hook_update_N().
116 * Delete variables that are no longer used.
117 */
118 function weblinks_update_6101() {
119 $ret = array();
120
121 variable_del('weblinks_maxdisp_block_recent');
122 variable_del('weblinks_containers');
123 variable_del('weblinks_block_sort');
124
125 return $ret;
126 }
127
128 /**
129 * Implementation of hook_update_N().
130 * Adding fields for link validity checking.
131 */
132 function weblinks_update_6102() {
133 $ret = array();
134
135 if (!db_column_exists('weblinks', 'last_status')) {
136 db_add_field($ret, 'weblinks', 'last_status', array('type' => 'char', 'length' => 4, 'not null' => FALSE, 'default' => '200'));
137 db_add_field($ret, 'weblinks', 'last_checked', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0));
138 }
139
140 return $ret;
141 }
142
143 /**
144 * Implementation of hook_update_N().
145 * Change link description variable.
146 */
147 function weblinks_update_6103() {
148 $ret = array();
149
150 if (variable_get('weblinks_linkdesc', TRUE)) {
151 variable_set('weblinks_linkdesc', 'teaser');
152 $ret[] = array('success' => TRUE, 'query' => "variable_set('weblinks_linkdesc', 'teaser')");
153 }
154 else {
155 variable_set('weblinks_linkdesc', 'none');
156 $ret[] = array('success' => TRUE, 'query' => "variable_set('weblinks_linkdesc', 'none')");
157 }
158
159 return $ret;
160 }
161
162 /**
163 * Implementation of hook_update_N().
164 * Clear the caches because of menu/theme changes..
165 */
166 function weblinks_update_6104() {
167 $ret = array();
168 drupal_flush_all_caches();
169 $ret[] = array('success' => TRUE, 'query' => t('Caches flushed.'));
170 return $ret;
171 }
172
173 /**
174 * Implementation of hook_update_N().
175 * Fix the index structure (http://drupal.org/node/293925).
176 */
177 function weblinks_update_6105() {
178 $ret = array();
179 $table = 'weblinks';
180
181 switch ($GLOBALS['db_type']) {
182 case 'mysql':
183 case 'mysqli':
184 default:
185 $result = db_query("SHOW INDEX FROM {weblinks}");
186 while ($row = db_fetch_array($result)) {
187 if ($row['Key_name'] == 'nid') {
188 db_drop_index($ret, $table, 'nid');
189 db_drop_primary_key($ret, $table);
190 db_add_primary_key($ret, $table, array('nid', 'vid'));
191 }
192 }
193 break;
194
195 case 'pgsql':
196 $result = db_query("SELECT * FROM pg_indexes WHERE tablename = 'weblinks' and indexdef like '%(nid)'");
197 if (db_result($result)) {
198 db_drop_index($ret, $table, 'nid');
199 db_drop_primary_key($ret, $table);
200 db_add_primary_key($ret, $table, array('nid', 'vid'));
201 }
202 break;
203 }
204
205 if (db_column_exists('weblinks', 'tid')) {
206 db_drop_index($ret, $table, 'tid');
207 db_add_index($ret, $table, 'tid', array('tid'));
208 }
209
210 return $ret;
211 }
212
213 /**
214 * Implementation of hook_update_N().
215 * Remove tid, add click_count, last_click.
216 */
217 function weblinks_update_6106() {
218 $ret = array();
219 $table = 'weblinks';
220
221 if (db_column_exists('weblinks', 'tid')) {
222 db_drop_field($ret, $table, 'tid');
223 }
224 if (!db_column_exists('weblinks', 'click_count')) {
225 db_add_field($ret, $table, 'click_count', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
226 db_add_field($ret, $table, 'last_click', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0));
227 }
228
229 return $ret;
230 }
231
232 /**
233 * Implementation of hook_update_N().
234 * Update "Visit" variable.
235 */
236 function weblinks_update_6107() {
237 $ret = array();
238
239 if (!$visit_text = variable_get('weblinks_visit_text', NULL)) {
240 return $ret;
241 }
242
243 $where = strpos($visit_text, '%title');
244 if ($where === FALSE) {
245 if (strpos($visit_text, '[title]') === FALSE) {
246 $visit_text .= ' [title]';
247 }
248 }
249 else {
250 $visit_text = str_replace('%title', '[title]', $visit_text);
251 }
252 variable_set('weblinks_visit_text', $visit_text);
253 $ret[] = array('success' => TRUE, 'query' => "variable_set('weblinks_visit_text', $visit_text)");
254
255 return $ret;
256 }
257
258 /**
259 * Implementation of hook_update_N().
260 * Change module weight.
261 */
262 function weblinks_update_6108() {
263 $ret = array();
264 $ret[] = update_sql("UPDATE {system} SET weight=-2 WHERE type='module' AND name='weblinks'");
265 return $ret;
266 }
267
268 /**
269 * Implementation of hook_update_N().
270 * Move blocks over to the new contrib.
271 */
272 function weblinks_update_6109() {
273 $ret = array();
274 $ret[] = update_sql("UPDATE {blocks} SET module='weblinks_blocks' WHERE module='weblinks'");
275 return $ret;
276 }
277
278 /**
279 * Implementation of hook_update_N().
280 * Index changes.
281 */
282 function weblinks_update_6110() {
283 $ret = array();
284
285 $table = 'weblinks';
286 db_add_field($ret, $table, 'urlhash', array('type' => 'char', 'length' => 32, 'not null' => TRUE, 'default' => ''));
287
288 switch ($GLOBALS['db_type']) {
289 case 'mysql':
290 case 'mysqli':
291 default:
292 $result = db_query("SHOW INDEX FROM {weblinks}");
293 while ($row = db_fetch_array($result)) {
294 if ($row['Key_name'] == 'url') {
295 db_drop_index($ret, $table, 'url');
296 $ret[] = update_sql("UPDATE {weblinks} SET urlhash=MD5(url)");
297 }
298 }
299 break;
300
301 case 'pgsql':
302 $result = db_query("SELECT * FROM pg_indexes WHERE tablename = 'weblinks' and indexdef like '%(nid)'");
303 if (db_result($result)) {
304 db_drop_index($ret, $table, 'url');
305 }
306 }
307
308 db_add_index($ret, $table, 'urlhash', array('urlhash'));
309 db_add_index($ret, $table, 'last_checked', array('last_checked'));
310
311 return $ret;
312 }
313
314 /**
315 * Implementation of hook_update_N().
316 * Settings change.
317 */
318 function weblinks_update_6111() {
319 $ret = array();
320 if (variable_get('weblinks_url', 'url') == 'goto') {
321 variable_set('weblinks_redirect', TRUE);
322 $ret[] = array('success' => TRUE, 'query' => "variable_set('weblinks_redirect', TRUE)");
323 }
324 variable_del('weblinks_url');
325 $ret[] = array('success' => TRUE, 'query' => "variable_del('weblinks_url')");
326 return $ret;
327 }
328
329 /**
330 * Implementation of hook_update_N().
331 * New column for referers.
332 */
333 function weblinks_update_6112() {
334 $ret = array();
335
336 if (!db_column_exists('weblinks', 'reciprocal')) {
337 db_add_field($ret, 'weblinks', 'reciprocal', array('type' => 'text', 'not null' => FALSE));
338 }
339
340 return $ret;
341 }
342
343 /**
344 * Implementation of hook_update_N().
345 * Change to DATETIME type.
346 */
347 function weblinks_update_6113() {
348 $ret = array();
349
350 if (!variable_get('weblinks_6113', FALSE)) {
351 // Convert "last_click" date and time.
352 db_add_field($ret, 'weblinks', 'last_click_new', array('type' => 'datetime'));
353 switch ($GLOBALS['db_type']) {
354 case 'mysql':
355 case 'mysqli':
356 default:
357 $ret[] = $last = update_sql("UPDATE {weblinks} SET last_click_new = FROM_UNIXTIME(last_click) WHERE last_click <> 0");
358 break;
359
360 case 'pgsql':
361 $ret[] = $last = update_sql("UPDATE {weblinks} SET last_click_new = last_click::abstime::timestamp without time zone WHERE last_click <> 0");
362 break;
363 }
364 if ($last['success']) {
365 db_drop_field($ret, 'weblinks', 'last_click');
366 db_change_field($ret, 'weblinks', 'last_click_new', 'last_click', array('type' => 'datetime'));
367 }
368
369 // Convert "last_checked" date and time.
370 db_add_field($ret, 'weblinks', 'last_checked_new', array('type' => 'datetime'));
371 switch ($GLOBALS['db_type']) {
372 case 'mysql':
373 case 'mysqli':
374 default:
375 $ret[] = $last = update_sql("UPDATE {weblinks} SET last_checked_new = FROM_UNIXTIME(last_checked) WHERE last_checked <> 0");
376 break;
377
378 case 'pgsql':
379 $ret[] = $last = update_sql("UPDATE {weblinks} SET last_checked_new = last_checked::abstime::timestamp without time zone WHERE last_checked <> 0");
380 break;
381 }
382 if ($last['success']) {
383 db_drop_index($ret, 'weblinks', 'last_checked');
384 db_drop_field($ret, 'weblinks', 'last_checked');
385 db_change_field($ret, 'weblinks', 'last_checked_new', 'last_checked', array('type' => 'datetime'));
386 db_add_index($ret, 'weblinks', 'last_checked', array('last_checked'));
387 }
388 }
389 variable_set('weblinks_6113', TRUE);
390
391 return $ret;
392 }
393
394 /**
395 * Implementation of hook_update_N().
396 * Use sticky-encoded weighting (preferably by the Weight module).
397 */
398 function weblinks_update_6114() {
399 $ret = array();
400
401 $types = variable_get('weight_node_types', array());
402 if (isset($types['weblinks'])) {
403 drupal_set_message(t('Cannot convert Web Links weights because the Weight module is already set for them.'), 'error');
404 }
405 else {
406 $types['weblinks'] = 'weblinks';
407 variable_set('weight_node_types', $types);
408 $ret[] = array('success' => TRUE, 'query' => "'weblinks' added to 'weight_node_types'.");
409
410 switch ($GLOBALS['db_type']) {
411 case 'mysql':
412 case 'mysqli':
413 default:
414 $ret[] = update_sql("UPDATE {node} n LEFT JOIN {weblinks} l USING(nid, vid) SET n.sticky = 100 - l.weight WHERE n.type='weblinks' AND n.sticky=1");
415 $ret[] = update_sql("UPDATE {node} n LEFT JOIN {weblinks} l USING(nid, vid) SET n.sticky = -100 - l.weight WHERE n.type='weblinks' AND n.sticky=0");
416 break;
417
418 case 'pgsql':
419 $ret[] = update_sql("UPDATE {node} SET sticky = 100 - COALESCE(l.weight,0) FROM {node} n LEFT JOIN {weblinks} l USING(nid, vid) WHERE {node}.nid=n.nid and {node}.vid=n.vid and {node}.type='weblinks' and {node}.sticky=1");
420 $ret[] = update_sql("UPDATE {node} SET sticky = -100 - COALESCE(l.weight,0) FROM {node} n LEFT JOIN {weblinks} l USING(nid, vid) WHERE {node}.nid=n.nid and {node}.vid=n.vid and {node}.type='weblinks' and {node}.sticky=0");
421 break;
422 }
423 }
424
425 return $ret;
426 }
427
428 /**
429 * Implementation of hook_update_N().
430 * New column for last status change info.
431 * Delete weight column.
432 */
433 function weblinks_update_6115() {
434 $ret = array();
435 if (!db_column_exists('weblinks', 'last_status_info')) {
436 db_add_field($ret, 'weblinks', 'last_status_info', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => NULL));
437 }
438 db_drop_field($ret, 'weblinks', 'weight');
439
440 return $ret;
441 }
442
443 /**
444 * Implementation of hook_enable().
445 * Set our module weight.
446 */
447 function weblinks_enable() {
448 db_query("UPDATE {system} SET weight=-2 WHERE type='module' AND name='weblinks'");
449 }
450 /**
451 * Implementation of hook_uninstall().
452 */
453 function weblinks_uninstall() {
454 if (variable_get('weblinks_nav_vocabulary', '')!='') {
455 taxonomy_del_vocabulary(variable_get('weblinks_nav_vocabulary', ''));
456 }
457
458 // Remove all weblinks nodes.
459 $result = db_query("SELECT nid FROM {node} WHERE type='weblinks'");
460 while ($obj = db_fetch_object($result)) {
461 node_delete($obj->nid);
462 }
463
464 // Remove the node type.
465 node_type_delete('weblinks');
466
467 // Get the variables that have a tid at the end.
468 // @@@ I'm not crazy about this, but it works.
469 $result = db_query("SELECT v.name FROM {variable} v WHERE v.name LIKE ('weblinks_filter_%')");
470 while ($name = db_result($result)) {
471 variable_del($name);
472 }
473 variable_del('weblinks_6113');
474 variable_del('weblinks_body_stub');
475 variable_del('weblinks_block_urlnode');
476 variable_del('weblinks_catdesc');
477 variable_del('weblinks_clickthru');
478 variable_del('weblinks_collapsed');
479 variable_del('weblinks_collapsible');
480 variable_del('weblinks_comment_links');
481 variable_del('weblinks_empty_text');
482 variable_del('weblinks_external');
483 variable_del('weblinks_format');
484 variable_del('weblinks_linkdesc');
485 variable_del('weblinks_linkinfo');
486 variable_del('weblinks_linktitle');
487 variable_del('weblinks_maxdepth');
488 variable_del('weblinks_maxfrontdepth');
489 variable_del('weblinks_nav_vocabulary');
490 variable_del('weblinks_nofollow');
491 variable_del('weblinks_pagedesc');
492 variable_del('weblinks_page_sort');
493 variable_del('weblinks_popular_list_type');
494 variable_del('weblinks_redirect');
495 variable_del('weblinks_show_title');
496 variable_del('weblinks_show_url');
497 variable_del('weblinks_simplelinks');
498 variable_del('weblinks_sort');
499 variable_del('weblinks_strip');
500 variable_del('weblinks_subcatdesc');
501 variable_del('weblinks_title_link');
502 variable_del('weblinks_trim');
503 variable_del('weblinks_trim_block');
504 variable_del('weblinks_unclassified_desc');
505 variable_del('weblinks_unclassified_title');
506 variable_del('weblinks_unpublished_desc');
507 variable_del('weblinks_unpublished_title');
508 variable_del('weblinks_url_stub');
509 variable_del('weblinks_urlnode');
510 variable_del('weblinks_user_links');
511 variable_del('weblinks_view_as');
512 variable_del('weblinks_view_position');
513 variable_del('weblinks_visit_text');
514 // Remove our tables.
515 drupal_uninstall_schema('weblinks');
516
517 drupal_set_message(t('weblinks module uninstalled.'));
518 }

  ViewVC Help
Powered by ViewVC 1.1.2