I'm trying to reset some path aliases in hook_update_N by doing the following:
// 3. Adjust the url of all Blog entries from /blogs/posts/[title] -> /news-blogs/[blog-name]/[title]
// Set up 3001 redirects for these URL changes in Path Redirect (these can not be handled in NginX)
$nodes = db_query("SELECT nid FROM {node} WHERE type = 'blog'");
while ($node = db_fetch_object($nodes)) {
$n = node_load(array('nid' => $node->nid));
$n->pathauto_perform_alias = TRUE;
node_save($n);
}
However, my pathauto value is stored in code (as part of a Feature) and loaded/controlled by Strongarm. I'm finding that at the point where this runs (in hook_update_N), it's not picking up the pathauto value for this nodetype, and resetting the URL aliases to /content/[title-raw] (the default one) instead of the one defined in my Feature with Strongarm.
From #798700: Strongarm drops entries in database ? help: Strongarm provides an alternative place (code) to store a variables value, so that a variable can have a value without and entry in the `variable` database table. If you use Drupal's variable API (`variable_set()`, `variable_get()` and `variabl_del()`) this will all just work. If you're accessing that database table directly, you would have issues.
I doubt if pathauto is accessing the variable table directly, and as far as I can tell it uses variable_get() to pull the node path settings. It seems like strongarm is not running in hook_update_N when called from `drush updatedb`? Can you confirm if this is the case? And, if so how can I ensure that it does run?
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | get_full_bootstrap_with_drush-808654.patch | 403 bytes | chrisns |
Comments
Comment #1
yhahn commentedI believe the issue is that
hook_init()is not invoked during the Drupal bootstrap used inupdate.php, seecommon.inc:Strongarm does its magic in
hook_init()so withouthook_init()being called there's no way it can set its values.You may want to try the following in your update hook prior to running code that expects to use Strongarmed values, but generally speaking you probably would be better off with standalone code in your update hooks:
Hope this helps.
Comment #3
hefox commentedHere's a generalized solution for drush only, works via the fact drush does user_load on user 1. for update.
Comment #4
chrisns commentedSo the problem here is that that the core drush commands don't set the updatedb batch process to get a full bootstrap.
Heres a patch for strongarm that obtains a full bootstrap before running hook_updates
Might slow down updates, but will give you access to strongarm stuff
Comment #5
hefox commentedChrisn, when you update a issue, see if it's closed :P
Comment #6
chrisns commented@hefox, missed that, thanks!
Comment #7
febbraro commentedFYI #1094598: Performance issues from strongarm_init() should fix this when it is committed.