I just tried to re-order my term-data and set new parents for the terms. Unfortunately the structure is not updated in frontend. After clearing cache everything is working fine again..

CommentFileSizeAuthor
#8 1901844-1.patch640 bytescharlie-s
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stBorchert’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Active » Needs review

Committed to 7.x-1.x-dev so it should be available in the next development release (>"7.x-1.3+4-dev").

stBorchert’s picture

Status: Needs review » Fixed

Committed and created a new release: 7.x-1.4.

stBorchert’s picture

Status: Fixed » Closed (fixed)
charlie-s’s picture

I'm using 7.x-1.6 and am experiencing this. Is it possible the problem was re-introduced?

thedotwriter’s picture

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

Same here with 7.x-1.6, clearing the cache is needed to get the correct structure.

mariusm’s picture

Please update 7.x-1.6

charlie-s’s picture

I will check into this more and update with a patch if needed. Clients definitely needing terms to instantly appear in these forms in the correct position.

charlie-s’s picture

Status: Active » Needs review
FileSize
640 bytes

I've found the issue.

Ultimately, it lies in taxonomy_get_tree() caching taxonomy trees – https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/f....

When you submit the taxonomy sort form (admin/structure/taxonomy/vocabulary_foo), SHS tried to update it's cache of the vocabulary options. It looks like it's replacing the cache with the result of taxonomy_get_tree(), which, even tho the form's submit handler updated all of the term weights / hierarchy, the terms have already been loaded into memory during this bootstrap cycle and thus their new weight isn't taken into consideration.

Patch unsets this cache via drupal_static_reset('taxonomy_get_tree');. Tested and working for me.

f0ns’s picture

Patch #8 seemed to work at first sight, still had issues. Fixed it by adding this code in a custom module named "shs fix"

<?php

/*
 * implements hook_taxonomy_term_insert
 */
function shs_fix_taxonomy_term_insert($term) {
  _cache_clear($term);
}

/*
 * implements hook_taxonomy_term_update
 */
function shs_fix_taxonomy_term_update($term) {
  _cache_clear($term);
}

/*
 * implements hook_taxonomy_term_delete
 */
function shs_fix_taxonomy_term_delete($term) {
  _cache_clear($term);
}

function _cache_clear($term) {
  //machine names of the vocabularies that use SHS filtering
  $vocabularies = array('veelgestelde_vragen_categorieen');

  if(in_array($term->vocabulary_machine_name, $vocabularies)) {
    // Reset taxonomy_get_tree()'s static cache.
    drupal_static_reset('taxonomy_get_tree');
  }
}

If anyone has a better way to solve this, please feel free to share.

charlie-s’s picture

I was also still running into the issue where re-ordering a 2nd level item never appeared in SHS until a full cache clear. Turns out the cache key that was being set only cared about the first level of items. See this code from ~ line 583:

      // Get term children (only first level).
      $tree = taxonomy_get_tree($vid, $parent, 1);
      foreach ($tree as $term) {
            ...

Because we only have a generic cache key of "shs:[vid]" then trees below level 1 are never cached. I appended the parent ID to the cache like so:

$cache_key = "shs:{$vid}:{$parent}";

and it's working as expected for me now. Can we discuss getting this stuff committed?

4fs’s picture

Hi csdco,
Can you assist a little further. Not 100% sure what to do with the code above. Can you explain further or provide a patch? Am I correct in that $cache_key = "shs:{$vocabulary_cache_key}"; will be replaced by $cache_key = "shs:{$vid}:{$parent}"; (line 774). Is that correct? Thank you.

Tino’s picture

Still running into this problem. Created a module from #9, but after editing a list and moving a child term back to root, the term does not appear when editing a node with this term. Running 7.x-1.6+56-dev.

  • stBorchert committed 3f1f6e7 on 8.x-1.x
    Issue #1901844: updated hierarchy cache after changing order of terms...
  • stBorchert committed 36a71af on 8.x-1.x
    Issue #1901844: fix error after changing order of terms
    
    Signed-off-by:...
stBorchert’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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