You are here

function fe_taxonomy_vocabulary_features_revert in Features Extra 6

Implementation of hook_features_revert().

File

./fe_taxonomy.module, line 147

Code

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

  // Revert.
  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);
      }
    }
    else {
      $object->vid = $vid;
      $result = _fe_taxonomy_save_vocabulary((array) $object);
    }
  }
  return TRUE;
}