nodeorder.install in Node Order 6
Same filename and directory in other branches
Nodeorder install file.
File
nodeorder.installView source
<?php
/**
* @file
* Nodeorder install file.
*/
/**
* Implementation of hook_install()
*
* Adds field 'weight_in_tid' to core table 'term_node'.
*/
function nodeorder_install() {
$module_name = 'nodeorder';
// Set field properties
$spec = array(
'type' => 'int',
'signed' => TRUE,
'not null' => TRUE,
'default' => 0,
'initial' => 0,
'description' => t('A user-defined weight for each node in its respective category.'),
);
// Create an index for 'weight_in_tid'
$keys['indexes'] = array(
'weight_in_tid' => array(
'weight_in_tid',
),
);
// Add the column to the table
$ret = array();
db_add_field($ret, 'term_node', 'weight_in_tid', $spec, $keys);
// Check for query errors
for ($i = 0; $i < count($ret); $i++) {
if ($ret[$i]['success'] !== TRUE) {
$installation_failed = TRUE;
break;
}
}
if ($installation_failed) {
drupal_set_message(st('Table installation for the %name module was unsuccessful. The tables may need to be installed by hand. See %name.install file for a list of the installation queries.', array(
'%name' => $module_name,
)), 'error');
}
else {
// Set the weight of the nodeorder module in the system table
// so that we come after most other modules in module_invoke_all()
// calls. This ensures that we can alter forms after, for instance,
// the taxonomy module...
db_query("UPDATE {system} SET weight = 5 WHERE name = 'nodeorder' AND type = 'module'");
drupal_set_message(st('The %name module was installed successfully.', array(
'%name' => $module_name,
)));
}
}
/**
* Implementation of hook_uninstall()
*
* Drops field 'weight_in_tid' from core table 'term_node'.
*/
function nodeorder_uninstall() {
$module_name = 'nodeorder';
$ret = array();
db_drop_index($ret, 'term_node', 'weight_in_tid');
db_drop_field($ret, 'term_node', 'weight_in_tid');
// Check for query errors
for ($i = 0; $i < count($ret); $i++) {
if ($ret[$i]['success'] !== TRUE) {
$installation_failed = TRUE;
break;
}
}
if ($installation_failed) {
drupal_set_message(st('Table uninstallation for the %name module was unsuccessful. The tables may need to be installed by hand. See %name.install file for a list of the installation queries.', array(
'%name' => $module_name,
)), 'error');
}
else {
drupal_set_message(st('The %name module was uninstalled successfully.', array(
'%name' => $module_name,
)));
}
}
/**
* Implementation of hook_schema_alter()
*
* Informs drupal_get_schema() of the field addition to 'term_node'.
*/
function nodeorder_schema_alter(&$schema) {
$schema['term_node']['fields']['weight_in_tid'] = array(
'type' => 'int',
'signed' => TRUE,
'not null' => TRUE,
'default' => 0,
'initial' => 0,
'description' => t('A user-defined weight for each node in its respective category.'),
);
}
/**
* Update function for Nodeorder-6.x-1.*
* Original nodeorder schema used an unsigned field for the weight.
* With the new ordering from core this should be changed to a signed field.
* We therefore take the following measures:
* - change the field to a signed field
*/
function nodeorder_update_6100() {
$ret = array();
// Create an index for 'weight_in_tid'
$keys['indexes'] = array(
'weight_in_tid' => array(
'weight_in_tid',
),
);
// Set field properties
$spec = array(
'type' => 'int',
'signed' => TRUE,
'not null' => TRUE,
'default' => 0,
'initial' => 0,
'description' => t('A user-defined weight for each node in its respective category.'),
);
// change field to a SIGNED int
db_change_field($ret, 'term_node', 'weight_in_tid', 'weight_in_tid', $spec, $keys);
return $ret;
}
Functions
Name | Description |
---|---|
nodeorder_install | Implementation of hook_install() |
nodeorder_schema_alter | Implementation of hook_schema_alter() |
nodeorder_uninstall | Implementation of hook_uninstall() |
nodeorder_update_6100 | Update function for Nodeorder-6.x-1.* Original nodeorder schema used an unsigned field for the weight. With the new ordering from core this should be changed to a signed field. We therefore take the following measures: |