| 1 |
<?php
|
| 2 |
// $Id: nodequeue.install,v 1.18 2009/10/03 20:32:12 ezrag Exp $
|
| 3 |
|
| 4 |
function nodequeue_schema() {
|
| 5 |
$schema['nodequeue_queue'] = array(
|
| 6 |
'description' => t('Base table for queues, storing global information for each queue'),
|
| 7 |
'fields' => array(
|
| 8 |
'qid' => array(
|
| 9 |
'description' => t('The primary identifier for a queue.'),
|
| 10 |
'type' => 'serial',
|
| 11 |
'unsigned' => TRUE,
|
| 12 |
'not null' => TRUE
|
| 13 |
),
|
| 14 |
'title' => array(
|
| 15 |
'description' => t('Title of a queue.'),
|
| 16 |
'type' => 'varchar',
|
| 17 |
'length' => 255,
|
| 18 |
'not null' => TRUE,
|
| 19 |
),
|
| 20 |
'subqueue_title' => array(
|
| 21 |
'description' => '',
|
| 22 |
'type' => 'varchar',
|
| 23 |
'length' => 255,
|
| 24 |
'not null' => TRUE,
|
| 25 |
),
|
| 26 |
'size' => array(
|
| 27 |
'description' => t('How many nodes this queue will hold'),
|
| 28 |
'type' => 'int',
|
| 29 |
'default' => 0,
|
| 30 |
),
|
| 31 |
'link' => array(
|
| 32 |
'description' => t('The link text to show under a node to add it to the queue.'),
|
| 33 |
'type' => 'varchar',
|
| 34 |
'length' => 40,
|
| 35 |
),
|
| 36 |
'link_remove' => array(
|
| 37 |
'description' => t('The link text to show under a node to remove it from the queue.'),
|
| 38 |
'type' => 'varchar',
|
| 39 |
'length' => 40,
|
| 40 |
),
|
| 41 |
'owner' => array(
|
| 42 |
'description' => '',
|
| 43 |
'type' => 'varchar',
|
| 44 |
'length' => 255,
|
| 45 |
),
|
| 46 |
'show_in_ui' => array(
|
| 47 |
'description' => '',
|
| 48 |
'type' => 'int',
|
| 49 |
'size' => 'tiny',
|
| 50 |
'default' => 1,
|
| 51 |
),
|
| 52 |
'show_in_tab' => array(
|
| 53 |
'description' => '',
|
| 54 |
'type' => 'int',
|
| 55 |
'size' => 'tiny',
|
| 56 |
'default' => 1,
|
| 57 |
),
|
| 58 |
'show_in_links' => array(
|
| 59 |
'description' => '',
|
| 60 |
'type' => 'int',
|
| 61 |
'size' => 'tiny',
|
| 62 |
'default' => 1,
|
| 63 |
),
|
| 64 |
'reference' => array(
|
| 65 |
'description' => '',
|
| 66 |
'type' => 'varchar',
|
| 67 |
'length' => 255,
|
| 68 |
'default' => '0',
|
| 69 |
),
|
| 70 |
'reverse' => array(
|
| 71 |
'description' => '',
|
| 72 |
'type' => 'int',
|
| 73 |
'size' => 'tiny',
|
| 74 |
),
|
| 75 |
'i18n' => array(
|
| 76 |
'description' => '',
|
| 77 |
'type' => 'int',
|
| 78 |
'size' => 'tiny',
|
| 79 |
'default' => 1,
|
| 80 |
),
|
| 81 |
), // fields
|
| 82 |
'primary key' => array('qid'),
|
| 83 |
); // nodequeue_queue.
|
| 84 |
$schema['nodequeue_roles'] = array(
|
| 85 |
'description' => t('Defines the roles which are allowed to use a particular nodequeue.'),
|
| 86 |
'fields' => array(
|
| 87 |
'qid' => array(
|
| 88 |
'description' => t('Primary key for {nodequeue_queue}'),
|
| 89 |
'type' => 'int',
|
| 90 |
'size' => 'big',
|
| 91 |
'unsigned' => TRUE,
|
| 92 |
'not null' => TRUE
|
| 93 |
),
|
| 94 |
'rid' => array(
|
| 95 |
'description' => t('Primary key for roles'),
|
| 96 |
'type' => 'int',
|
| 97 |
'size' => 'big',
|
| 98 |
'unsigned' => TRUE,
|
| 99 |
'not null' => TRUE
|
| 100 |
),
|
| 101 |
), // fields
|
| 102 |
'indexes' => array(
|
| 103 |
'{nodequeue_roles}_qid_idx' => array('qid'),
|
| 104 |
'{nodequeue_roles}_rid_idx' => array('rid'),
|
| 105 |
), // indexes
|
| 106 |
); // nodequeue_roles
|
| 107 |
$schema['nodequeue_types'] = array(
|
| 108 |
'description' => t('Defines the node types which are allowed in each queue'),
|
| 109 |
'fields' => array(
|
| 110 |
'qid' => array(
|
| 111 |
'description' => t('Primary key for {nodequeue_queue}'),
|
| 112 |
'type' => 'int',
|
| 113 |
'size' => 'big',
|
| 114 |
'unsigned' => TRUE,
|
| 115 |
'not null' => TRUE
|
| 116 |
),
|
| 117 |
'type' => array(
|
| 118 |
'description' => t('Node Type'),
|
| 119 |
'type' => 'varchar',
|
| 120 |
'length' => 255,
|
| 121 |
'not null' => FALSE
|
| 122 |
),
|
| 123 |
), // fields
|
| 124 |
'indexes' => array(
|
| 125 |
'{nodequeue_types}_qid_idx' => array('qid'),
|
| 126 |
'{nodequeue_types}_type_idx' => array('type'),
|
| 127 |
), // indexes
|
| 128 |
); // nodequeue_types
|
| 129 |
|
| 130 |
// Subqueues are minor queues that inherit all of the properties of
|
| 131 |
// the parent queue. A parent queue must have at least 1 subqueue
|
| 132 |
// to do anything. Reference is for the use of whatever is creating
|
| 133 |
// the subqueues in order to link it to some other ID easily.
|
| 134 |
$schema['nodequeue_subqueue'] = array(
|
| 135 |
'description' => t('Subqueues are minor queues that inherit all of the properties of the parent queue. A parent queue must have at least 1 subqueue to do anything. Reference is for the use of whatever is creating the subqueues in order to link it to some other ID easily.'),
|
| 136 |
'fields' => array(
|
| 137 |
'sqid' => array(
|
| 138 |
'description' => t('Subqueue identifier'),
|
| 139 |
'type' => 'serial',
|
| 140 |
'unsigned' => TRUE,
|
| 141 |
'not null' => TRUE,
|
| 142 |
),
|
| 143 |
'qid' => array(
|
| 144 |
'description' => t('Queue identifier.'),
|
| 145 |
'type' => 'int',
|
| 146 |
'unsigned' => TRUE,
|
| 147 |
'not null' => TRUE,
|
| 148 |
),
|
| 149 |
'reference' => array(
|
| 150 |
'description' => '',
|
| 151 |
'type' => 'varchar',
|
| 152 |
'length' => 255,
|
| 153 |
'default' => '0',
|
| 154 |
'not null' => FALSE
|
| 155 |
),
|
| 156 |
'title' => array(
|
| 157 |
'description' => '',
|
| 158 |
'type' => 'varchar',
|
| 159 |
'length' => 255,
|
| 160 |
'default' => '',
|
| 161 |
'not null' => FALSE
|
| 162 |
),
|
| 163 |
), // fields
|
| 164 |
'primary key' => array('sqid'),
|
| 165 |
'indexes' => array(
|
| 166 |
'{nodequeue_subqueue}_qid_idx' => array('qid'),
|
| 167 |
'{nodequeue_subqueue}_reference_idx' => array('reference'),
|
| 168 |
'{nodequeue_subqueue}_title_idx' => array('title'),
|
| 169 |
), // indexes
|
| 170 |
); // nodequeue_subqueue
|
| 171 |
|
| 172 |
$schema['nodequeue_nodes'] = array(
|
| 173 |
'description' => t('Indicates which nodes are in which queues/subqueues.'),
|
| 174 |
'fields' => array(
|
| 175 |
'qid' => array(
|
| 176 |
'description' => t('Queue id'),
|
| 177 |
'type' => 'int',
|
| 178 |
'unsigned' => TRUE,
|
| 179 |
'not null' => TRUE,
|
| 180 |
),
|
| 181 |
'sqid' => array(
|
| 182 |
'description' => t('Subqueue this node is in'),
|
| 183 |
'type' => 'int',
|
| 184 |
'unsigned' => TRUE,
|
| 185 |
'not null' => TRUE,
|
| 186 |
),
|
| 187 |
'nid' => array(
|
| 188 |
'description' => t('Node id in this subqueue'),
|
| 189 |
'type' => 'int',
|
| 190 |
'unsigned' => TRUE,
|
| 191 |
'not null' => FALSE
|
| 192 |
),
|
| 193 |
'position' => array(
|
| 194 |
'description' => t('The position of the node in this subqueue.'),
|
| 195 |
'type' => 'int',
|
| 196 |
'unsigned' => TRUE,
|
| 197 |
'not null' => FALSE
|
| 198 |
),
|
| 199 |
'timestamp' => array(
|
| 200 |
'description' => t(''),
|
| 201 |
'type' => 'int',
|
| 202 |
'unsigned' => TRUE,
|
| 203 |
'not null' => TRUE,
|
| 204 |
'default' => 0,
|
| 205 |
),
|
| 206 |
), // fields
|
| 207 |
'indexes' => array(
|
| 208 |
'{nodequeue_nodes}_sqid_idx' => array('sqid', 'position'),
|
| 209 |
'{nodequeue_subqueue}_nid_idx' => array('nid'),
|
| 210 |
'{nodequeue_nodes}_qid_nid_idx' => array('qid', 'nid'),
|
| 211 |
), // indexes
|
| 212 |
); // nodequeue_nodes
|
| 213 |
|
| 214 |
return $schema;
|
| 215 |
}
|
| 216 |
|
| 217 |
// TODO: Figure out what to fix here?
|
| 218 |
function nodequeue_update_1() {
|
| 219 |
if ($GLOBALS['db_type'] == 'pgsql') {
|
| 220 |
db_query("CREATE SEQUENCE nodequeue_queue_qid_seq INCREMENT 1 START 1");
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 224 |
function nodequeue_update_5000() {
|
| 225 |
$ret = array();
|
| 226 |
$ret[] = array('success' => TRUE, 'query' => t('Some of the following queries may appear to fail. This is not a problem.'));
|
| 227 |
|
| 228 |
db_add_field($ret, "nodequeue_queue", "link", array(
|
| 229 |
'description' => t('The link text to show under a node to add it to the queue.'),
|
| 230 |
'type' => 'varchar',
|
| 231 |
'length' => 40,
|
| 232 |
));
|
| 233 |
db_add_field($ret, "nodequeue_queue", "link_remove", array(
|
| 234 |
'description' => t('The link text to show under a node to remove it from the queue.'),
|
| 235 |
'type' => 'varchar',
|
| 236 |
'length' => 40,
|
| 237 |
));
|
| 238 |
//$ret[] = update_sql("ALTER TABLE {nodequeue_queue} ADD COLUMN link VARCHAR(40) DEFAULT '' NOT NULL");
|
| 239 |
//$ret[] = update_sql("ALTER TABLE {nodequeue_queue} ADD COLUMN link_remove VARCHAR(40) DEFAULT '' NOT NULL");
|
| 240 |
|
| 241 |
db_add_index($ret, 'nodequeue_roles', "{nodequeue_roles}_qid", array('qid'));
|
| 242 |
db_add_index($ret, "nodequeue_roles", "{nodequeue_roles}_rid", array('rid'));
|
| 243 |
db_add_index($ret, "nodequeue_types", "{nodequeue_types}_qid", array('qid'));
|
| 244 |
db_add_index($ret, "nodequeue_nodes", "{nodequeue_nodes}_qid", array('qid', 'position'));
|
| 245 |
db_add_index($ret, "nodequeue_nodes", "{nodequeue_nodes}_nid", array('nid'));
|
| 246 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_roles}_qid_idx ON {nodequeue_roles} (qid)");
|
| 247 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_roles}_rid_idx ON {nodequeue_roles} (rid)");
|
| 248 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_types}_qid_idx ON {nodequeue_types} (qid)");
|
| 249 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_qid_idx ON {nodequeue_nodes} (qid, position)");
|
| 250 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_nid_idx ON {nodequeue_nodes} (nid)");
|
| 251 |
|
| 252 |
// TODO: Figure out how to fix this?
|
| 253 |
//$ret[] = _system_update_utf8(array('nodequeue_queue', 'nodequeue_roles', 'nodequeue_types', 'nodequeue_nodes'));
|
| 254 |
return $ret;
|
| 255 |
}
|
| 256 |
|
| 257 |
function nodequeue_update_5001() {
|
| 258 |
$ret = array();
|
| 259 |
/*switch ($GLOBALS['db_type']) {
|
| 260 |
case 'mysql':
|
| 261 |
case 'mysqli':
|
| 262 |
$ret[] = update_sql("ALTER TABLE {nodequeue_nodes} ADD COLUMN timestamp int DEFAULT '0' NOT NULL");
|
| 263 |
break;
|
| 264 |
case 'pgsql':
|
| 265 |
db_add_column($ret, 'nodequeue_nodes', 'timestamp', 'integer', array('default' => 0, 'not null' => TRUE));
|
| 266 |
break;
|
| 267 |
}*/
|
| 268 |
db_add_column($ret, 'nodequeue_nodes', 'timestamp', array('type' => 'int', 'default' => 0, 'not null' => TRUE));
|
| 269 |
return $ret;
|
| 270 |
}
|
| 271 |
|
| 272 |
function nodequeue_update_5201() {
|
| 273 |
$ret = array();
|
| 274 |
// Add new columns to the nodequeue_queue table.
|
| 275 |
db_add_column($ret, 'nodequeue_queue', 'owner', array('type' => 'varchar', 'length' => 255, 'default' => "'nodequeue'"));
|
| 276 |
db_add_column($ret, 'nodequeue_queue', 'show_in_ui', array('type' => 'int', 'default' => 1));
|
| 277 |
db_add_column($ret, 'nodequeue_queue', 'show_in_tab', array('type' => 'int', 'default' => 1));
|
| 278 |
db_add_column($ret, 'nodequeue_queue', 'show_in_links', array('type' => 'int', 'default' => 1));
|
| 279 |
db_add_column($ret, 'nodequeue_queue', 'reference', array('type' => 'varchar', 'length' => 255, 'default' => 0));
|
| 280 |
|
| 281 |
// Create the nodequeue_subqueue table.
|
| 282 |
$ret[] = update_sql("UPDATE {nodequeue_queue} SET owner = 'nodequeue', show_in_ui = 1, show_in_tab = 1, show_in_links = 1, reference = 0");
|
| 283 |
|
| 284 |
db_create_table($ret, 'nodequeue_subqueue', array(
|
| 285 |
'description' => t('Subqueues are minor queues that inherit all of the properties of the parent queue. A parent queue must have at least 1 subqueue to do anything. Reference is for the use of whatever is creating the subqueues in order to link it to some other ID easily.'),
|
| 286 |
'fields' => array(
|
| 287 |
'sqid' => array(
|
| 288 |
'description' => t('Subqueue identifier'),
|
| 289 |
'type' => 'serial',
|
| 290 |
'unsigned' => TRUE,
|
| 291 |
'not null' => TRUE,
|
| 292 |
),
|
| 293 |
'qid' => array(
|
| 294 |
'description' => t('Queue identifier.'),
|
| 295 |
'type' => 'int',
|
| 296 |
'unsigned' => TRUE,
|
| 297 |
'not null' => TRUE,
|
| 298 |
),
|
| 299 |
'reference' => array(
|
| 300 |
'description' => '',
|
| 301 |
'type' => 'varchar',
|
| 302 |
'length' => 255,
|
| 303 |
'default' => '0',
|
| 304 |
),
|
| 305 |
'title' => array(
|
| 306 |
'description' => '',
|
| 307 |
'type' => 'varchar',
|
| 308 |
'length' => 255,
|
| 309 |
'default' => '',
|
| 310 |
),
|
| 311 |
), // fields
|
| 312 |
'primary key' => array('sqid'),
|
| 313 |
'indexes' => array(
|
| 314 |
'{nodequeue_subqueue}_qid_idx' => array('qid'),
|
| 315 |
'{nodequeue_subqueue}_reference_idx' => array('reference'),
|
| 316 |
'{nodequeue_subqueue}_title_idx' => array('title'),
|
| 317 |
), // indexes
|
| 318 |
));
|
| 319 |
|
| 320 |
// Populate the nodequeue_subqueue table.
|
| 321 |
$result = db_query("SELECT * FROM {nodequeue_queue}");
|
| 322 |
while ($queue = db_fetch_object($result)) {
|
| 323 |
// Keep the qid so that we can update our sequence table later on.
|
| 324 |
$last_qid = $queue->qid;
|
| 325 |
$ret[] = update_sql("INSERT INTO {nodequeue_subqueue} (sqid, qid, reference, title) VALUES (%d, %d, %d, '%s')", $queue->qid, $queue->qid, $queue->qid, $queue->title);
|
| 326 |
}
|
| 327 |
|
| 328 |
// Transform the nodequeue_nodes table.
|
| 329 |
db_add_field($ret, 'nodequeue_nodes', 'sqid', array('type' => 'int'));
|
| 330 |
$ret[] = update_sql("UPDATE {nodequeue_nodes} SET sqid = qid");
|
| 331 |
db_add_index($ret, 'nodequeue_nodes', '{nodequeue_nodes}_sqid', array('sqid', 'position'));
|
| 332 |
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_sqid_idx ON {nodequeue_nodes} (sqid, position)");
|
| 333 |
|
| 334 |
return $ret;
|
| 335 |
}
|
| 336 |
|
| 337 |
function nodequeue_update_5202() {
|
| 338 |
$ret = array();
|
| 339 |
db_add_field($ret, 'nodequeue_queue', 'subqueue_title', array('type' => 'varchar', 'length' => 255));
|
| 340 |
return $ret;
|
| 341 |
}
|
| 342 |
|
| 343 |
function nodequeue_update_5203() {
|
| 344 |
$ret = array();
|
| 345 |
db_add_field($ret, 'nodequeue_queue', 'reverse', array(type => 'int'));
|
| 346 |
return $ret;
|
| 347 |
}
|
| 348 |
|
| 349 |
function nodequeue_update_5204() {
|
| 350 |
$ret = array();
|
| 351 |
db_change_field($ret, 'nodequeue_queue', 'reverse', 'reverse', array('type' => 'int', 'size' => 'tiny'));
|
| 352 |
return $ret;
|
| 353 |
}
|
| 354 |
|
| 355 |
function nodequeue_update_5205() {
|
| 356 |
$ret = array();
|
| 357 |
db_drop_primary_key($ret, 'nodequeue_queue');
|
| 358 |
db_change_field($ret, 'nodequeue_queue', 'qid', 'qid',
|
| 359 |
array('type' => 'serial', 'not null' => TRUE),
|
| 360 |
array('primary key' => array('qid')));
|
| 361 |
|
| 362 |
db_drop_primary_key($ret, 'nodequeue_subqueue');
|
| 363 |
db_change_field($ret, 'nodequeue_subqueue', 'sqid', 'sqid',
|
| 364 |
array('type' => 'serial', 'not null' => TRUE),
|
| 365 |
array('primary key' => array('sqid')));
|
| 366 |
//When these quries don't fail, the function fails to return the empty array, causing an array merge error in update.php on line 174.
|
| 367 |
if (empty($ret)) {
|
| 368 |
return array();
|
| 369 |
}
|
| 370 |
return $ret;
|
| 371 |
}
|
| 372 |
/**
|
| 373 |
* There was a discrepancy between the link/link_remove fields created with node_install/node_schema, and the ones created with nodequeue_update_5000. This forces everyone to 40 characters.
|
| 374 |
*
|
| 375 |
*/
|
| 376 |
function nodequeue_update_6000() {
|
| 377 |
$ret = array();
|
| 378 |
db_change_field($ret, 'nodequeue_queue', 'link', 'link', array('type' => 'varchar', 'length' => 40));
|
| 379 |
db_change_field($ret, 'nodequeue_queue', 'link_remove', 'link_remove', array('type' => 'varchar', 'length' => 40));
|
| 380 |
return $ret;
|
| 381 |
}
|
| 382 |
|
| 383 |
function nodequeue_update_6001() {
|
| 384 |
$ret = array();
|
| 385 |
db_add_field($ret, 'nodequeue_queue', 'i18n', array('description' => '', 'type' => 'int', 'size' => 'tiny', 'default' => 1));
|
| 386 |
return $ret;
|
| 387 |
}
|
| 388 |
|
| 389 |
//The previous 6002 update has been moved to 5205.
|
| 390 |
|
| 391 |
/*
|
| 392 |
* Remove invalid entries from the nodequeue_nodes table created as a result of bugs like http://drupal.org/node/593858.
|
| 393 |
*/
|
| 394 |
function nodequeue_update_6003() {
|
| 395 |
$ret = array();
|
| 396 |
$invalid = db_result(db_query("SELECT count(nid) FROM {nodequeue_nodes} WHERE nid = 0"));
|
| 397 |
if (!empty($invalid)) {
|
| 398 |
db_query("DELETE FROM {nodequeue_nodes} WHERE nid = 0");
|
| 399 |
$t = get_t();
|
| 400 |
$ret[] = array('success' => TRUE, 'query' => $t("Deleted @invalid invalid entries from the {nodequeue_nodes} table.", array('@invalid' => $invalid)));
|
| 401 |
}
|
| 402 |
else {
|
| 403 |
$ret[] = array('success' => TRUE, 'query' => "No invalid entries found in the {nodequeue_nodes} table.");
|
| 404 |
}
|
| 405 |
return $ret;
|
| 406 |
}
|
| 407 |
|
| 408 |
/**
|
| 409 |
* Add a new index to {nodequeue_nodes}
|
| 410 |
*/
|
| 411 |
function nodequeue_update_6004() {
|
| 412 |
$ret = array();
|
| 413 |
db_add_index($ret, 'nodequeue_nodes', '{nodequeue_nodes}_qid_nid_idx', array('qid', 'nid'));
|
| 414 |
return $ret;
|
| 415 |
}
|
| 416 |
|
| 417 |
function nodequeue_install() {
|
| 418 |
drupal_install_schema('nodequeue');
|
| 419 |
}
|
| 420 |
|
| 421 |
function nodequeue_uninstall() {
|
| 422 |
drupal_uninstall_schema('nodequeue');
|
| 423 |
}
|
| 424 |
|
| 425 |
/**
|
| 426 |
* Implementation of hook_requirements().
|
| 427 |
*
|
| 428 |
* We need the translation_helpers module to enable internationalization for queues.
|
| 429 |
*/
|
| 430 |
function nodequeue_requirements($phase) {
|
| 431 |
$requirements = array();
|
| 432 |
$t = get_t();
|
| 433 |
if (($phase == 'install' || $phase == 'runtime') && module_exists('translation') && !module_exists('translation_helpers')) {
|
| 434 |
$requirements['nodequeue_translation']['title'] = $t('Nodequeue');
|
| 435 |
$requirements['nodequeue_translation']['severity'] = REQUIREMENT_WARNING;
|
| 436 |
$requirements['nodequeue_translation']['description'] = $t('To have the nodequeue module work with translations, you need to install and enable the !url module.', array('!url' => l('translation_helpers', 'http://drupal.org/project/translation_helpers')));
|
| 437 |
$requirements['nodequeue_translation']['value'] = $t('Translation helpers module not found.');
|
| 438 |
}
|
| 439 |
return $requirements;
|
| 440 |
}
|