taxonomy_defaults.install in Taxonomy Defaults 7
Same filename and directory in other branches
Install, update and uninstall functions for the taxonomy_defaults module.
File
taxonomy_defaults.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the taxonomy_defaults module.
*/
/**
* Hook sets taxonomy_defaults 'weight' so that it runs after taxonomy
*
*/
function taxonomy_defaults_install() {
$ret = array();
$weight = 0;
$query = "SELECT weight FROM {system} WHERE type = 'module' AND status = 1 and name = 'taxonomy'";
$result = db_query("SELECT weight FROM {system} WHERE type = :type AND status = :status and name = :name", array(
':type' => 'module',
':status' => 1,
':name' => 'taxonomy',
));
if ($row = db_fetch_object($result)) {
$weight = $row->weight;
}
$weight = $weight + 1;
// TODO Please convert this statement to the D7 database API syntax.
$ret[] = db_query("UPDATE {system} SET weight = " . $weight . " WHERE name = 'taxonomy_defaults'");
return $ret;
}
/**
* Implements hook_uninstall().
*
*/
function taxonomy_defaults_uninstall() {
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("DELETE FROM {variable} WHERE name LIKE 'taxdef_%'") */
db_delete('variable')
->condition('name', 'taxdef_%', 'LIKE')
->execute();
}
/**
* Implements hook_requirements().
*
*/
function taxonomy_defaults_requirements($phase) {
$requirements = array();
$tax_weight = 0;
$weight = 0;
$query = "SELECT weight FROM {system} WHERE type = 'module' AND status = 1 and name = 'taxonomy'";
$result = db_query("SELECT weight FROM {system} WHERE type = :type AND status = :status and name = :name", array(
':type' => 'module',
':status' => 1,
':name' => 'taxonomy',
));
if ($row = db_fetch_object($result)) {
$tax_weight = $row->weight;
}
$query = "SELECT weight FROM {system} WHERE type = 'module' AND status = 1 and name = 'taxonomy_defaults'";
$result = db_query("SELECT weight FROM {system} WHERE type = :type AND status = :status and name = :name", array(
':type' => 'module',
':status' => 1,
':name' => 'taxonomy_defaults',
));
if ($row = db_fetch_object($result)) {
$weight = $row->weight;
if ($tax_weight >= $weight) {
$requirements['taxdef'] = array(
'title' => t('Taxonomy Defaults'),
'value' => t('Invalid Module Weight'),
'severity' => REQUIREMENT_ERROR,
'description' => t("The Taxonomy Defaults module's weight is lower than the Taxonomy module's, so taxonomy default settings will be ignored. !link to learn more about module weights, or reinstall the Taxonomy Defaults module.", array(
'!link' => l('Go here', 'http://drupal.org/node/110238'),
)),
);
}
}
return $requirements;
}
/**
* Update taxonomy defaults weighting.
* Previous versions of taxonomy defaults had to run BEFORE taxonomy, but now it must run AFTER taxonomy
*/
function taxonomy_defaults_update_6101() {
$ret = array();
$weight = 0;
$query = "SELECT weight FROM {system} WHERE type = 'module' AND status = 1 and name = 'taxonomy'";
$result = db_query("SELECT weight FROM {system} WHERE type = :type AND status = :status and name = :name", array(
':type' => 'module',
':status' => 1,
':name' => 'taxonomy',
));
if ($row = db_fetch_object($result)) {
$weight = $row->weight;
}
$weight = $weight + 1;
// TODO Please convert this statement to the D7 database API syntax.
db_query("UPDATE {system} SET weight = " . $weight . " WHERE name = 'taxonomy_defaults'");
// hook_update_N() no longer returns a $ret array. Instead, return
// nothing or a translated string indicating the update ran successfully.
// See http://drupal.org/node/224333#update_sql.
return t('TODO Add a descriptive string here to show in the UI.');
}
/**
* Update taxonomy defaults settings.
*
* Delete orphaned settings due to deleted vocabularies & content types, as well as deprecated settings,
* and initialize the new "visible" setting
*/
function taxonomy_defaults_update_6102() {
$ret = array();
$valid_settings = array();
//loop through every combo of content types and vocabularies
foreach (node_type_get_types() as $type => $name) {
foreach (taxonomy_get_vocabularies() as $vid => $vocab) {
// only store settings for vocabs previously marked active for this content type
if (variable_get("taxdef_{$type}_{$vid}_active", FALSE)) {
$valid_settings["taxdef_{$type}_{$vid}"] = variable_get("taxdef_{$type}_{$vid}", array());
if (!array_key_exists($vid, taxonomy_get_vocabularies($type))) {
// this appears to be a "hidden" vocabulary, so turn off visibility
$valid_settings["taxdef_{$type}_{$vid}_visible"] = FALSE;
}
else {
// otherwise, leave visibility on
$valid_settings["taxdef_{$type}_{$vid}_visible"] = TRUE;
}
}
}
}
// delete ALL taxonomy default settings
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("DELETE FROM {variable} WHERE name LIKE 'taxdef_%'") */
db_delete('variable')
->condition('name', 'taxdef_%', 'LIKE')
->execute();
foreach ($valid_settings as $setting => $value) {
variable_set($setting, $value);
}
// hook_update_N() no longer returns a $ret array. Instead, return
// nothing or a translated string indicating the update ran successfully.
// See http://drupal.org/node/224333#update_sql.
return t('TODO Add a descriptive string here to show in the UI.');
}
Functions
Name![]() |
Description |
---|---|
taxonomy_defaults_install | Hook sets taxonomy_defaults 'weight' so that it runs after taxonomy |
taxonomy_defaults_requirements | Implements hook_requirements(). |
taxonomy_defaults_uninstall | Implements hook_uninstall(). |
taxonomy_defaults_update_6101 | Update taxonomy defaults weighting. Previous versions of taxonomy defaults had to run BEFORE taxonomy, but now it must run AFTER taxonomy |
taxonomy_defaults_update_6102 | Update taxonomy defaults settings. |