I'm trying to build an install profile which adds vocabularies and hierarchical terms to the system and I'm having trouble getting the vocabulary list.

I doesn't seem like there's an easy way to add a term to a named vocabulary so I build an array of terms with a key of parent name. I then use taxonomy_get_vocabularies to get an array of vocabularies which I can loop through adding the relevant terms for each vocabulary.

The problem is that taxonomy_get_vocabularies isn't returning anything. I can't see why although this line (line 643):

db_query(db_rewrite_sql('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid ORDER BY v.weight, v.name', 'v', 'vid'));

adds a WHERE v.vid IS NULL clause to the query which may be a problem. Having said that I'm sure this function works elsewhere in Drupal so I can't believe there's a problem with it.

My code is:

  $terms = array(
	array(
		'name' => 'John Smith',
		'description' => '',
		'vocab' => 'Publisher',
		'parent_terms' => '', // Single parent name term  - can technically be an array but note that the routine that adds the terms below doesn't support this
		'weight' => 0
	)
  );
  $vocabularies = array();
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $vid => $vocabulary) {
    foreach ($terms as $term)
	{
	  if ($term['vocab'] == $vocabulary->name)
	  {
	    $term['vid'] = $vocabulary->vid;
		 if (array_key_exists('parent',$term)) 
		{
			$term_obj = taxonomy_get_term_by_name($term['parent_terms']);
			$term['parent_test'] = $term_obj->name;
		}
	    taxonomy_save_term($term);
	  }
	}
  }

The vocabularies do all get added correctly earlier in the profile.

I've been looking at this for 2 days so I figured maybe it was time to ask for help!

Thank you in advance for any pointers.