diff --git a/cron.php b/cron.php index 9af2f9acb5d74081557cccc97cf28143163cb5dd..7e2ba89a7732d66199cb5eb0ffc5d293095e3f0b 100644 --- a/cron.php +++ b/cron.php @@ -27,5 +27,5 @@ // Clean up variable_set('cron_busy', false); +variable_set('cron_last', time()); watchdog('cron', t('Cron run completed')); - diff --git a/database/updates.inc b/database/updates.inc index 966fb6c631e8ac40a4de9cd9f9235829a7cd776e..5cb099bf9b26548e2074754609d97f3a0e2836cc 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -1333,3 +1333,11 @@ function system_update_164() { return $ret; } + +function system_update_165() { + $cron_last = max(variable_get('drupal_cron_last'), variable_get('ping_cron_last')); + variable_set('cron_last', $cron_last); + variable_del('drupal_cron_last'); + variable_del('ping_cron_last'); + return array(); +} diff --git a/modules/drupal.module b/modules/drupal.module index c42d2c13487f28614a9c511e0e760ef2fc1d8ee5..fe25a0f3b94db2d23b3782a6577ac985f9ad95f6 100644 --- a/modules/drupal.module +++ b/modules/drupal.module @@ -74,8 +74,7 @@ function drupal_settings() { * Implementation of hook_cron(); handles pings to and from the site. */ function drupal_cron() { - if (time() - variable_get('drupal_cron_last', 0) > 21600) { - variable_set('drupal_cron_last', time()); + if (time() - variable_get('cron_last', 0) > 21600) { // If this site acts as a Drupal XML-RPC server, delete the sites that // stopped sending "ping" messages. diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module index c42d2c13487f28614a9c511e0e760ef2fc1d8ee5..fe25a0f3b94db2d23b3782a6577ac985f9ad95f6 100644 --- a/modules/drupal/drupal.module +++ b/modules/drupal/drupal.module @@ -74,8 +74,7 @@ function drupal_settings() { * Implementation of hook_cron(); handles pings to and from the site. */ function drupal_cron() { - if (time() - variable_get('drupal_cron_last', 0) > 21600) { - variable_set('drupal_cron_last', time()); + if (time() - variable_get('cron_last', 0) > 21600) { // If this site acts as a Drupal XML-RPC server, delete the sites that // stopped sending "ping" messages. diff --git a/modules/ping.module b/modules/ping.module index d43138378868dd78ac6569e1e4ae53948b412481..1d06e78e85b678168eaca8dedff69230816ddfae 100644 --- a/modules/ping.module +++ b/modules/ping.module @@ -37,11 +37,9 @@ function ping_cron() { global $base_url; if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) { - if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('ping_cron_last', time()) ."' OR changed > '". variable_get('ping_cron_last', time()) ."')"), 1)) { + if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('cron_last', time()) ."' OR changed > '". variable_get('cron_last', time()) ."')"), 1)) { _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url); } - - variable_set('ping_cron_last', time()); } } diff --git a/modules/ping/ping.module b/modules/ping/ping.module index d43138378868dd78ac6569e1e4ae53948b412481..1d06e78e85b678168eaca8dedff69230816ddfae 100644 --- a/modules/ping/ping.module +++ b/modules/ping/ping.module @@ -37,11 +37,9 @@ function ping_cron() { global $base_url; if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) { - if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('ping_cron_last', time()) ."' OR changed > '". variable_get('ping_cron_last', time()) ."')"), 1)) { + if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('cron_last', time()) ."' OR changed > '". variable_get('cron_last', time()) ."')"), 1)) { _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url); } - - variable_set('ping_cron_last', time()); } } diff --git a/modules/system.module b/modules/system.module index b634a232e369dbf60cea74541ea8567df6667db0..e01ecfc13614fe1f0712c8ba230769a10885c113 100644 --- a/modules/system.module +++ b/modules/system.module @@ -18,10 +18,10 @@ function system_help($section) { $output .= t('<p>You can</p> <ul> <li>activate your cron job on the cron page <a href="%file-cron">cron.php</a>.</li> -<li>read how to <a href="%external-http-drupal-org-node-23714">configure cron jobs</a>.</li> +<li>read how to <a href="%external-http-drupal-org-cron">configure cron jobs</a>.</li> <li>administer cache settings in <a href="%admin-settings">administer >> settings</a>.</li> </ul> -', array('%file-cron' => 'cron.php', '%external-http-drupal-org-node-23714' => 'http://drupal.org/node/23714', '%admin-settings' => url('admin/settings'))); +', array('%file-cron' => 'cron.php', '%external-http-drupal-org-cron' => 'http://drupal.org/cron', '%admin-settings' => url('admin/settings'))); $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%system">System page</a>.', array('%system' => 'http://www.drupal.org/handbook/modules/system/')) .'</p>'; return $output; case 'admin/modules#description': @@ -461,6 +461,10 @@ function system_view_general() { $form['strings'] = array('#type' => 'fieldset', '#title' => t('String handling'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['strings'] = array_merge($form['strings'], unicode_settings()); + // Cron: report status and errors. + $form['cron'] = array('#type' => 'fieldset', '#title' => t('Cron jobs'), '#collapsible' => TRUE, '#collapsed' => TRUE); + $form['cron'] = array_merge($form['cron'], system_cron_settings()); + return $form; } @@ -479,6 +483,25 @@ function system_check_directory($form_element) { return $form_element; } +/** + * Return the cron status and errors for admin/settings. + */ +function system_cron_settings() { + $cron_last = variable_get('cron_last', NULL); + + if (is_numeric($cron_last)) { + $title = t('Cron properly configured'); + $status = t('Cron is running. The last cron job ran %time ago.', array('%time' => format_interval(time() - $cron_last))); + } + else { + $title = t('Cron not configured'); + $status = t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for <a href="%url">configuring cron jobs</a>.', array('%url' => 'http://drupal.org/cron')); + } + + $form['settings'] = array('#type' => 'item', '#title' => $title, '#value' => $status); + return $form; +} + /** * Retrieves the current status of an array of files in the system table. */ diff --git a/modules/system/system.module b/modules/system/system.module index b634a232e369dbf60cea74541ea8567df6667db0..e01ecfc13614fe1f0712c8ba230769a10885c113 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -18,10 +18,10 @@ function system_help($section) { $output .= t('<p>You can</p> <ul> <li>activate your cron job on the cron page <a href="%file-cron">cron.php</a>.</li> -<li>read how to <a href="%external-http-drupal-org-node-23714">configure cron jobs</a>.</li> +<li>read how to <a href="%external-http-drupal-org-cron">configure cron jobs</a>.</li> <li>administer cache settings in <a href="%admin-settings">administer >> settings</a>.</li> </ul> -', array('%file-cron' => 'cron.php', '%external-http-drupal-org-node-23714' => 'http://drupal.org/node/23714', '%admin-settings' => url('admin/settings'))); +', array('%file-cron' => 'cron.php', '%external-http-drupal-org-cron' => 'http://drupal.org/cron', '%admin-settings' => url('admin/settings'))); $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%system">System page</a>.', array('%system' => 'http://www.drupal.org/handbook/modules/system/')) .'</p>'; return $output; case 'admin/modules#description': @@ -461,6 +461,10 @@ function system_view_general() { $form['strings'] = array('#type' => 'fieldset', '#title' => t('String handling'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['strings'] = array_merge($form['strings'], unicode_settings()); + // Cron: report status and errors. + $form['cron'] = array('#type' => 'fieldset', '#title' => t('Cron jobs'), '#collapsible' => TRUE, '#collapsed' => TRUE); + $form['cron'] = array_merge($form['cron'], system_cron_settings()); + return $form; } @@ -479,6 +483,25 @@ function system_check_directory($form_element) { return $form_element; } +/** + * Return the cron status and errors for admin/settings. + */ +function system_cron_settings() { + $cron_last = variable_get('cron_last', NULL); + + if (is_numeric($cron_last)) { + $title = t('Cron properly configured'); + $status = t('Cron is running. The last cron job ran %time ago.', array('%time' => format_interval(time() - $cron_last))); + } + else { + $title = t('Cron not configured'); + $status = t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for <a href="%url">configuring cron jobs</a>.', array('%url' => 'http://drupal.org/cron')); + } + + $form['settings'] = array('#type' => 'item', '#title' => $title, '#value' => $status); + return $form; +} + /** * Retrieves the current status of an array of files in the system table. */