As described at http://sachachua.com/wp/2009/03/19/drupal-gotcha-watch-out-for-user-duri..., you really should be uid #1 or similarly priveleged account when running update.php. Consider that node_delete() does an access check internally (for example).

I'd like to add code like below to each update_main() function, after the full bootstrap. Any objections?


  // Updates only run reliably if user ID #1 is logged in. For example, node_delete() requires elevated perms in D6.
  if (!drush_get_context('DRUSH_USER')) {
    drush_set_context('DRUSH_USER', 1);
    _drush_bootstrap_drupal_login();
  }

Comments

adrian’s picture

that's cool. i never picked up any problems in the code i updated, because i always thought that it would just be like running with access_check disabled.

adrian’s picture

btw. i think the correct way to handle this is :


drush_set_option('user', 1);
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN)

instead of setting the context by hand

moshe weitzman’s picture

Status: Active » Fixed

Committed to all 3 branches using adrian's suggestion.

Status: Fixed » Closed (fixed)

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

moshe weitzman’s picture

For posterity - the above technique works great IFF you add a 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL (or less) in your command definition. Without that, drush logs in as uid=0 during its bootstrap and the bootstrap call in the command callback does nothing.