You are here

function tvi_update_7001 in Taxonomy Views Integrator 7

Replace vids by machine_names and tids by uuids if enabled.

File

./tvi.install, line 54
Install, update, and uninstall functions for the tvi module.

Code

function tvi_update_7001(&$sandbox) {
  $settings = db_select('tvi_settings', 'tvi')
    ->fields('tvi')
    ->condition('tvi.type', TVI_TYPE_VOCAB)
    ->execute()
    ->fetchAll();
  foreach ($settings as $setting) {
    $voc = taxonomy_vocabulary_load($setting->xid);

    // Check if the vocabulary still exists.
    if ($voc !== FALSE && !empty($voc->machine_name)) {
      db_update('tvi_settings')
        ->fields(array(
        'xid' => $voc->machine_name,
      ))
        ->condition('type', $setting->type)
        ->condition('xid', $setting->xid)
        ->execute();
    }
  }
  if (module_exists('uuid')) {
    $settings = db_select('tvi_settings', 'tvi')
      ->fields('tvi')
      ->condition('tvi.type', TVI_TYPE_TERM)
      ->execute()
      ->fetchAll();
    foreach ($settings as $setting) {
      $term = taxonomy_term_load($setting->xid);

      // Check if the term still exists and its uuid is defined.
      if ($term !== FALSE && !empty($term->uuid)) {
        db_update('tvi_settings')
          ->fields(array(
          'xid' => $term->uuid,
        ))
          ->condition('type', $setting->type)
          ->condition('xid', $setting->xid)
          ->execute();
      }
    }
  }
}