Drupal, drush and the –user setting being ignored

Posted up to help others…

When using the Drush it is possible to run various commands for Drupal from the command line.  This is a brilliant way of being able to script admin tasks etc for Drupal.

However, since the command line is used it is not obvious how to set which Drupal user the commands are run as.  This is important as only certain users can carry out certain functions such as delete nodes etc.

So – we see the command line option –user=1 to set the user to run as – and under ‘drush status’ it shows that the admin user is being used.

I’d built my own module and no matter what I tried the command I was running would not delete a node – it was as if the user being set was being ignored.  Then I found the reason – Drush bootstrap level.

When setting up a Drush command the Drush bootstrap level is set.  I’d set mine to  DRUSH_BOOTSTRAP_DRUPAL_FULL as this seemed to be what I initially wanted – however, I should have set it (or left it) to the default level of DRUSH_BOOTSTRAP_DRUPAL_LOGIN.

The –user option is then honoured!

Share Post :

1 Comment

  • Jason
    3rd August 2012 at 9:45 am 

    ah this really helped me a lot – thanks!

Leave a Reply