| 1 |
<?php
|
| 2 |
// $Id: tracker.install,v 1.1 2009/08/31 08:55:12 dries Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implement hook_install().
|
| 6 |
*/
|
| 7 |
function tracker_install() {
|
| 8 |
drupal_install_schema('tracker');
|
| 9 |
}
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implement hook_uninstall().
|
| 13 |
*/
|
| 14 |
function tracker_uninstall() {
|
| 15 |
drupal_uninstall_schema('tracker');
|
| 16 |
|
| 17 |
variable_del('tracker_index_nid');
|
| 18 |
variable_del('tracker_batch_size');
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implement hook_enable().
|
| 23 |
*/
|
| 24 |
function tracker_enable() {
|
| 25 |
$max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
|
| 26 |
if ($max_nid != 0) {
|
| 27 |
variable_set('tracker_index_nid', $max_nid);
|
| 28 |
// To avoid timing out while attempting to do a complete indexing, we
|
| 29 |
// simply call our cron job to remove stale records and begin the process.
|
| 30 |
tracker_cron();
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Implement hook_schema().
|
| 36 |
*/
|
| 37 |
function tracker_schema() {
|
| 38 |
$schema['tracker_node'] = array(
|
| 39 |
'description' => 'Tracks when nodes were last changed or commented on.',
|
| 40 |
'fields' => array(
|
| 41 |
'nid' => array(
|
| 42 |
'description' => 'The {node}.nid this record tracks.',
|
| 43 |
'type' => 'int',
|
| 44 |
'unsigned' => TRUE,
|
| 45 |
'not null' => TRUE,
|
| 46 |
'default' => 0,
|
| 47 |
),
|
| 48 |
'published' => array(
|
| 49 |
'description' => 'Boolean indicating whether the node is published.',
|
| 50 |
'type' => 'int',
|
| 51 |
'not null' => FALSE,
|
| 52 |
'default' => 0,
|
| 53 |
'size' => 'tiny',
|
| 54 |
),
|
| 55 |
'changed' => array(
|
| 56 |
'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
|
| 57 |
'type' => 'int',
|
| 58 |
'unsigned' => TRUE,
|
| 59 |
'not null' => TRUE,
|
| 60 |
'default' => 0,
|
| 61 |
),
|
| 62 |
),
|
| 63 |
'indexes' => array(
|
| 64 |
'tracker' => array('published', 'changed'),
|
| 65 |
),
|
| 66 |
'primary key' => array('nid'),
|
| 67 |
'foreign keys' => array(
|
| 68 |
'node' => 'nid',
|
| 69 |
),
|
| 70 |
);
|
| 71 |
|
| 72 |
$schema['tracker_user'] = array(
|
| 73 |
'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
|
| 74 |
'fields' => array(
|
| 75 |
'nid' => array(
|
| 76 |
'description' => 'The {node}.nid this record tracks.',
|
| 77 |
'type' => 'int',
|
| 78 |
'unsigned' => TRUE,
|
| 79 |
'not null' => TRUE,
|
| 80 |
'default' => 0,
|
| 81 |
),
|
| 82 |
'uid' => array(
|
| 83 |
'description' => 'The {users}.uid of the node author or commenter.',
|
| 84 |
'type' => 'int',
|
| 85 |
'not null' => TRUE,
|
| 86 |
'default' => 0,
|
| 87 |
),
|
| 88 |
'published' => array(
|
| 89 |
'description' => 'Boolean indicating whether the node is published.',
|
| 90 |
'type' => 'int',
|
| 91 |
'not null' => FALSE,
|
| 92 |
'default' => 0,
|
| 93 |
'size' => 'tiny',
|
| 94 |
),
|
| 95 |
'changed' => array(
|
| 96 |
'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
|
| 97 |
'type' => 'int',
|
| 98 |
'unsigned' => TRUE,
|
| 99 |
'not null' => TRUE,
|
| 100 |
'default' => 0,
|
| 101 |
),
|
| 102 |
),
|
| 103 |
'indexes' => array(
|
| 104 |
'tracker' => array('uid', 'published', 'changed'),
|
| 105 |
),
|
| 106 |
'primary key' => array('nid', 'uid'),
|
| 107 |
'foreign keys' => array(
|
| 108 |
'node' => 'nid',
|
| 109 |
'users' => 'uid',
|
| 110 |
),
|
| 111 |
);
|
| 112 |
|
| 113 |
return $schema;
|
| 114 |
}
|
| 115 |
|
| 116 |
/**
|
| 117 |
* @defgroup updates-6.x-to-7.x Tracker updates from 6.x to 7.x
|
| 118 |
* @{
|
| 119 |
*/
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Create new tracker_node and tracker_user tables.
|
| 123 |
*/
|
| 124 |
function tracker_update_7000() {
|
| 125 |
$schema['tracker_node'] = array(
|
| 126 |
'description' => 'Tracks when nodes were last changed or commented on',
|
| 127 |
'fields' => array(
|
| 128 |
'nid' => array(
|
| 129 |
'description' => 'The {node}.nid this record tracks.',
|
| 130 |
'type' => 'int',
|
| 131 |
'unsigned' => TRUE,
|
| 132 |
'not null' => TRUE,
|
| 133 |
'default' => 0,
|
| 134 |
),
|
| 135 |
'published' => array(
|
| 136 |
'description' => 'Boolean indicating whether the node is published.',
|
| 137 |
'type' => 'int',
|
| 138 |
'not null' => FALSE,
|
| 139 |
'default' => 0,
|
| 140 |
'size' => 'tiny',
|
| 141 |
),
|
| 142 |
'changed' => array(
|
| 143 |
'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
|
| 144 |
'type' => 'int',
|
| 145 |
'unsigned' => TRUE,
|
| 146 |
'not null' => TRUE,
|
| 147 |
'default' => 0,
|
| 148 |
),
|
| 149 |
),
|
| 150 |
'indexes' => array(
|
| 151 |
'tracker' => array('published', 'changed'),
|
| 152 |
),
|
| 153 |
'primary key' => array('nid'),
|
| 154 |
'foreign keys' => array(
|
| 155 |
'node' => 'nid',
|
| 156 |
),
|
| 157 |
);
|
| 158 |
|
| 159 |
$schema['tracker_user'] = array(
|
| 160 |
'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
|
| 161 |
'fields' => array(
|
| 162 |
'nid' => array(
|
| 163 |
'description' => 'The {node}.nid this record tracks.',
|
| 164 |
'type' => 'int',
|
| 165 |
'unsigned' => TRUE,
|
| 166 |
'not null' => TRUE,
|
| 167 |
'default' => 0,
|
| 168 |
),
|
| 169 |
'uid' => array(
|
| 170 |
'description' => 'The {users}.uid of the node author or commenter.',
|
| 171 |
'type' => 'int',
|
| 172 |
'not null' => TRUE,
|
| 173 |
'default' => 0,
|
| 174 |
),
|
| 175 |
'published' => array(
|
| 176 |
'description' => 'Boolean indicating whether the node is published.',
|
| 177 |
'type' => 'int',
|
| 178 |
'not null' => FALSE,
|
| 179 |
'default' => 0,
|
| 180 |
'size' => 'tiny',
|
| 181 |
),
|
| 182 |
'changed' => array(
|
| 183 |
'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
|
| 184 |
'type' => 'int',
|
| 185 |
'unsigned' => TRUE,
|
| 186 |
'not null' => TRUE,
|
| 187 |
'default' => 0,
|
| 188 |
),
|
| 189 |
),
|
| 190 |
'indexes' => array(
|
| 191 |
'tracker' => array('uid', 'published', 'changed'),
|
| 192 |
),
|
| 193 |
'primary key' => array('nid', 'uid'),
|
| 194 |
'foreign keys' => array(
|
| 195 |
'node' => 'nid',
|
| 196 |
'users' => 'uid',
|
| 197 |
),
|
| 198 |
);
|
| 199 |
|
| 200 |
foreach ($schema as $name => $table) {
|
| 201 |
db_create_table($name, $table);
|
| 202 |
}
|
| 203 |
|
| 204 |
$max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
|
| 205 |
if ($max_nid != 0) {
|
| 206 |
variable_set('tracker_index_nid', $max_nid);
|
| 207 |
}
|
| 208 |
}
|
| 209 |
|
| 210 |
/**
|
| 211 |
* @} End of "defgroup updates-6.x-to-7.x"
|
| 212 |
* The next series of updates should start at 8000.
|
| 213 |
*/
|