Issue #1860026 by aspilicious, David_Rothstein, katbailey, rootatwc: Remove hook_exit() for cached page requests, and decide between it and the onTerminate eventotherwise.

8.0.x
catch 2013-02-07 14:14:22 +00:00
parent a039a98aef
commit b574b9e52d
4 changed files with 16 additions and 26 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -33,7 +33,7 @@ class HookExitTest extends WebTestBase {
* 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 @@ class HookExitTest extends WebTestBase {
$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('');

View File

@ -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);
}
/**