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?

CommentFileSizeAuthor
#4 get_full_bootstrap_with_drush-808654.patch403 byteschrisns

Comments

yhahn’s picture

Status: Active » Fixed

I believe the issue is that hook_init() is not invoked during the Drupal bootstrap used in update.php, see common.inc:

function _drupal_bootstrap_full() {
  ...
  // Let all modules take action before menu system handles the request
  // We do not want this while running update.php.
  if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {
    module_invoke_all('init');
  }
}

Strongarm does its magic in hook_init() so without hook_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:

  if (module_exists('strongarm')) {
    strongarm_set_conf();
  }

Hope this helps.

Status: Fixed » Closed (fixed)

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

hefox’s picture


/**
 * Implementation of hook_user().
 */
function mymodule_user($op, &$edit, &$account, $category = NULL) {
  static $done = FALSE;
  // THIS IS HACKISH
  // Strongarm isn't initlized during maintaince mode. That's potentially an issue.
  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update' && $op == 'load' && $account->uid == 1 && module_exists('strongarm') && empty($done)) {
    strongarm_set_conf();
    $done = 1;
  } 
}

Here's a generalized solution for drush only, works via the fact drush does user_load on user 1. for update.

chrisns’s picture

StatusFileSize
new403 bytes

So 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

hefox’s picture

Status: Closed (fixed) » Needs review

Chrisn, when you update a issue, see if it's closed :P

chrisns’s picture

@hefox, missed that, thanks!

febbraro’s picture

Status: Needs review » Closed (duplicate)

FYI #1094598: Performance issues from strongarm_init() should fix this when it is committed.