function cron_example_form_cron_run_submit in Examples for Developers 7
Allow user to directly execute cron, optionally forcing it.
Related topics
1 string reference to 'cron_example_form_cron_run_submit'
- cron_example_form in cron_example/
cron_example.module - The form to provide a link to cron.php.
File
- cron_example/
cron_example.module, line 128 - Demonstrates use of the Cron API in Drupal - hook_cron()
Code
function cron_example_form_cron_run_submit($form, &$form_state) {
if (!empty($form_state['values']['cron_reset'])) {
variable_set('cron_example_next_execution', 0);
}
// We don't usually use globals in this way. This is used here only to
// make it easy to tell if cron was run by this form.
$GLOBALS['cron_example_show_status_message'] = TRUE;
if (drupal_cron_run()) {
drupal_set_message(t('Cron ran successfully.'));
}
else {
drupal_set_message(t('Cron run failed.'), 'error');
}
}