Order of items in hook_update_n()
Recently I was writing an update for a site that required that Domain Taxonomy module be installed on the site and all current forums be published in site's default language and to all domains. I was also decided that Forum vocabulary should be with per term languages (yes, that makes forums per language and per domain).
Normally one would write the updates in the following order:
- check if Domain Taxonomy is enabled, if not enable it
- configure Domain Taxonomy
- configure Forum vocabulary
- find all terms and associated nodes in the forum vocabulary and set term language and publish terms and nodes to all affiliates.
The logical thing to do is to write something like this for step 4:
$forums_vid = variable_get('forum_nav_vocabulary', '');
$tree = taxonomy_get_tree($forums_vid);
However when you are running your update you will soon discover that $tree at this point is an empty array. The first thing you will attempt is flushing static cache in taxonomy_get_tree() which won't do you any good. Domain Taxonomy module implements hook_db_rewrite_sql() for terms, it does not however add grants on install. To sum it up - before installing Domain Taxonomy you have forums on ALL domains, after installing it you have them on NONE.
The solution? Fetch vocabulary hierarchy before installing Domain Taxonomy and you are golden. Of course you could write your own sql queries or could add all the grants yourself but I preferred to rely on domain_taxonomy_save_term() for that instead. Or even better open an issue requesting grants to be set on install the same way Domain Blocks does it.