diff --git a/commands/runserver/runserver-drupal.inc b/commands/runserver/runserver-drupal.inc index 7a05b83f98..c9ce313ac1 100644 --- a/commands/runserver/runserver-drupal.inc +++ b/commands/runserver/runserver-drupal.inc @@ -12,7 +12,7 @@ class DrupalServer extends HTTPServer { // We pass in variables, rather than querying options here, to allow this to // potentially be used in other commands. - public $site, $path, $conf_inject, $user, $debug, $first_request_complete; + public $path, $debug, $env, $site; /** * This is the equivalent of .htaccess, passing requests to files if they @@ -51,7 +51,6 @@ class DrupalServer extends HTTPServer { * Override get started event. */ function listening() { - drush_print(dt('HTTP server listening on !addr, port !port (see http://!hostname:!port/), serving site !site...', array('!addr' => $this->addr, '!hostname' => $this->hostname, '!port' => $this->port, '!site' => $this->site))); if (!empty($this->path)) { drush_start_browser($this->path); } diff --git a/commands/runserver/runserver-prepend.php b/commands/runserver/runserver-prepend.php index ce4d696f4a..fbac5273e5 100644 --- a/commands/runserver/runserver-prepend.php +++ b/commands/runserver/runserver-prepend.php @@ -5,6 +5,17 @@ // site in a multisite configuration (e.g. http://mysite.com/...). $base_url = runserver_env('RUNSERVER_BASE_URL'); +// Complete $_GET['q'] for Drupal 6 with built in server +// - this uses the Drupal 7 method. +if (!isset($_GET['q']) && isset($_SERVER['REQUEST_URI'])) { + // This request is either a clean URL, or 'index.php', or nonsense. + // Extract the path from REQUEST_URI. + $request_path = strtok($_SERVER['REQUEST_URI'], '?'); + $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')); + // Unescape and strip $base_path prefix, leaving q without a leading slash. + $_GET['q'] = substr(urldecode($request_path), $base_path_len + 1); +} + // We hijack filter_init (which core filter module does not implement) as // a convenient place to affect early changes. if (!function_exists('filter_init')) { @@ -16,18 +27,24 @@ function filter_init() { $conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF'))); // Merge in the injected conf, overriding existing items. $conf = array_merge($conf, $conf_inject); - $uid = runserver_env('RUNSERVER_USER'); - if (isset($_GET['login']) && $user->uid == 0 && !empty($uid)) { - // If a user was provided, log in as this user. - $user = user_load($uid); - if (function_exists('drupal_session_regenerate')) { - // Drupal 7 - drupal_session_regenerate(); - } - else { - // Drupal 6 - sess_regenerate(); + + // Log in user if needed. + if (isset($_GET['login'])) { + $uid = runserver_env('RUNSERVER_USER'); + if (!empty($uid) && $user->uid !== $uid) { + // If a user was provided, log in as this user. + $user = user_load($uid); + if (function_exists('drupal_session_regenerate')) { + // Drupal 7 + drupal_session_regenerate(); + } + else { + // Drupal 6 + sess_regenerate(); + } } + // Refresh the page (in case access denied has been called already). + drupal_goto($_GET['q']); } } } diff --git a/commands/runserver/runserver.drush.inc b/commands/runserver/runserver.drush.inc index 99f47dd671..a4f816e578 100644 --- a/commands/runserver/runserver.drush.inc +++ b/commands/runserver/runserver.drush.inc @@ -104,6 +104,20 @@ function drush_core_runserver_validate() { return drush_set_error('RUNSERVER_PHP_CGI', dt('The runserver command with the "builtin" server requires php 5.4 (or higher), which could not be found.')); } + if ($server == 'cgi') { + // Fetch httpserver cgi based server to our /lib directory, if needed. + $lib = drush_get_option('lib', DRUSH_BASE_PATH . '/lib'); + $httpserverfile = $lib . '/' . DRUSH_HTTPSERVER_DIR_BASE . substr(DRUSH_HTTPSERVER_VERSION, 0, 7) . '/httpserver.php'; + if (!drush_file_not_empty($httpserverfile)) { + // Download and extract httpserver, and confirm success. + drush_lib_fetch(DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION); + if (!drush_file_not_empty($httpserverfile)) { + // Something went wrong - the library is still not present. + return drush_set_error('RUNSERVER_HTTPSERVER_LIB_NOT_FOUND', dt("The runserver command needs a copy of the httpserver library in order to function, and the attempt to download this file automatically failed. To continue you will need to download the package from !url, extract it into the !lib directory, such that httpserver.php exists at !httpserverfile.", array('!version' => DRUSH_HTTPSERVER_VERSION, '!url' => DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION, '!httpserverfile' => $httpserverfile, '!lib' => $lib))); + } + } + } + // Check we have a valid server. if (!in_array(drush_get_option('server', FALSE), array('cgi', 'builtin'))) { return drush_set_error('RUNSERVER_INVALID', dt('Invalid server specified.')); @@ -183,10 +197,13 @@ function drush_core_runserver($uri = NULL) { // We pass in the specified user ID (if set). This will automatically log // this user in the browser during the first request (but not subsequent // requests, to allow logging out). + $user_message = ''; if ($user->uid) { $env['RUNSERVER_USER'] = $user->uid; + $user_message = ', logged in as ' . $user->name; } + drush_print(dt('HTTP server listening on !addr, port !port (see http://!hostname:!port!path), serving site !site!user...', array('!addr' => $addr, '!hostname' => $hostname, '!port' => $uri['port'], '!path' => $uri['path'], '!site' => drush_get_context('DRUSH_DRUPAL_SITE', 'default'), '!user' => $user_message))); if (drush_get_option('server', FALSE) == 'builtin') { // Start php 5.4 builtin server. // Store data used by runserver-prepend.php in the shell environment. @@ -202,19 +219,9 @@ function drush_core_runserver($uri = NULL) { drush_shell_exec_interactive($php . ' -S ' . $addr . ':' . $uri['port'] . ' --define auto_prepend_file="' . DRUSH_BASE_PATH . '/commands/runserver/runserver-prepend.php"'); } else { - // Fetch httpserver cgi based server to our /lib directory, if needed. + // Include the library and our class that extends it. $lib = drush_get_option('lib', DRUSH_BASE_PATH . '/lib'); $httpserverfile = $lib . '/' . DRUSH_HTTPSERVER_DIR_BASE . substr(DRUSH_HTTPSERVER_VERSION, 0, 7) . '/httpserver.php'; - if (!drush_file_not_empty($httpserverfile)) { - // Download and extract httpserver, and confirm success. - drush_lib_fetch(DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION); - if (!drush_file_not_empty($httpserverfile)) { - // Something went wrong - the library is still not present. - return drush_set_error('RUNSERVER_HTTPSERVER_LIB_NOT_FOUND', dt("The runserver command needs a copy of the httpserver library in order to function, and the attempt to download this file automatically failed. To continue you will need to download the package from !url, extract it into the !lib directory, such that httpserver.php exists at !httpserverfile.", array('!version' => DRUSH_HTTPSERVER_VERSION, '!url' => DRUSH_HTTPSERVER_BASE_URL . DRUSH_HTTPSERVER_VERSION, '!httpserverfile' => $httpserverfile, '!lib' => $lib))); - } - } - - // Include the library and our class that extends it. require_once $httpserverfile; require_once 'runserver-drupal.inc'; // Create a new httpserver instance and start it running.