| 1 |
<?php |
<?php |
| 2 |
// $Id: poormanscron.module,v 1.19 2007/01/14 12:28:10 uwe Exp $ $Name: $ |
// $Id: poormanscron.module,v 1.18.2.1 2007/01/14 12:34:37 uwe Exp $ $Name: DRUPAL-5 $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 9 |
/** |
/** |
| 10 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 11 |
*/ |
*/ |
| 12 |
function poormanscron_help($section = 'admin/help#poormanscron') { |
function poormanscron_help($section) { |
| 13 |
switch ($section) { |
switch ($section) { |
| 14 |
case 'admin/help#poormanscron': |
case 'admin/help#poormanscron': |
| 15 |
case 'admin/settings/modules#description': |
return '<p>'. t('The Poormanscron module runs cron jobs without the need of the cron application.') .'</p>'; |
| 16 |
case 'admin/settings/poormanscron': |
case 'admin/settings/poormanscron': |
| 17 |
$output = t('Runs Drupal cron jobs without the cron application.'); |
return '<p>'. t('The settings provided here allow you to administer Poormancron.') .'</p>'; |
|
break; |
|
| 18 |
} |
} |
|
return $output; |
|
| 19 |
} |
} |
| 20 |
|
|
| 21 |
/** |
/** |
| 45 |
$saved_messages = drupal_set_message(); |
$saved_messages = drupal_set_message(); |
| 46 |
|
|
| 47 |
// Invoke the cron hooks of all enabled modules. |
// Invoke the cron hooks of all enabled modules. |
| 48 |
if (variable_get('poormanscron_log_progress', 0) == 1) { |
if (drupal_cron_run()) { |
| 49 |
// Invoke the cron hooks of all enabled modules and log the progress. |
$message = 'Cron run completed (via poormanscron).'; |
|
$modules = module_list(); |
|
|
foreach ($modules as $key => $value) { |
|
|
if (module_hook($key, 'cron')) { |
|
|
$tt = time(); |
|
|
module_invoke($key, 'cron'); |
|
|
watchdog('cron', "Executed ${key}_cron via poormanscron, took " . format_interval(time() - $tt, 1) . '.', WATCHDOG_NOTICE); |
|
|
} |
|
|
} |
|
| 50 |
} |
} |
| 51 |
else { |
else { |
| 52 |
// Invoke the cron hooks of all enabled modules, no progress logging. |
$message = 'Cron run unsuccessful (via poormanscron).'; |
|
module_invoke_all('cron'); |
|
| 53 |
} |
} |
| 54 |
|
|
| 55 |
// Write a message to the logs if the user wants us to do so. |
// Write a message to the logs if the user wants us to do so. |
| 56 |
if (variable_get('poormanscron_log_cron_runs', 1) == 1) { |
if (variable_get('poormanscron_log_cron_runs', 1) == 1) { |
| 57 |
watchdog('cron', 'Cron run completed (via poormanscron).', |
watchdog('cron', $message); |
|
WATCHDOG_NOTICE); |
|
| 58 |
} |
} |
| 59 |
|
|
| 60 |
$t = time(); |
$t = time(); |
| 62 |
// Update the time of the last poormanscron run (this one). |
// Update the time of the last poormanscron run (this one). |
| 63 |
variable_set('poormanscron_lastrun', $t); |
variable_set('poormanscron_lastrun', $t); |
| 64 |
|
|
|
// Update the $cron_last variable, in order to update the |
|
|
// cron status in admin/settings. |
|
|
variable_set('cron_last', $t); |
|
|
|
|
| 65 |
// Delete any messages added during the cron run (and existing prior |
// Delete any messages added during the cron run (and existing prior |
| 66 |
// messages). |
// messages). |
| 67 |
drupal_get_messages(); |
drupal_get_messages(); |
| 74 |
} |
} |
| 75 |
} |
} |
| 76 |
} |
} |
|
|
|
| 77 |
} |
} |
| 78 |
} |
} |
| 79 |
|
|
| 80 |
/** |
/** |
| 81 |
* With hook_settings() obsoleted in 5.0, we now need a menu handler |
* Implmentation of hook_menu(). |
|
* for settings. |
|
|
* |
|
|
* @param bool $may_cache |
|
|
* @return array |
|
| 82 |
*/ |
*/ |
| 83 |
function poormanscron_menu($may_cache) { |
function poormanscron_menu($may_cache) { |
|
|
|
| 84 |
if ($may_cache) { |
if ($may_cache) { |
| 85 |
$items[] = array( |
$items[] = array( |
| 86 |
'path' => 'admin/settings/poormanscron', |
'path' => 'admin/settings/poormanscron', |
| 89 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 90 |
'callback arguments' => 'poormanscron_admin_settings', |
'callback arguments' => 'poormanscron_admin_settings', |
| 91 |
'access' => user_access('administer site configuration'), |
'access' => user_access('administer site configuration'), |
|
'type' => MENU_NORMAL_ITEM, |
|
| 92 |
); |
); |
| 93 |
} |
} |
| 94 |
|
|
| 96 |
} |
} |
| 97 |
|
|
| 98 |
/** |
/** |
| 99 |
* 5.0 version of obsolete hook_settings(). |
* Administration page for Poormanscron. |
| 100 |
*/ |
*/ |
| 101 |
function poormanscron_admin_settings() { |
function poormanscron_admin_settings() { |
| 102 |
$form['time_intervals'] = array('#type' => 'fieldset', '#title' => t('Time intervals')); |
$form['time_intervals'] = array('#type' => 'fieldset', '#title' => t('Time intervals')); |
| 120 |
'#options' => array('1' => t('Yes'), '0' => t('No')), |
'#options' => array('1' => t('Yes'), '0' => t('No')), |
| 121 |
'#description' => t('If you want to log successful cron runs to the Drupal watchdog, say Yes here. If those messages annoy you, disable them by selecting No.') |
'#description' => t('If you want to log successful cron runs to the Drupal watchdog, say Yes here. If those messages annoy you, disable them by selecting No.') |
| 122 |
); |
); |
|
$form['logging']['poormanscron_log_progress'] = array( |
|
|
'#type' => 'select', '#title' => t('Log poormanscron progress'), |
|
|
'#default_value' => variable_get('poormanscron_log_progress', 0), |
|
|
'#options' => array('1' => t('Yes'), '0' => t('No')), |
|
|
'#description' => t('If you want to log the progress of a poormanscron run to the Drupal watchdog, say Yes here. If those messages annoy you, disable them by selecting No.') |
|
|
); |
|
|
|
|
| 123 |
return system_settings_form($form); |
return system_settings_form($form); |
| 124 |
} |
} |