You are here

function taxonomy_defaults_update_6102 in Taxonomy Defaults 7

Same name and namespace in other branches
  1. 6.2 taxonomy_defaults.install \taxonomy_defaults_update_6102()
  2. 6 taxonomy_defaults.install \taxonomy_defaults_update_6102()

Update taxonomy defaults settings.

Delete orphaned settings due to deleted vocabularies & content types, as well as deprecated settings, and initialize the new "visible" setting

File

./taxonomy_defaults.install, line 107
Install, update and uninstall functions for the taxonomy_defaults module.

Code

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.');
}