diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-10-13 21:16:44 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-10-13 21:16:44 +0000 |
commit | 24c259cdd87e747187aecf94dc1f1834e7602adf (patch) | |
tree | 807f9e82346dcf8d397ef9756ef049ff1c1b2d93 | |
parent | 3257ebf6606c4ab7c56acb012be95075eb67fbda (diff) | |
download | brdo-24c259cdd87e747187aecf94dc1f1834e7602adf.tar.gz brdo-24c259cdd87e747187aecf94dc1f1834e7602adf.tar.bz2 |
- Patch #601570 by effulgentsia: hook_exit() and other cleanup needs to happen for AJAX requests too.
-rw-r--r-- | includes/ajax.inc | 4 | ||||
-rw-r--r-- | includes/common.inc | 34 | ||||
-rw-r--r-- | includes/file.inc | 2 | ||||
-rw-r--r-- | includes/install.inc | 2 | ||||
-rw-r--r-- | includes/xmlrpcs.inc | 2 | ||||
-rw-r--r-- | modules/dashboard/dashboard.module | 6 | ||||
-rw-r--r-- | modules/image/image.module | 6 | ||||
-rw-r--r-- | modules/openid/openid.inc | 10 | ||||
-rw-r--r-- | modules/system/system.admin.inc | 2 | ||||
-rw-r--r-- | modules/system/system.api.php | 5 | ||||
-rw-r--r-- | modules/system/system.module | 2 | ||||
-rw-r--r-- | modules/upload/upload.module | 2 |
12 files changed, 40 insertions, 37 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc index 1b8564d7a..ca198d6fa 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -162,7 +162,7 @@ function ajax_render($commands = array(), $header = TRUE) { else { print drupal_json_encode($commands); } - exit; + drupal_exit(); } /** @@ -207,7 +207,7 @@ function ajax_get_form() { // This is likely a hacking attempt as it never happens under normal // circumstances, so we just do nothing. watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING); - exit; + drupal_exit(); } // Since some of the submit handlers are run, redirects need to be disabled. diff --git a/includes/common.inc b/includes/common.inc index 8993047c6..e715010f2 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -656,22 +656,12 @@ function drupal_goto($path = '', array $query = array(), $fragment = NULL, $http $url = url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => TRUE)); - // Allow modules to react to the end of the page request before redirecting. - // We do not want this while running update.php. - if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { - module_invoke_all('exit', $url); - } - - // Commit the session, if necessary. We need all session data written to the - // database before redirecting. - drupal_session_commit(); - header('Location: ' . $url, TRUE, $http_response_code); // The "Location" header sends a redirect status code to the HTTP daemon. In // some cases this can be wrong, so we make sure none of the code below the // drupal_goto() call gets executed upon redirection. - exit(); + drupal_exit($url); } /** @@ -2628,6 +2618,28 @@ function drupal_page_footer() { } /** + * Perform end-of-request tasks. + * + * In some cases page requests need to end without calling drupal_page_footer(). + * In these cases, call drupal_exit() instead. There should rarely be a reason + * to call exit instead of drupal_exit(); + * + * @param $destination + * If this function is called from drupal_goto(), then this argument + * will be a fully-qualified URL that is the destination of the redirect. + * This should be passed along to hook_exit() implementations. + */ +function drupal_exit($destination = NULL) { + if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { + if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { + module_invoke_all('exit', $destination); + } + drupal_session_commit(); + } + exit; +} + +/** * Form an associative array from a linear array. * * This function walks through the provided array and constructs an associative diff --git a/includes/file.inc b/includes/file.inc index dc9d8236e..719d04677 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -1527,7 +1527,7 @@ function file_transfer($uri, $headers) { else { drupal_not_found(); } - exit(); + drupal_exit(); } /** diff --git a/includes/install.inc b/includes/install.inc index 69e49c951..d05a8096f 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -925,7 +925,7 @@ function install_goto($path) { global $base_url; header('Location: ' . $base_url . '/' . $path); header('Cache-Control: no-cache'); // Not a permanent redirect. - exit(); + drupal_exit(); } /** diff --git a/includes/xmlrpcs.inc b/includes/xmlrpcs.inc index cf378f4fc..35a18161d 100644 --- a/includes/xmlrpcs.inc +++ b/includes/xmlrpcs.inc @@ -109,7 +109,7 @@ function xmlrpc_server_output($xml) { drupal_add_http_header('Content-Length', strlen($xml)); drupal_add_http_header('Content-Type', 'text/xml'); echo $xml; - exit; + drupal_exit(); } /** diff --git a/modules/dashboard/dashboard.module b/modules/dashboard/dashboard.module index bc903d676..6db5e21c8 100644 --- a/modules/dashboard/dashboard.module +++ b/modules/dashboard/dashboard.module @@ -242,7 +242,7 @@ function dashboard_show_disabled() { // Theme the output and end the page request. print theme('dashboard_disabled_blocks', array('blocks' => $blocks)); - exit(); + drupal_exit(); } /** @@ -270,7 +270,7 @@ function dashboard_show_block_content($module, $delta) { $build = _block_get_renderable_array($block_content); $rendered_block = drupal_render($build); print $rendered_block; - exit; + drupal_exit(); } /** @@ -318,7 +318,7 @@ function dashboard_update() { } } } - exit; + drupal_exit(); } /** diff --git a/modules/image/image.module b/modules/image/image.module index f745662d3..e41edc642 100644 --- a/modules/image/image.module +++ b/modules/image/image.module @@ -484,7 +484,7 @@ function image_style_generate() { // image_style_url(). if (!$style || !cache_get('access:' . $style_name . ':' . $path_md5, 'cache_image')) { drupal_access_denied(); - exit(); + drupal_exit(); } // Don't start generating the image if the derivate already exists or if @@ -498,7 +498,7 @@ function image_style_generate() { drupal_add_http_header('503 Service Unavailable'); drupal_add_http_header('Retry-After', 3); print t('Image generation in progress, please try again shortly.'); - exit(); + drupal_exit(); } } @@ -518,7 +518,7 @@ function image_style_generate() { watchdog('image', 'Unable to generate the derived image located at %path.', $destination); drupal_add_http_header('500 Internal Server Error'); print t('Error generating image.'); - exit(); + drupal_exit(); } } diff --git a/modules/openid/openid.inc b/modules/openid/openid.inc index bb90596a5..ef923c97e 100644 --- a/modules/openid/openid.inc +++ b/modules/openid/openid.inc @@ -62,10 +62,7 @@ function openid_redirect_http($url, $message) { $sep = (strpos($url, '?') === FALSE) ? '?' : '&'; header('Location: ' . $url . $sep . implode('&', $query), TRUE, 302); - // Commit session data before redirecting. - drupal_session_commit(); - - exit; + drupal_exit(); } /** @@ -78,10 +75,7 @@ function openid_redirect($url, $message) { $output .= "</body></html>\n"; print $output; - // Commit session data before redirecting. - drupal_session_commit(); - - exit; + drupal_exit(); } function openid_redirect_form($form, &$form_state, $url, $message) { diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index e21c114ae..190128b4a 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1922,7 +1922,7 @@ function system_run_cron() { */ function system_php() { phpinfo(); - exit(); + drupal_exit(); } /** diff --git a/modules/system/system.api.php b/modules/system/system.api.php index 2826cdbc6..1c5094704 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -259,7 +259,7 @@ 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 printing out debugging information. + * page logging and specialized cleanup. This hook MUST NOT print anything. * * 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 @@ -271,9 +271,6 @@ function hook_element_info_alter(&$type) { * @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. - * Modules may use this to react appropriately; for example, nothing should - * be output in this case, because PHP will then throw a "headers cannot be - * modified" error when attempting the redirection. */ function hook_exit($destination = NULL) { db_update('counter') diff --git a/modules/system/system.module b/modules/system/system.module index 0e932863d..996894419 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -2888,7 +2888,7 @@ function system_run_cron_image() { } } - exit; + drupal_exit(); } /** diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 51328d97c..391d064b3 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -649,7 +649,7 @@ function upload_js() { form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.')); $output = theme('status_messages'); print drupal_json_encode(array('status' => TRUE, 'data' => $output)); - exit(); + drupal_exit(); } $form_state = array('values' => $_POST); |