After installing Taxonomy Manager, my client managed to create a cycle in the term hierarchy for his vocabulary that caused another module to go into an infinite loop whenever displaying a page that also displayed all the terms from that vocabulary (when adding a new node, for example). The Taxonomy module and all modules that depended on it needed to be temporarily disabled to regain control of our site.

Taxonomy Manager needs to detect when an operation will create a cycle in the hierarchy graph and prevent it from occurring. (Other modules that walk taxonomy hierarchy graphs may need to detect this condition as well, but I will postpone posting to those queues until I have a solution for this.)

I am working right now on a short stand-alone Perl program that can connect to the database and detect this condition for our particular site. Once I'm satisfied that it's working, I can convert it to PHP and integrate it into the module.

Comments

mh86’s picture

Hi!

Since the D6 version of the Taxonomy Manager, a cycle detection is integrated.
See function taxonomy_manager_check_circular_hierarchy in taxonomy_manager.admin.inc

You can easily backport this by copying the function to your D5 version and by adding the validations.

lsiden’s picture

Thanks. Where can I find the definition for taxonomy_manager_form_add_validate() for v2.2?

$ grep -R add_validate *
taxonomy_manager.admin.inc: '#validate' => array('taxonomy_manager_form_add_validate'),

mh86’s picture

you can take a look at taxonomy_manager_form_move_validate:

...
  // values from autocomplete
  $parents = array();
  foreach ($typed_parents as $parent_info) {
    $parents[(int) $parent_info['tid']] = (int) $parent_info['tid'];
  }

  // selected_tids = selected terms in tree
  if (!taxonomy_manager_check_circular_hierarchy($selected_tids, $parents)) {
    form_set_error('move', t('Invalid selection. The resulting hierarchy would contain circles, which is not allowed. A term cannot be a parent of itself.')); 
    $form_state['rebuild'] = TRUE;
  }
lsiden’s picture

I saw the definition for ..._move_validate(), but the form array-hash also references 'taxonomy_manager_form_add_validate()', yet I can't find a definition for ..._add_validate().

$ grep -R _add_validate *
taxonomy_manager.admin.inc: '#validate' => array('taxonomy_manager_form_add_validate'),

What happens when ..._add_validate() gets called? Where does the call go?

mh86’s picture

_add_validate() has no validation for cycles, because this function only adds new terms (optional assigns them to parents) and I see no possibility of creating cycles with new terms

mh86’s picture

ah, taxonomy_manager_form_add_validate is missing. now I get it. There is no need for extra validation when adding new terms, but this #validate entry shouldn't exist at all

lsiden’s picture

But where is _add_validate() ___DEFINED___???

mh86’s picture

Although it is defined in the form array, the function for _add_validate doesn't exist. The form API doesn't throw an error, but the definition in the form array shouldn't be there.

lsiden’s picture

Then it might be a good idea to delete "_add_validate" in the form-array in upcoming releases to avoid confusion.

Thank you for getting back to me.

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)