#331611: integrate a "poormanscron" like feature in core. From: Damien Tournoud --- includes/common.inc | 9 +++++++++ modules/system/system.admin.inc | 7 +++++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git includes/common.inc includes/common.inc index 73b7526..908b78b 100644 --- includes/common.inc +++ includes/common.inc @@ -2715,6 +2715,7 @@ function _drupal_bootstrap_full() { require_once DRUPAL_ROOT . '/includes/form.inc'; require_once DRUPAL_ROOT . '/includes/mail.inc'; require_once DRUPAL_ROOT . '/includes/actions.inc'; + // Set the Drupal custom error handler. set_error_handler('_drupal_error_handler'); set_exception_handler('_drupal_exception_handler'); @@ -2728,6 +2729,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 (variable_get('cron_safe_run', 1)) { + $cron_last = variable_get('cron_last', NULL); + if (!isset($cron_last) || (REQUEST_TIME - $cron_last > variable_get('cron_safe_threshold', 10800))) { + 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') { diff --git modules/system/system.admin.inc modules/system/system.admin.inc index b18adc7..6f545d5 100644 --- modules/system/system.admin.inc +++ modules/system/system.admin.inc @@ -1716,6 +1716,13 @@ function system_site_maintenance_settings() { '#description' => t('Message to show visitors when the site is in offline mode.') ); + $form['cron_safe_run'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically run the cron'), + '#default_value' => variable_get('cron_safe_run', 1), + '#description' => t('Automatically run the cron if it has not run for an extended period of time.'), + ); + return system_settings_form($form); }