diff -u b/core/includes/batch.inc b/core/includes/batch.inc --- b/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -52,9 +52,6 @@ // Retrieve the current state of the batch. if (!$batch) { $batch = batch_load($_REQUEST['id']); - debug($_REQUEST); - debug(drupal_get_token($_REQUEST['id'])); - debug(db_query("SELECT token FROM {batch} WHERE bid = :bid", array(':bid' => $_REQUEST['id']))->fetchField()); if (!$batch) { drupal_set_message(t('No active batch.'), 'error'); drupal_goto(); @@ -457,8 +454,6 @@ */ function _batch_finished() { $batch = &batch_get(); - debug($batch); - error_log(var_export($batch, TRUE)); // Execute the 'finished' callbacks for each batch set, if defined. foreach ($batch['sets'] as $batch_set) { diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2575,9 +2575,12 @@ * Returns TRUE if a Drupal installation is currently being attempted. */ function drupal_installation_attempted() { - return isset($GLOBALS['install_state']); - // @todo Entirely incompatible with non-interactive installer invoked from SimpleTest. - return defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install'; + // This cannot rely on the MAINTENANCE_MODE constant, since that would prevent + // tests from using the non-interactive installer, in which case Drupal is + // only happens to be installed within the same request, but subsequently + // executed code does not involve the installer at all. + // @see install_drupal() + return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']); } /** diff -u b/core/includes/install.core.inc b/core/includes/install.core.inc --- b/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -94,19 +94,27 @@ throw $e; } } + // After execution, all tasks might be complete, in which case + // $install_state['installation_finished'] is TRUE. In case the last task + // has been processed, remove the global $install_state, so other code can + // reliably check whether it is running during the installer. + // @see drupal_installation_attempted() + $state = $install_state; + unset($install_state); + // All available tasks for this page request are now complete. Interactive // installations can send output to the browser or redirect the user to the // next page. - if ($install_state['interactive']) { - if ($install_state['parameters_changed']) { + if ($state['interactive']) { + if ($state['parameters_changed']) { // Redirect to the correct page if the URL parameters have changed. - install_goto(install_redirect_url($install_state)); + install_goto(install_redirect_url($state)); } elseif (isset($output)) { // Display a page only if some output is available. Otherwise it is // possible that we are printing a JSON page and theme output should // not be shown. - install_display_output($output, $install_state); + install_display_output($output, $state); } } } @@ -460,23 +468,6 @@ } elseif ($task['type'] == 'batch') { - if (0 && !$install_state['interactive']) { - $batch = $function($install_state); - if (!empty($batch['operations'])) { - // Build a dummy 'context' array to avoid exceptions. - $batch_context = array( - 'sandbox' => &$current_set['sandbox'], - 'results' => &$current_set['results'], - 'finished' => &$finished, - 'message' => &$task_message, - ); - foreach ($batch['operations'] as $operation) { - list($function, $args) = $operation; - call_user_func_array($function, array_merge($args, array(&$batch_context))); - } - } - return; - } // Start a new batch based on the task function, if one is not running // already. $current_batch = variable_get('install_current_batch'); reverted: --- b/core/includes/install.inc +++ a/core/includes/install.inc @@ -93,10 +93,10 @@ * @see install_profile_info() */ function drupal_install_profile_distribution_name() { - global $install_state; // During installation, the profile information is stored in the global // installation state (it might not be saved anywhere yet). + if (drupal_installation_attempted()) { + global $install_state; - if (isset($install_state['profile_info']['distribution_name'])) { return $install_state['profile_info']['distribution_name']; } // At all other times, we load the profile via standard methods. diff -u b/core/includes/session.inc b/core/includes/session.inc --- b/core/includes/session.inc +++ b/core/includes/session.inc @@ -349,7 +349,7 @@ function drupal_session_regenerate() { global $user, $is_https; - // Nothing to do if we are not allowed to save the session. + // Nothing to do if we are not allowed to change the session. if (!drupal_save_session()) { return; } @@ -423,7 +423,7 @@ function _drupal_session_destroy($sid) { global $user, $is_https; - // Nothing to do if we are not allowed to save the session. + // Nothing to do if we are not allowed to change the session. if (!drupal_save_session()) { return; } @@ -475,7 +475,7 @@ * User ID. */ function drupal_session_destroy_uid($uid) { - // Nothing to do if we are not allowed to save the session. + // Nothing to do if we are not allowed to change the session. if (!drupal_save_session()) { return; } @@ -522,6 +522,9 @@ * FALSE if writing session data has been disabled. Otherwise, TRUE. */ function drupal_save_session($status = NULL) { + // PHP session ID, session, and cookie handling happens in the global scope. + // This value has to persist across calls to drupal_static_reset(), since a + // potentially wrong or disallowed session would be written otherwise. static $save_session = TRUE; if (isset($status)) { $save_session = $status; diff -u b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -637,10 +637,6 @@ $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files'); $this->originalProfile = drupal_get_profile(); $this->originalUser = clone $user; -// $this->originalSessionID = session_id(); -// $this->originalSession = isset($_SESSION) ? $_SESSION : NULL; -// $this->originalCookies = $_COOKIE; -// $this->originalGlobals = $GLOBALS; // Save and clean the shutdown callbacks array because it is static cached // and will be changed by the test run. Otherwise it will contain callbacks @@ -710,6 +706,7 @@ // Restore original database connection. Database::removeConnection('default'); Database::renameConnection('simpletest_original_default', 'default'); + // @see TestBase::changeDatabasePrefix() global $databases; $connection_info = Database::getConnectionInfo('default'); $databases['default']['default'] = $connection_info['default']; @@ -735,10 +732,6 @@ // Restore original user session. $user = $this->originalUser; -// session_id($this->originalSessionID); -// $_SESSION = $this->originalSession; -// $_COOKIE = $this->originalCookies; -// $GLOBALS = $this->originalGlobals; drupal_save_session(TRUE); } diff -u b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -588,10 +588,6 @@ // Backup the currently running Simpletest batch. $this->originalBatch = batch_get(); -// if (!empty($this->originalBatch['id'])) { -// $this->originalToken = drupal_get_token($this->originalBatch['id']); -// } - // Create the database prefix for this test. $this->prepareDatabasePrefix(); @@ -657,49 +653,30 @@ ), ); -// $parent_session = $_SESSION; -// $parent_get = $_GET; - // Reset it and invoke the non-interactive installer. + // Reset the batch and invoke the non-interactive installer. $batch = &batch_get(); $batch = array(); - // @todo The above has been replaced with changing install_run_task() in - // install.core.inc to not invoke the Batch API at all for install tasks - // of type 'batch'. - - // @todo _batch_page() calls into batch_load() to reload the batch definition, - // but that uses drupal_get_token() to validate that the batch belongs to - // the current user. drupal_get_token() returns a different value after - // test execution, so the batch finished page does not load. -// $session_id = session_id(); - -// $originalSession = isset($_SESSION) ? $_SESSION : NULL; -// $originalGlobals = $GLOBALS; -// $request = request(); + // Ensure that the session is not changed by the new environment. + drupal_save_session(FALSE); + + // Replace the global $user session with an anonymous user to resemble a + // regular installation. + $user = drupal_anonymous_user(); + + // The installer sets/overrides some services to Null implementations, since + // there is no database yet. Thus, backup and restore the current $conf. $originalConf = $conf; - $user = drupal_anonymous_user(); - drupal_save_session(FALSE); + // Execute the non-interactive installer. install_drupal($settings); -// session_id($session_id); - -// $_SESSION = $originalSession; -// $GLOBALS = $originalGlobals; -// request($request); + // Restore global $conf from before install_begin_request(). $conf = $originalConf; // Restore the original Simpletest batch. $batch = &batch_get(); $batch = $this->originalBatch; -// $_SESSION = $parent_session; -// $_GET = $parent_get; - // @todo Simpletest batch finishes, but redirects to /batch (which in turn - // redirects to the front page, along with the message "No active batch." - // -- something in the Drupal installer code seems to reset/erase the - // Simpletest batch's ID or final redirection target. -// $this->verbose(var_export($batch, TRUE)); - // Set path variables. variable_set('file_public_path', $this->public_files_directory); @@ -724,14 +701,6 @@ $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); } - // Reset/rebuild all data structures after enabling the modules. - $this->resetAll(); - - // Ensure that the session is not written to the new environment and replace - // the global $user session with uid 1 from the new test site. - // Login as uid 1. - $user = user_load(1); - // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'Drupal\Core\Mail\VariableLog')); @@ -814,16 +783,6 @@ // Close the CURL handler. $this->curlClose(); - - // Regenerate batch token after install_drupal() created a new session_id. - if (0 && !empty($this->originalBatch)) { - db_update('batch') - ->fields(array( - 'token' => drupal_get_token($this->originalBatch['id']), - )) - ->condition('token', $this->originalToken) - ->execute(); - } } /**