Commit 24c259cd authored by Dries's avatar Dries

- Patch #601570 by effulgentsia: hook_exit() and other cleanup needs to happen...

- Patch #601570 by effulgentsia: hook_exit() and other cleanup needs to happen for AJAX requests too.
parent 3257ebf6
......@@ -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.
......
......@@ -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);
}
/**
......@@ -2627,6 +2617,28 @@ function drupal_page_footer() {
module_implements_write_cache();
}
/**
* 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.
*
......
......@@ -1527,7 +1527,7 @@ function file_transfer($uri, $headers) {
else {
drupal_not_found();
}
exit();
drupal_exit();
}
/**
......
......@@ -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();
}
/**
......
......@@ -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();
}
/**
......
......@@ -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();
}
/**
......
......@@ -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();
}
}
......
......@@ -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) {
......
......@@ -1922,7 +1922,7 @@ function system_run_cron() {
*/
function system_php() {
phpinfo();
exit();
drupal_exit();
}
/**
......
......@@ -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')
......
......@@ -2888,7 +2888,7 @@ function system_run_cron_image() {
}
}
exit;
drupal_exit();
}
/**
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment