| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id: links.install,v 1.7 2007/12/14 18:52:15 syscrusher Exp $
|
| 4 |
|
| 5 |
/**
|
| 6 |
* This function reads the entire links table. For each row, it takes
|
| 7 |
* the full URL as stored, normalizes it using the current version of
|
| 8 |
* links_normalize_url(), and recalculates the MD5 sum for
|
| 9 |
* the row. If the new sum or the newly-normalized URL differs from
|
| 10 |
* the old, returns SQL to change the record accordingly.
|
| 11 |
*
|
| 12 |
* The return value is an array generated by update_sql().
|
| 13 |
*/
|
| 14 |
function _links_recalc_all_url_md5() {
|
| 15 |
$updates = array();
|
| 16 |
$sql = "SELECT lid, url, url_md5 FROM {links}";
|
| 17 |
$result = db_query($sql);
|
| 18 |
if (db_error()) {
|
| 19 |
watchdog("error","links failed on main query in _links_recalc_all_url_md5()");
|
| 20 |
return -1;
|
| 21 |
}
|
| 22 |
while (is_array($row=db_fetch_array($result))) {
|
| 23 |
$parsed = links_parse_url($row["url"]);
|
| 24 |
$md5_new = $parsed['md5'];
|
| 25 |
$url_new = $parsed['normalized'];
|
| 26 |
if ($md5_new != $row["url_md5"] || $url_new != $row["url"]) {
|
| 27 |
$sql = "UPDATE {links} SET url='".db_escape_string($url_new)."', url_md5='".db_escape_string($md5_new)."' WHERE lid=".$row['lid'];
|
| 28 |
$updates[] = update_sql($sql);
|
| 29 |
}
|
| 30 |
}
|
| 31 |
return $updates;
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Update the tables to UTF-8
|
| 36 |
*/
|
| 37 |
function links_update_6101() {
|
| 38 |
return _system_update_utf8(array('links', 'links_node', 'links_monitor'));
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Recalc all the MD5 sums because links_normalize_url() changed
|
| 43 |
*/
|
| 44 |
function links_update_6102() {
|
| 45 |
return _links_recalc_all_url_md5();
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Install the initial schema.
|
| 50 |
*/
|
| 51 |
function links_install() {
|
| 52 |
drupal_install_schema('links');
|
| 53 |
}
|
| 54 |
|
| 55 |
/**
|
| 56 |
* Uninstall the module
|
| 57 |
*/
|
| 58 |
function links_uninstall() {
|
| 59 |
drupal_uninstall_schema('links');
|
| 60 |
}
|
| 61 |
|
| 62 |
function links_schema() {
|
| 63 |
$schema['links'] = array(
|
| 64 |
'fields' => array(
|
| 65 |
'lid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 66 |
'url_md5' => array('type' => 'char', 'length' => 32, 'not null' => TRUE, 'default' => ''),
|
| 67 |
'url' => array('type' => 'text', 'not null' => TRUE, 'default' => ''),
|
| 68 |
'link_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 69 |
'last_click_time' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 70 |
),
|
| 71 |
'primary key' => array('lid'),
|
| 72 |
'unique keys' => array(
|
| 73 |
'url_ix' => array('url_md5'),
|
| 74 |
'title_ix' => array('link_title','lid'),
|
| 75 |
'stale_ix' => array('last_click_time','lid'),
|
| 76 |
),
|
| 77 |
);
|
| 78 |
$schema['links_node'] = array(
|
| 79 |
'fields' => array(
|
| 80 |
'lid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 81 |
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 82 |
'link_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 83 |
'weight' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size'=>'tiny'),
|
| 84 |
'clicks' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 85 |
'module' => array('type' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => ''),
|
| 86 |
),
|
| 87 |
'primary key' => array('lid', 'nid', 'module'),
|
| 88 |
'unique_keys' => array(
|
| 89 |
'node_link_ix1' => array('nid','module','link_title','lid'),
|
| 90 |
'node_link_ix2' => array('link_title','nid','module','lid'),
|
| 91 |
'node_link_ix3' => array('nid','module','lid','weight'),
|
| 92 |
),
|
| 93 |
);
|
| 94 |
$schema['links_monitor'] = array(
|
| 95 |
'fields' => array(
|
| 96 |
'lid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 97 |
'check_interval' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 98 |
'last_check' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 99 |
'fail_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 100 |
'alternate_monitor_url' => array('type' => 'text', 'not null' => FALSE),
|
| 101 |
'redirect_propose_url' => array('type' => 'text', 'not null' => FALSE),
|
| 102 |
'redirect_saved_url' => array('type' => 'text', 'not null' => FALSE),
|
| 103 |
'change_threshold' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 104 |
'change_flag' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size'=>'tiny'),
|
| 105 |
'change_last_data' => array('type' => 'text', 'not null' => FALSE),
|
| 106 |
),
|
| 107 |
'primary key' => array('lid'),
|
| 108 |
'unique keys' => array(
|
| 109 |
'check_ix' => array('last_check','check_interval','lid'),
|
| 110 |
'change_ix' => array('change_flag','last_check','lid'),
|
| 111 |
'rotted_ix' => array('fail_count','last_check','lid'),
|
| 112 |
),
|
| 113 |
);
|
| 114 |
return $schema;
|
| 115 |
}
|