weight.install in Weight 7
Same filename and directory in other branches
This module uses the sticky column of the node table to add weighting to nodes.
File
weight.installView source
<?php
/**
* @file
* This module uses the sticky column of the node table
* to add weighting to nodes.
*/
/**
* Implements hook_install().
*/
function weight_install() {
// change taxonomy_index sticky field to type INT from TINYINT to hold larger weight values.
$spec = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
}
/**
* Implements hook_uninstall().
*/
function weight_uninstall() {
// We need to unset any weighted nodes and reset sticky to normal values.
$weight_node_types = variable_get('weight_node_types', array());
if ($weight_node_types) {
db_update('node')
->fields(array(
'sticky' => 1,
))
->condition('sticky', 1, '>')
->condition('type', $weight_node_types, 'IN')
->execute();
db_update('node')
->fields(array(
'sticky' => 0,
))
->condition('sticky', 0, '<')
->condition('type', $weight_node_types, 'IN')
->execute();
}
// reset sticky values in taxonomy_index table.
db_update('taxonomy_index')
->fields(array(
'sticky' => 1,
))
->condition('sticky', 1, '>')
->execute();
db_update('taxonomy_index')
->fields(array(
'sticky' => 0,
))
->condition('sticky', 0, '<')
->execute();
// reset taxonomy_index field to original type.
$spec = array(
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
// Delete our variables.
variable_del('weight_node_types');
variable_del('weight_range');
variable_del('weight_use_menu');
}
/**
* Implements hook_schema_alter().
*/
function weight_schema_alter(&$schema) {
$schema['taxonomy_index']['fields']['sticky'] = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
}
/**
* Change {taxonomy_index} stick field to type INT from TINYINT.
*/
function weight_update_7100() {
$spec = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
}
Functions
Name | Description |
---|---|
weight_install | Implements hook_install(). |
weight_schema_alter | Implements hook_schema_alter(). |
weight_uninstall | Implements hook_uninstall(). |
weight_update_7100 | Change {taxonomy_index} stick field to type INT from TINYINT. |