You are here

function quotes_update_7001 in Quotes 7

Update taxonomy or add a default vocabulary for quotes.

File

./quotes.install, line 306
Handles installation and updates for the quotes module.

Code

function quotes_update_7001() {

  // Get only the quotes module vocabulary.
  $vid = db_query('SELECT * FROM {taxonomy_vocabulary} WHERE name = :name', array(
    ':name' => 'quotes',
  ))
    ->fetchObject();
  if ($vid) {

    // Change our vocabulary machine name.
    db_update('taxonomy_vocabulary')
      ->fields(array(
      'machine_name' => 'quotes',
    ))
      ->condition('vid', $vid->vid)
      ->execute();

    // Get our vocabulary by our new machine_name.
    $vocabulary = taxonomy_vocabulary_machine_name_load('quotes');

    // Install our taxonomy fields under new vocabulary machine_name
    _quotes_taxonomy_fields();

    // Now run the remaining taxonomy updates.
    // First copy our old machine_name field data to the new machine_name.
    $instance = "taxonomy_{$vid->machine_name}";
    _quotes_update_taxonomy($instance);

    // Delete the field
    field_delete_field($instance);

    // Now take care of taxonomyextra.
    _quotes_update_taxonomy('taxonomyextra');
    return t('Quotes taxonomy has been updated.');
  }
  else {

    // If there isn't a vocabulary set up the default.
    _quotes_taxonomy_fields();
    return t('The default vocabulary "Quotes" has been added. You may now setup category terms to categorize quotes');
  }
}