Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.142 diff -u -p -r1.142 install.php --- install.php 10 Nov 2008 05:22:56 -0000 1.142 +++ install.php 11 Nov 2008 23:07:15 -0000 @@ -1109,10 +1109,18 @@ function install_configure_form(&$form_s '#weight' => 15, ); + $form['server_settings']['cron_run_safe'] = array( + '#type' => 'checkbox', + '#title' => st('Automatically run cron'), + '#default_value' => TRUE, + '#description' => st('With this option enabled, the site will check whether cron has been run in the past @interval and automatically run it upon the next page request.', array('@interval' => format_interval(10800, 1))), + '#weight' => 20, + ); + $form['submit'] = array( '#type' => 'submit', '#value' => st('Save and continue'), - '#weight' => 15, + '#weight' => 30, ); $form['#action'] = $url; $form['#redirect'] = FALSE; @@ -1172,9 +1180,14 @@ function install_configure_form_submit($ unset($form_state['old_values']); variable_set('user_email_verification', TRUE); + // Configure clean URLs. if (isset($form_state['values']['clean_url'])) { variable_set('clean_url', $form_state['values']['clean_url']); } + // Configure cron, using the default value of 3 hours, if enabled. + if (!empty($form_state['values']['cron_run_safe'])) { + variable_set('cron_safe_threshold', 10800); + } // The user is now logged in, but has no session ID yet, which // would be required later in the request, so remember it. $user->sid = session_id(); Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.247 diff -u -p -r1.247 bootstrap.inc --- includes/bootstrap.inc 11 Nov 2008 22:39:58 -0000 1.247 +++ includes/bootstrap.inc 12 Nov 2008 00:06:59 -0000 @@ -1141,8 +1141,15 @@ function _drupal_bootstrap($phase) { if ($cache_mode != CACHE_AGGRESSIVE) { bootstrap_invoke_all('boot'); } - // If there is a cached page, display it. - if ($cache) { + // Check whether we need to run cron. + if ($cron_treshold = variable_get('cron_safe_threshold', 0)) { + $cron_last = variable_get('cron_last', NULL); + if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $cron_treshold)) { + $run_cron = TRUE; + } + } + // If there is a cached page, display it; unless we need to run cron. + if ($cache && !isset($run_cron)) { drupal_page_cache_header($cache); // If the skipping of the bootstrap hooks is not enforced, call hook_exit. if ($cache_mode != CACHE_AGGRESSIVE) { Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.824 diff -u -p -r1.824 common.inc --- includes/common.inc 11 Nov 2008 22:39:58 -0000 1.824 +++ includes/common.inc 11 Nov 2008 23:58:48 -0000 @@ -2728,6 +2728,14 @@ function _drupal_bootstrap_full() { // Load all enabled modules module_load_all(); + // Register a safe cron run at the end of the request if needed. + if ($cron_treshold = variable_get('cron_safe_threshold', 0)) { + $cron_last = variable_get('cron_last', NULL); + if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $cron_treshold)) { + register_shutdown_function('drupal_cron_run'); + } + } + // Let all modules take action before menu system handles the request // We do not want this while running update.php. if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.104 diff -u -p -r1.104 system.admin.inc --- modules/system/system.admin.inc 11 Nov 2008 22:39:59 -0000 1.104 +++ modules/system/system.admin.inc 12 Nov 2008 00:06:59 -0000 @@ -1700,7 +1700,6 @@ function system_date_time_lookup() { * @see system_settings_form() */ function system_site_maintenance_settings() { - $form['site_offline'] = array( '#type' => 'radios', '#title' => t('Site status'), @@ -1716,6 +1715,14 @@ function system_site_maintenance_setting '#description' => t('Message to show visitors when the site is in offline mode.') ); + $form['cron_safe_threshold'] = array( + '#type' => 'select', + '#title' => t('Automatically run cron'), + '#default_value' => variable_get('cron_safe_threshold', 0), + '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), + '#description' => t('When enabled, the site will check whether cron has been run in the configured interval and automatically run it upon the next page request. For more information visit the status report page.', array('@status-report-url' => url('admin/reports/status'))), + ); + return system_settings_form($form); }