diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 9e6f334fbe90b6fae4b7d31ee7c6dd16b45140a1..edbe0b7d503778d28f42b0628c077d637ffab1b9 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1443,7 +1443,7 @@ function drupal_serve_page_from_cache(stdClass $cache) { * Defines the critical hooks that force modules to always be loaded. */ function bootstrap_hooks() { - return array('exit', 'watchdog'); + return array('watchdog'); } /** @@ -2353,11 +2353,6 @@ function _drupal_bootstrap_page_cache() { date_default_timezone_set(drupal_get_user_timezone()); drupal_serve_page_from_cache($cache); - // If the skipping of the bootstrap hooks is not enforced, call - // hook_exit. - if (variable_get('page_cache_invoke_hooks', TRUE)) { - bootstrap_invoke_all('exit'); - } // We are done. exit; } diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 383f08a5cd240ba6c715ea24bf96c859c29e628b..1893a15a1d3b4a484f66dbb4cf6512234ee600db 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -171,9 +171,7 @@ function overlay_init() { * the supplemental regions of the overlay on the next page request. */ function overlay_exit() { - // Check that we are in an overlay child page. Note that this should never - // return TRUE on a cached page view, since the child mode is not set until - // overlay_init() is called. + // Check that we are in an overlay child page. if (overlay_get_mode() == 'child') { // Load any markup that was stored earlier in the page request, via calls // to overlay_store_rendered_content(). If none was stored, this is not a diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php similarity index 75% rename from core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php rename to core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php index 850687b5cafa72d6973099318dde2bc7d869fcdf..06733409d7399a51423a2a06d2671c3a71d71c11 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php @@ -33,7 +33,7 @@ public static function getInfo() { * Tests calling of hook_exit(). */ function testHookExit() { - // Test with cache disabled. Boot and exit should always fire. + // Test with cache disabled. Exit should always fire. $config = config('system.performance'); $config->set('cache.page.enabled', 0); $config->save(); @@ -42,14 +42,18 @@ function testHookExit() { $calls = 1; $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with disabled cache.'); - // Test with normal cache. Exit should be called. + // Test with normal cache. On the first call, exit should fire + // (since cache is empty), but on the second call it should not be fired. $config->set('cache.page.enabled', 1); $config->save(); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with normal cache.'); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with normal cache and no cached page.'); + $this->assertTrue(cache('page')->get(url('', array('absolute' => TRUE))), 'Page has been cached.'); + $this->drupalGet(''); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit not called with normal cache and a cached page.'); - // Exit should not fire since the page is cached. + // Test with aggressive cache. Exit should not fire since page is cached. variable_set('page_cache_invoke_hooks', FALSE); $this->assertTrue(cache('page')->get(url('', array('absolute' => TRUE))), 'Page has been cached.'); $this->drupalGet(''); diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ba82bd468c950cf5e05b7f20249fd44b31659679..528eb02cb3e2fff97d819f2bd80d0ce3a3b6e318 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -318,26 +318,19 @@ function hook_element_info_alter(&$type) { /** * Perform cleanup tasks. * - * This hook is run at the end of each page request. It is often used for - * page logging and specialized cleanup. This hook MUST NOT print anything - * because by the time it runs the response is already sent to the browser. + * This hook is run at the end of each non-cached page request. It is often + * used for page logging and specialized cleanup. This hook MUST NOT print + * anything because by the time it runs the response is already sent to the + * browser. * - * Only use this hook if your code must run even for cached page views. - * If you have code which must run once on all non-cached pages, use - * hook_init() instead. That is the usual case. If you implement this hook - * and see an error like 'Call to undefined function', it is likely that - * you are depending on the presence of a module which has not been loaded yet. - * It is not loaded because Drupal is still in bootstrap mode. + * This hook is not run on cached pages. * * @param $destination * If this hook is invoked as part of a drupal_goto() call, then this argument * will be a fully-qualified URL that is the destination of the redirect. */ function hook_exit($destination = NULL) { - db_update('counter') - ->expression('hits', 'hits + 1') - ->condition('type', 1) - ->execute(); + watchdog('mymodule', 'Page was built for user %name.', array('%name' => user_format_name($GLOBALS['user'])), WATCHDOG_INFO); } /**