From 25a927031c218d7bd49da1bad5f97bef690a7518 Mon Sep 17 00:00:00 2001 From: webchick Date: Fri, 30 Sep 2011 15:08:10 -0700 Subject: Issue #1289364 by swentel: Fixed SchemaCache generates empty cid. --- includes/bootstrap.inc | 2 +- includes/install.core.inc | 22 +++++++++---- includes/install.inc | 63 ++++++++++++++++++++++++++++++++++++- modules/simpletest/tests/cache.test | 12 +++++-- modules/system/system.test | 45 +++++++++++++++++++++++++- update.php | 39 ++++++++++++++++------- 6 files changed, 161 insertions(+), 22 deletions(-) diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 39c1b0852..545beba21 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -2778,7 +2778,7 @@ class SchemaCache extends DrupalCacheArray { public function __construct() { // Cache by request method. - parent::__construct('schema:runtime:' . $_SERVER['REQUEST_METHOD'] == 'GET', 'cache'); + parent::__construct('schema:runtime:' . ($_SERVER['REQUEST_METHOD'] == 'GET'), 'cache'); } protected function resolveCacheMiss($offset) { diff --git a/includes/install.core.inc b/includes/install.core.inc index a74dfdf0f..094c9b871 100644 --- a/includes/install.core.inc +++ b/includes/install.core.inc @@ -710,8 +710,10 @@ function install_display_output($output, $install_state) { * * @return * A themed status report, or an exception if there are requirement errors. - * Otherwise, no output is returned, so that the next task can be run - * in the same page request. + * If there are only requirement warnings, a themed status report is shown + * initially, but the user is allowed to bypass it by providing 'continue=1' + * in the URL. Otherwise, no output is returned, so that the next task can be + * run in the same page request. */ function install_verify_requirements(&$install_state) { // Check the installation requirements for Drupal and this profile. @@ -723,22 +725,30 @@ function install_verify_requirements(&$install_state) { // Check the severity of the requirements reported. $severity = drupal_requirements_severity($requirements); - if ($severity == REQUIREMENT_ERROR) { + // If there are errors, always display them. If there are only warnings, skip + // them if the user has provided a URL parameter acknowledging the warnings + // and indicating a desire to continue anyway. See drupal_requirements_url(). + if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue']))) { if ($install_state['interactive']) { drupal_set_title(st('Requirements problem')); $status_report = theme('status_report', array('requirements' => $requirements)); - $status_report .= st('Check the error messages and proceed with the installation.', array('!url' => check_url(request_uri()))); + $status_report .= st('Check the error messages and proceed with the installation.', array('!url' => check_url(drupal_requirements_url($severity)))); return $status_report; } else { - // Throw an exception showing all unmet requirements. + // Throw an exception showing any unmet requirements. $failures = array(); foreach ($requirements as $requirement) { + // Skip warnings altogether for non-interactive installations; these + // proceed in a single request so there is no good opportunity (and no + // good method) to warn the user anyway. if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { $failures[] = $requirement['title'] . ': ' . $requirement['value'] . "\n\n" . $requirement['description']; } } - throw new Exception(implode("\n\n", $failures)); + if (!empty($failures)) { + throw new Exception(implode("\n\n", $failures)); + } } } } diff --git a/includes/install.inc b/includes/install.inc index 089cdee8f..88a663a4f 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -999,7 +999,6 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { } } - /** * Send the user to a different installer page. * @@ -1016,6 +1015,68 @@ function install_goto($path) { drupal_exit(); } +/** + * Returns the URL of the current script, with modified query parameters. + * + * This function can be called by low-level scripts (such as install.php and + * update.php) and returns the URL of the current script. Existing query + * parameters are preserved by default, but new ones can optionally be merged + * in. + * + * This function is used when the script must maintain certain query parameters + * over multiple page requests in order to work correctly. In such cases (for + * example, update.php, which requires the 'continue=1' parameter to remain in + * the URL throughout the update process if there are any requirement warnings + * that need to be bypassed), using this function to generate the URL for links + * to the next steps of the script ensures that the links will work correctly. + * + * @param $query + * (optional) An array of query parameters to merge in to the existing ones. + * + * @return + * The URL of the current script, with query parameters modified by the + * passed-in $query. The URL is not sanitized, so it still needs to be run + * through check_url() if it will be used as an HTML attribute value. + * + * @see drupal_requirements_url() + */ +function drupal_current_script_url($query = array()) { + $uri = $_SERVER['SCRIPT_NAME']; + $query = array_merge(drupal_get_query_parameters(), $query); + if (!empty($query)) { + $uri .= '?' . drupal_http_build_query($query); + } + return $uri; +} + +/** + * Returns a URL for proceeding to the next page after a requirements problem. + * + * This function can be called by low-level scripts (such as install.php and + * update.php) and returns a URL that can be used to attempt to proceed to the + * next step of the script. + * + * @param $severity + * The severity of the requirements problem, as returned by + * drupal_requirements_severity(). + * + * @return + * A URL for attempting to proceed to the next step of the script. The URL is + * not sanitized, so it still needs to be run through check_url() if it will + * be used as an HTML attribute value. + * + * @see drupal_current_script_url() + */ +function drupal_requirements_url($severity) { + $query = array(); + // If there are no errors, only warnings, append 'continue=1' to the URL so + // the user can bypass this screen on the next page load. + if ($severity == REQUIREMENT_WARNING) { + $query['continue'] = 1; + } + return drupal_current_script_url($query); +} + /** * Functional equivalent of t(), used when some systems are not available. * diff --git a/modules/simpletest/tests/cache.test b/modules/simpletest/tests/cache.test index 954f57596..d292fa661 100644 --- a/modules/simpletest/tests/cache.test +++ b/modules/simpletest/tests/cache.test @@ -151,14 +151,22 @@ class CacheSavingCase extends CacheTestCase { $this->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.')); } - /* + /** * Check or a variable is stored and restored properly. - **/ + */ function checkVariable($var) { cache_set('test_var', $var, 'cache'); $cache = cache_get('test_var', 'cache'); $this->assertTrue(isset($cache->data) && $cache->data === $var, t('@type is saved and restored properly.', array('@type' => ucfirst(gettype($var))))); } + + /** + * Test no empty cids are written in cache table. + */ + function testNoEmptyCids() { + $this->drupalGet('user/register'); + $this->assertFalse(cache_get(''), t('No cache entry is written with an empty cid.')); + } } /** diff --git a/modules/system/system.test b/modules/system/system.test index d482afa22..5c22a38b3 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -2086,7 +2086,7 @@ class UpdateScriptFunctionalTest extends DrupalWebTestCase { } function setUp() { - parent::setUp(); + parent::setUp('update_script_test'); $this->update_url = $GLOBALS['base_url'] . '/update.php'; $this->update_user = $this->drupalCreateUser(array('administer software updates')); } @@ -2122,6 +2122,49 @@ class UpdateScriptFunctionalTest extends DrupalWebTestCase { $this->assertResponse(200); } + /** + * Tests that requirements warnings and errors are correctly displayed. + */ + function testRequirements() { + $this->drupalLogin($this->update_user); + + // If there are no requirements warnings or errors, we expect to be able to + // go through the update process uninterrupted. + $this->drupalGet($this->update_url, array('external' => TRUE)); + $this->drupalPost(NULL, array(), t('Continue')); + $this->assertText(t('No pending updates.'), t('End of update process was reached.')); + + // If there is a requirements warning, we expect it to be initially + // displayed, but clicking the link to proceed should allow us to go + // through the rest of the update process uninterrupted. (First run this + // test with pending updates to make sure they can be run successfully; + // then try again without pending updates to make sure that works too.) + variable_set('update_script_test_requirement_type', REQUIREMENT_WARNING); + drupal_set_installed_schema_version('update_script_test', drupal_get_installed_schema_version('update_script_test') - 1); + $this->drupalGet($this->update_url, array('external' => TRUE)); + $this->assertText('This is a requirements warning provided by the update_script_test module.'); + $this->clickLink('try again'); + $this->assertNoText('This is a requirements warning provided by the update_script_test module.'); + $this->drupalPost(NULL, array(), t('Continue')); + $this->drupalPost(NULL, array(), t('Apply pending updates')); + $this->assertText(t('The update_script_test_update_8000() update was executed successfully.'), t('End of update process was reached.')); + $this->drupalGet($this->update_url, array('external' => TRUE)); + $this->assertText('This is a requirements warning provided by the update_script_test module.'); + $this->clickLink('try again'); + $this->assertNoText('This is a requirements warning provided by the update_script_test module.'); + $this->drupalPost(NULL, array(), t('Continue')); + $this->assertText(t('No pending updates.'), t('End of update process was reached.')); + + // If there is a requirements error, it should be displayed even after + // clicking the link to proceed (since the problem that triggered the error + // has not been fixed). + variable_set('update_script_test_requirement_type', REQUIREMENT_ERROR); + $this->drupalGet($this->update_url, array('external' => TRUE)); + $this->assertText('This is a requirements error provided by the update_script_test module.'); + $this->clickLink('try again'); + $this->assertText('This is a requirements error provided by the update_script_test module.'); + } + /** * Tests the effect of using the update script on the theme system. */ diff --git a/update.php b/update.php index ac594ff85..865072031 100644 --- a/update.php +++ b/update.php @@ -245,7 +245,8 @@ function update_info_page() { $output .= "
  • Install your new files in the appropriate location, as described in the handbook.
  • \n"; $output .= "\n"; $output .= "

    When you have performed the steps above, you may proceed.

    \n"; - $output .= '

    '; + $form_action = check_url(drupal_current_script_url(array('op' => 'selection', 'token' => $token))); + $output .= '

    '; $output .= "\n"; return $output; } @@ -316,20 +317,26 @@ function update_extra_requirements($requirements = NULL) { } /** - * Check update requirements and report any errors. + * Check update requirements and report any errors or (optionally) warnings. + * + * @param $skip_warnings + * (optional) If set to TRUE, requirement warnings will be ignored, and a + * report will only be issued if there are requirement errors. Defaults to + * FALSE. */ -function update_check_requirements() { +function update_check_requirements($skip_warnings = FALSE) { // Check requirements of all loaded modules. $requirements = module_invoke_all('requirements', 'update'); $requirements += update_extra_requirements(); $severity = drupal_requirements_severity($requirements); - // If there are issues, report them. - if ($severity == REQUIREMENT_ERROR) { + // If there are errors, always display them. If there are only warnings, skip + // them if the caller has indicated they should be skipped. + if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && !$skip_warnings)) { update_task_list('requirements'); drupal_set_title('Requirements problem'); $status_report = theme('status_report', array('requirements' => $requirements)); - $status_report .= 'Check the error messages and try again.'; + $status_report .= 'Check the error messages and try again.'; print theme('update_page', array('content' => $status_report)); exit(); } @@ -385,8 +392,9 @@ if (empty($op) && update_access_allowed()) { // Set up theme system for the maintenance page. drupal_maintenance_theme(); - // Check the update requirements for Drupal. - update_check_requirements(); + // Check the update requirements for Drupal. Only report on errors at this + // stage, since the real requirements check happens further down. + update_check_requirements(TRUE); // Redirect to the update information page if all requirements were met. install_goto('update.php?op=info'); @@ -418,8 +426,12 @@ if (update_access_allowed()) { update_fix_compatibility(); - // Check the update requirements for all modules. - update_check_requirements(); + // Check the update requirements for all modules. If there are warnings, but + // no errors, skip reporting them if the user has provided a URL parameter + // acknowledging the warnings and indicating a desire to continue anyway. See + // drupal_requirements_url(). + $skip_warnings = !empty($_GET['continue']); + update_check_requirements($skip_warnings); $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : ''; switch ($op) { @@ -433,7 +445,12 @@ if (update_access_allowed()) { case 'Apply pending updates': if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) { - update_batch($_POST['start'], $base_url . '/update.php?op=results', $base_url . '/update.php'); + // Generate absolute URLs for the batch processing (using $base_root), + // since the batch API will pass them to url() which does not handle + // update.php correctly by default. + $batch_url = $base_root . drupal_current_script_url(); + $redirect_url = $base_root . drupal_current_script_url(array('op' => 'results')); + update_batch($_POST['start'], $redirect_url, $batch_url); break; } -- cgit v1.2.3