0byt3m1n1
Path:
/
data
/
applications
/
aps.bak
/
drupal
/
6.9-5
/
standard
/
htdocs
/
sites
/
all
/
modules
/
[
Home
]
File: poormanscron.module
<?php // $Id: poormanscron.module,v 1.21 2008/02/06 16:35:17 robloach Exp $ $Name: DRUPAL-6--1-0 $ /** * @file * A module which runs Drupal cron jobs without the cron application. */ /** * Implementation of hook_help(). */ function poormanscron_help($path, $arg) { switch ($path) { case 'admin/help#poormanscron': return '<p>'. t('The Poormanscron module runs cron jobs without the need of the cron application.') .'</p>'; case 'admin/settings/poormanscron': return '<p>'. t('The settings provided here allow you to administer Poormancron.') .'</p>'; } } /** * Implementation of hook_exit(). * * Checks if poormanscron needs to be run. If this is the case, it invokes * the cron hooks of all enabled modules, which are executed after * all HTML is returned to the browser. So the user who kicks off the cron * jobs should not notice any delay. */ function poormanscron_exit() { // Calculate when the next poormanscron run is due. $lastrun = variable_get('poormanscron_lastrun', 0); $nextrun = $lastrun + 60 * variable_get('poormanscron_interval', 60); // If the configured time has passed, start the next poormanscron run. if (time() > $nextrun) { // If this cron run fails to complete, wait a few minutes before retrying. variable_set('poormanscron_lastrun', $lastrun + 60 * variable_get('poormanscron_retry_interval', 10)); // Get the current Drupal messages. Use drupal_set_message() so that // the messages aren't deleted in case the cron run fails and // we don't get a chance to restore them below. $saved_messages = drupal_set_message(); // Invoke the cron hooks of all enabled modules. if (variable_get('poormanscron_log_progress', 0) == 1) { // Invoke the cron hooks of all enabled modules and log the progress. $modules = module_list(); foreach ($modules as $key => $value) { if (module_hook($key, 'cron')) { $tt = time(); module_invoke($key, 'cron'); watchdog('cron', "Executed %hook via poormanscron, took %time.", array('%time' => format_interval(time() - $tt, 1) . '.', '%hook' => "${key}_cron")); } } } else { // Invoke the cron hooks of all enabled modules, no progress logging. module_invoke_all('cron'); } // Write a message to the logs if the user wants us to do so. if (variable_get('poormanscron_log_cron_runs', 1) == 1) { watchdog('cron', 'Cron run completed (via poormanscron).'); } $t = time(); // Update the time of the last poormanscron run (this one). variable_set('poormanscron_lastrun', $t); // Update the $cron_last variable, in order to update the // cron status in admin/settings. variable_set('cron_last', $t); // Delete any messages added during the cron run (and existing prior // messages). drupal_get_messages(); // Restore any prior messages. if (isset($saved_messages)) { foreach ($saved_messages as $type => $types_messages) { foreach ($types_messages as $message) { drupal_set_message($message, $type); } } } } } /** * Implmentation of hook_menu(). */ function poormanscron_menu() { $items = array(); $items['admin/settings/poormanscron'] = array( 'title' => 'Poormanscron', 'description' => 'A module which runs Drupal cron jobs without the cron application.', 'page callback' => 'drupal_get_form', 'page arguments' => array('poormanscron_admin_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'poormanscron.admin.inc', ); return $items; }