You are here

function fe_taxonomy_vocabulary_features_rebuild in Features Extra 6

Implementation of hook_features_rebuild().

File

./fe_taxonomy.module, line 118

Code

function fe_taxonomy_vocabulary_features_rebuild($module_name = NULL) {
  $table = 'fe_taxonomy_vocabulary';
  $defaults = features_get_default($table, $module_name);
  if (empty($defaults)) {
    return;
  }

  // Rebuild.
  foreach ($defaults as $object) {
    if (empty($object->machine_name)) {
      continue;
    }
    $vid = db_result(db_query("SELECT vid FROM {{$table}} WHERE machine_name = '%s'", $object->machine_name));
    if (empty($vid) || !($vocab = taxonomy_vocabulary_load($vid))) {
      $result = _fe_taxonomy_save_vocabulary((array) $object);
      if (!empty($result['vid'])) {
        db_query("DELETE FROM {{$table}} WHERE vid = %d OR machine_name = '%s'", $result['vid'], $object->machine_name);
        db_query("INSERT INTO {{$table}} (vid, machine_name) VALUES (%d, '%s')", $result['vid'], $object->machine_name);
      }
    }
  }
  return TRUE;
}