nodequeue.install in Nodequeue 6.2
Same filename and directory in other branches
Install, update and uninstall functions for the nodequeue module.
File
nodequeue.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the nodequeue module.
*/
/**
* Implementation of hook_schema().
*/
function nodequeue_schema() {
$schema['nodequeue_queue'] = array(
'description' => 'Base table for queues, storing global information for each queue',
'fields' => array(
'qid' => array(
'description' => 'The primary identifier for a queue.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'The machine name for the queue',
'type' => 'varchar',
'length' => 128,
),
'title' => array(
'description' => 'Title of a queue.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'subqueue_title' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'size' => array(
'description' => 'How many nodes this queue will hold',
'type' => 'int',
'default' => 0,
),
'link' => array(
'description' => 'The link text to show under a node to add it to the queue.',
'type' => 'varchar',
'length' => 40,
),
'link_remove' => array(
'description' => 'The link text to show under a node to remove it from the queue.',
'type' => 'varchar',
'length' => 40,
),
'owner' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
),
'show_in_ui' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
),
'show_in_tab' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
),
'show_in_links' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
),
'reference' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'default' => '0',
),
'reverse' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
),
'i18n' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
),
),
// fields
'primary key' => array(
'qid',
),
'unique keys' => array(
'name' => array(
'name',
),
),
);
// nodequeue_queue.
$schema['nodequeue_roles'] = array(
'description' => 'Defines the roles which are allowed to use a particular nodequeue.',
'fields' => array(
'qid' => array(
'description' => 'Primary key for {nodequeue_queue}',
'type' => 'int',
'size' => 'big',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rid' => array(
'description' => 'Primary key for roles',
'type' => 'int',
'size' => 'big',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
// fields
'indexes' => array(
'qid' => array(
'qid',
),
'rid' => array(
'rid',
),
),
);
// nodequeue_roles
$schema['nodequeue_types'] = array(
'description' => 'Defines the node types which are allowed in each queue',
'fields' => array(
'qid' => array(
'description' => 'Primary key for {nodequeue_queue}',
'type' => 'int',
'size' => 'big',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Node Type',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
// fields
'indexes' => array(
'qid' => array(
'qid',
),
'type' => array(
'type',
),
),
);
// nodequeue_types
// 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.
$schema['nodequeue_subqueue'] = array(
'description' => '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.',
'fields' => array(
'sqid' => array(
'description' => 'Subqueue identifier',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'qid' => array(
'description' => 'Queue identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'reference' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'default' => '0',
'not null' => FALSE,
),
'title' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
),
// fields
'primary key' => array(
'sqid',
),
'indexes' => array(
'qid' => array(
'qid',
),
'reference' => array(
'reference',
),
'title' => array(
'title',
),
),
);
// nodequeue_subqueue
$schema['nodequeue_nodes'] = array(
'description' => 'Indicates which nodes are in which queues/subqueues.',
'fields' => array(
'qid' => array(
'description' => 'Queue id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'sqid' => array(
'description' => 'Subqueue this node is in',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'Node id in this subqueue',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'position' => array(
'description' => 'The position of the node in this subqueue.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'timestamp' => array(
'description' => "The time that the item's position in the subqueue was updated.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
// fields
'indexes' => array(
'sqid' => array(
'sqid',
'position',
),
'nid' => array(
'nid',
),
'qid_nid' => array(
'qid',
'nid',
),
),
);
// nodequeue_nodes
return $schema;
}
/**
* Implementation of hook_install().
*/
function nodequeue_install() {
drupal_install_schema('nodequeue');
}
/**
* Implementation of hook_uninstall().
*/
function nodequeue_uninstall() {
drupal_uninstall_schema('nodequeue');
// Remove our variables.
$variables = array(
'nodequeue_use_tab',
'nodequeue_tab_display_max',
'nodequeue_tab_name',
'nodequeue_autocomplete_limit',
'nodequeue_view_per_queue',
);
foreach ($variables as $variable) {
variable_del($variable);
}
}
// TODO: Figure out what to fix here?
function nodequeue_update_1() {
if ($GLOBALS['db_type'] == 'pgsql') {
db_query("CREATE SEQUENCE nodequeue_queue_qid_seq INCREMENT 1 START 1");
}
}
function nodequeue_update_5000() {
$ret = array();
$ret[] = array(
'success' => TRUE,
'query' => t('Some of the following queries may appear to fail. This is not a problem.'),
);
db_add_field($ret, "nodequeue_queue", "link", array(
'description' => 'The link text to show under a node to add it to the queue.',
'type' => 'varchar',
'length' => 40,
));
db_add_field($ret, "nodequeue_queue", "link_remove", array(
'description' => 'The link text to show under a node to remove it from the queue.',
'type' => 'varchar',
'length' => 40,
));
//$ret[] = update_sql("ALTER TABLE {nodequeue_queue} ADD COLUMN link VARCHAR(40) DEFAULT '' NOT NULL");
//$ret[] = update_sql("ALTER TABLE {nodequeue_queue} ADD COLUMN link_remove VARCHAR(40) DEFAULT '' NOT NULL");
db_add_index($ret, 'nodequeue_roles', "{nodequeue_roles}_qid", array(
'qid',
));
db_add_index($ret, "nodequeue_roles", "{nodequeue_roles}_rid", array(
'rid',
));
db_add_index($ret, "nodequeue_types", "{nodequeue_types}_qid", array(
'qid',
));
db_add_index($ret, "nodequeue_nodes", "{nodequeue_nodes}_qid", array(
'qid',
'position',
));
db_add_index($ret, "nodequeue_nodes", "{nodequeue_nodes}_nid", array(
'nid',
));
//$ret[] = update_sql("CREATE INDEX {nodequeue_roles}_qid_idx ON {nodequeue_roles} (qid)");
//$ret[] = update_sql("CREATE INDEX {nodequeue_roles}_rid_idx ON {nodequeue_roles} (rid)");
//$ret[] = update_sql("CREATE INDEX {nodequeue_types}_qid_idx ON {nodequeue_types} (qid)");
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_qid_idx ON {nodequeue_nodes} (qid, position)");
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_nid_idx ON {nodequeue_nodes} (nid)");
// TODO: Figure out how to fix this?
//$ret[] = _system_update_utf8(array('nodequeue_queue', 'nodequeue_roles', 'nodequeue_types', 'nodequeue_nodes'));
return $ret;
}
function nodequeue_update_5001() {
$ret = array();
/*switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {nodequeue_nodes} ADD COLUMN timestamp int DEFAULT '0' NOT NULL");
break;
case 'pgsql':
db_add_column($ret, 'nodequeue_nodes', 'timestamp', 'integer', array('default' => 0, 'not null' => TRUE));
break;
}*/
db_add_column($ret, 'nodequeue_nodes', 'timestamp', array(
'type' => 'int',
'default' => 0,
'not null' => TRUE,
));
return $ret;
}
function nodequeue_update_5201() {
$ret = array();
// Add new columns to the nodequeue_queue table.
db_add_column($ret, 'nodequeue_queue', 'owner', array(
'type' => 'varchar',
'length' => 255,
'default' => "'nodequeue'",
));
db_add_column($ret, 'nodequeue_queue', 'show_in_ui', array(
'type' => 'int',
'default' => 1,
));
db_add_column($ret, 'nodequeue_queue', 'show_in_tab', array(
'type' => 'int',
'default' => 1,
));
db_add_column($ret, 'nodequeue_queue', 'show_in_links', array(
'type' => 'int',
'default' => 1,
));
db_add_column($ret, 'nodequeue_queue', 'reference', array(
'type' => 'varchar',
'length' => 255,
'default' => 0,
));
// Create the nodequeue_subqueue table.
$ret[] = update_sql("UPDATE {nodequeue_queue} SET owner = 'nodequeue', show_in_ui = 1, show_in_tab = 1, show_in_links = 1, reference = 0");
db_create_table($ret, 'nodequeue_subqueue', array(
'description' => '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.',
'fields' => array(
'sqid' => array(
'description' => 'Subqueue identifier',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'qid' => array(
'description' => 'Queue identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'reference' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'default' => '0',
),
'title' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
),
// fields
'primary key' => array(
'sqid',
),
'indexes' => array(
'{nodequeue_subqueue}_qid_idx' => array(
'qid',
),
'{nodequeue_subqueue}_reference_idx' => array(
'reference',
),
'{nodequeue_subqueue}_title_idx' => array(
'title',
),
),
));
// Populate the nodequeue_subqueue table.
$result = db_query("SELECT * FROM {nodequeue_queue}");
while ($queue = db_fetch_object($result)) {
// Keep the qid so that we can update our sequence table later on.
$last_qid = $queue->qid;
$ret[] = update_sql("INSERT INTO {nodequeue_subqueue} (sqid, qid, reference, title) VALUES (%d, %d, %d, '%s')", $queue->qid, $queue->qid, $queue->qid, $queue->title);
}
// Transform the nodequeue_nodes table.
db_add_field($ret, 'nodequeue_nodes', 'sqid', array(
'type' => 'int',
));
$ret[] = update_sql("UPDATE {nodequeue_nodes} SET sqid = qid");
db_add_index($ret, 'nodequeue_nodes', '{nodequeue_nodes}_sqid', array(
'sqid',
'position',
));
//$ret[] = update_sql("CREATE INDEX {nodequeue_nodes}_sqid_idx ON {nodequeue_nodes} (sqid, position)");
return $ret;
}
function nodequeue_update_5202() {
$ret = array();
db_add_field($ret, 'nodequeue_queue', 'subqueue_title', array(
'type' => 'varchar',
'length' => 255,
));
return $ret;
}
function nodequeue_update_5203() {
$ret = array();
db_add_field($ret, 'nodequeue_queue', 'reverse', array(
type => 'int',
));
return $ret;
}
function nodequeue_update_5204() {
$ret = array();
db_change_field($ret, 'nodequeue_queue', 'reverse', 'reverse', array(
'type' => 'int',
'size' => 'tiny',
));
return $ret;
}
function nodequeue_update_5205() {
$ret = array();
db_drop_primary_key($ret, 'nodequeue_queue');
db_change_field($ret, 'nodequeue_queue', 'qid', 'qid', array(
'type' => 'serial',
'not null' => TRUE,
), array(
'primary key' => array(
'qid',
),
));
db_drop_primary_key($ret, 'nodequeue_subqueue');
db_change_field($ret, 'nodequeue_subqueue', 'sqid', 'sqid', array(
'type' => 'serial',
'not null' => TRUE,
), array(
'primary key' => array(
'sqid',
),
));
//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.
if (empty($ret)) {
return array();
}
return $ret;
}
/**
* 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.
*/
function nodequeue_update_6000() {
$ret = array();
db_change_field($ret, 'nodequeue_queue', 'link', 'link', array(
'type' => 'varchar',
'length' => 40,
));
db_change_field($ret, 'nodequeue_queue', 'link_remove', 'link_remove', array(
'type' => 'varchar',
'length' => 40,
));
return $ret;
}
function nodequeue_update_6001() {
$ret = array();
db_add_field($ret, 'nodequeue_queue', 'i18n', array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'default' => 1,
));
return $ret;
}
//The previous 6002 update has been moved to 5205.
/**
* Remove invalid entries from the nodequeue_nodes table created as a result of
* bugs like http://drupal.org/node/593858.
*/
function nodequeue_update_6003() {
$ret = array();
$invalid = db_result(db_query("SELECT count(nid) FROM {nodequeue_nodes} WHERE nid = 0"));
if (!empty($invalid)) {
$ret[] = update_sql("DELETE FROM {nodequeue_nodes} WHERE nid = 0");
$t = get_t();
$ret[] = array(
'success' => TRUE,
'query' => $t("Deleted @invalid invalid entries from the {nodequeue_nodes} table.", array(
'@invalid' => $invalid,
)),
);
}
else {
$ret[] = array(
'success' => TRUE,
'query' => "No invalid entries found in the {nodequeue_nodes} table.",
);
}
return $ret;
}
/**
* Add a new index to {nodequeue_nodes}
*/
function nodequeue_update_6004() {
$ret = array();
db_add_index($ret, 'nodequeue_nodes', '{nodequeue_nodes}_qid_nid_idx', array(
'qid',
'nid',
));
return $ret;
}
/**
* Rename the 'nodequeue_automatic_views_generation'
* to 'nodequeue_view_per_queue'.
*/
function nodequeue_update_6005() {
$ret = array();
$ret[] = update_sql("UPDATE {system} set name = 'nodequeue_view_per_queue' where name = 'nodequeue_automatic_views_generation'");
return $ret;
}
/**
* Implementation of hook_update_N
* Renaming indices so that they're consistent with what Schema module would expect
*/
function nodequeue_update_6006() {
$ret = array();
// Get all indices from {nodequeue_nodes}.
$result = db_query("SHOW INDEX FROM {nodequeue_nodes}");
while ($index = db_fetch_array($result)) {
$nn_indices[$index['Key_name']] = $index;
}
// Check if one the indices exists before trying to drop them.
if (isset($nn_indices['nodequeue_nodes_sqid_idx'])) {
// Delete existing indexes
$del_indices = array(
'nodequeue_roles' => array(
'qid',
'rid',
),
'nodequeue_types' => array(
'qid',
'type',
),
'nodequeue_subqueue' => array(
'qid',
'reference',
'title',
),
'nodequeue_nodes' => array(
'sqid',
'qid_nid',
),
);
foreach ($del_indices as $table => $indices) {
foreach ($indices as $k => $index) {
db_drop_index($ret, $table, $table . "_" . $index . "_idx");
}
}
// Naming convention incorrect for this one
db_drop_index($ret, "nodequeue_nodes", "nodequeue_subqueue_nid_idx");
}
// Check if the new indices weren't already created.
if (!isset($nn_indices['sqid'])) {
// Create new indexes
$add_indexes = array(
'nodequeue_roles' => array(
'qid' => array(
'qid',
),
'rid' => array(
'rid',
),
),
'nodequeue_types' => array(
'qid' => array(
'qid',
),
'type' => array(
'type',
),
),
'nodequeue_subqueue' => array(
'qid' => array(
'qid',
),
'reference' => array(
'reference',
),
'title' => array(
'title',
),
),
'nodequeue_nodes' => array(
'sqid' => array(
'sqid',
'position',
),
'qid_nid' => array(
'qid',
'nid',
),
'nid' => array(
'nid',
),
),
);
foreach ($add_indexes as $table => $indices) {
foreach ($indices as $name => $columns) {
db_add_index($ret, $table, $name, $columns);
}
}
}
return $ret;
}
/**
* Provide machine names, and auto-generation of machine names for existing
* queues.
*/
function nodequeue_update_6007() {
$ret = array();
db_add_field($ret, 'nodequeue_queue', 'name', array(
'type' => 'varchar',
'length' => 128,
));
db_add_unique_key($ret, 'nodequeue_queue', 'name', array(
'name',
));
// Auto-generate machine names for existing queues and subqueues. Existing
// queues will be named "queue{$qid}" while subqueues will be named
// "queue{$qid}_subqueue{$sqid}"
global $db_type;
if ($db_type == 'mysql' || $db_type == 'mysqli') {
$queue_update_sql = "UPDATE {nodequeue_queue} SET name = CONCAT('queue', qid)";
}
else {
$queue_update_sql = "UPDATE {nodequeue_queue} SET name = 'queue'||qid";
}
$ret[] = update_sql($queue_update_sql);
return $ret;
}
Functions
Name![]() |
Description |
---|---|
nodequeue_install | Implementation of hook_install(). |
nodequeue_schema | Implementation of hook_schema(). |
nodequeue_uninstall | Implementation of hook_uninstall(). |
nodequeue_update_1 | |
nodequeue_update_5000 | |
nodequeue_update_5001 | |
nodequeue_update_5201 | |
nodequeue_update_5202 | |
nodequeue_update_5203 | |
nodequeue_update_5204 | |
nodequeue_update_5205 | |
nodequeue_update_6000 | 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. |
nodequeue_update_6001 | |
nodequeue_update_6003 | Remove invalid entries from the nodequeue_nodes table created as a result of bugs like http://drupal.org/node/593858. |
nodequeue_update_6004 | Add a new index to {nodequeue_nodes} |
nodequeue_update_6005 | Rename the 'nodequeue_automatic_views_generation' to 'nodequeue_view_per_queue'. |
nodequeue_update_6006 | Implementation of hook_update_N Renaming indices so that they're consistent with what Schema module would expect |
nodequeue_update_6007 | Provide machine names, and auto-generation of machine names for existing queues. |