summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2013-02-07 14:14:22 (GMT)
committercatch2013-02-07 14:14:22 (GMT)
commitb574b9e52da16875daa896714c7c370d14e20e09 (patch)
tree8bbe0187535dd5027ac3d3a7aade728cf9b0f79a
parenta039a98aef8b34b0be0e7e69b99fc881f37d4312 (diff)
Issue #1860026 by aspilicious, David_Rothstein, katbailey, rootatwc: Remove hook_exit() for cached page requests, and decide between it and the onTerminate eventotherwise.
-rw-r--r--core/includes/bootstrap.inc7
-rw-r--r--core/modules/overlay/overlay.module4
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php (renamed from core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php)12
-rw-r--r--core/modules/system/system.api.php19
4 files changed, 16 insertions, 26 deletions
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 9e6f334..edbe0b7 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 383f08a..1893a15 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
index 850687b..0673340 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 @@ 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('');
diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php
index ba82bd4..528eb02 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);
}
/**