Drupal goto breaks drush

Posted by: 
Dominique De Cooman

Sometimes there is a need to make drupal redirect using drupal_goto. We had to do it in an SSO scenario. We had to make drupal goto a configurable admin page (node page) when no roles where assigned to you by the external authentication (shibboleth). So we would put a check in hook_init() to redirect drupal when our criteria where met.

This breaks drush. But, there is a solution. You can detect by who php is called using php_sapi_name(). When it is your webserver it will output:'apache2handler', when it is drush it will output 'cli'. In following snippet we check if drush is using php. You also see a check to check on which pages not to redirect, $path could be mapped to admin settings or hardcoded.

[] = $redirect;
$result db_result(db_query("SELECT uid FROM {extranet_role_assignment} WHERE uid = %d LIMIT 1"$user->uid));
if (!
$result && 
user_access('administer era settings') && 
in_array($_GET['q'], $paths) && 
php_sapi_name() != 'cli') {    

Add new comment

Who are you?

By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.