$vid = install_taxonomy_get_vid('Forums');
  install_taxonomy_add_term($vid, 'Types of Birds', 'Discussions grouped by bird classifications.');
  $container = install_taxonomy_get_tid('Types of Birds');
  variable_set('forum_containers', array($container));
  // Now add the forums.
  install_taxonomy_add_term($vid, 'Raptors', 'Birds of prey.', array('parent' => $container));
  install_taxonomy_add_term($vid, 'Water birds', 'Birds that live on or near the water.', array('parent' => $container));

For whatever reason, $vid gets set to 0 somewhere in taxonomy_term_save(), and things don't show up under the container like they should. I spent some time in a debugger on this and am mystified. I suspect this line from install_taxonomy_add_term():

  $term = array_unique(array_merge($defaults, $properties));

But wasn't able to spot where it's getting screwed up.

CommentFileSizeAuthor
#1 install_profile_api_subterms.patch598 bytesquicksketch

Comments

quicksketch’s picture

Status: Active » Needs review
StatusFileSize
new598 bytes

I thinks this officially qualifies as a "dumb" bug. :P

You're totally right, the problem was in that line. The call to array_unique() is completely unnecessary. Here's what was happening:

Before the array_unique() call:

Array (
    [name] => Water birds
    [description] => Birds that live on or near the water.
    [parent] => 1
    [relations] => Array ( )
    [weight] => 0
    [vid] => 1
)

After the array_unique() call:

Array (
    [name] => Water birds
    [description] => Birds that live on or near the water.
    [parent] => 1
    [relations] => Array ()
    [weight] => 0
)

array_unique compares the values of the arrays and removes any duplicates. Since the "vid" and "parent" values were both equal to "1", the vid value was being dropped. The same problem would occur if vid were set the same as weight (or other keys). Simply removing the array_unique() fixes the problem. I can't think of any reason for it's existence, since the keys are already unique.

quicksketch’s picture

Status: Needs review » Fixed

I've committed the above patch.

quicksketch’s picture

I found this same problem exists for install_add_vocabulary(). However, since most of the database columns set reasonable defaults for vocabularies, this problem was less noticeable. I've remove dthe array_unique() from this function also.

I've backported these changes to the 5--2 branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.