/[drupal]/contributions/modules/poormanscron/poormanscron.module
ViewVC logotype

Contents of /contributions/modules/poormanscron/poormanscron.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.22 - (show annotations) (download) (as text)
Tue Sep 29 22:28:04 2009 UTC (8 weeks, 2 days ago) by davereid
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.21: +5 -18 lines
File MIME type: text/x-php
by Dave Reid: Merging DRUPAL-6--1 branch into HEAD in preparation for the new DRUPAL-6--2 branch.
1 <?php
2 // $Id: poormanscron.module,v 1.21.2.2 2009/05/06 05:07:08 robloach Exp $ $Name: $
3
4 /**
5 * @file
6 * A module which runs Drupal cron jobs without the cron application.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function poormanscron_help($path, $arg) {
13 switch ($path) {
14 case 'admin/help#poormanscron':
15 return '<p>'. t('The Poormanscron module runs cron jobs without the need of the cron application.') .'</p>';
16 case 'admin/settings/poormanscron':
17 return '<p>'. t('The settings provided here allow you to administer Poormancron.') .'</p>';
18 }
19 }
20
21 /**
22 * Implementation of hook_exit().
23 *
24 * Checks if poormanscron needs to be run. If this is the case, it invokes
25 * the cron hooks of all enabled modules, which are executed after
26 * all HTML is returned to the browser. So the user who kicks off the cron
27 * jobs should not notice any delay.
28 */
29 function poormanscron_exit() {
30
31 // Calculate when the next poormanscron run is due.
32 $lastrun = variable_get('poormanscron_lastrun', 0);
33 $nextrun = $lastrun + 60 * variable_get('poormanscron_interval', 60);
34
35 // If the configured time has passed, start the next poormanscron run.
36 if (time() > $nextrun) {
37
38 // If this cron run fails to complete, wait a few minutes before retrying.
39 variable_set('poormanscron_lastrun',
40 $lastrun + 60 * variable_get('poormanscron_retry_interval', 10));
41
42 // Get the current Drupal messages. Use drupal_set_message() so that
43 // the messages aren't deleted in case the cron run fails and
44 // we don't get a chance to restore them below.
45 $saved_messages = drupal_set_message();
46
47 // Invoke the cron hooks of all enabled modules.
48 if (drupal_cron_run()) {
49 $message = 'Cron run completed (via poormanscron).';
50 }
51 else {
52 $message = 'Cron run unsuccessful (via poormanscron).';
53 }
54
55 // Write a message to the logs if the user wants us to do so.
56 if (variable_get('poormanscron_log_cron_runs', 1) == 1) {
57 watchdog('cron', $message);
58 }
59
60 $t = time();
61
62 // Update the time of the last poormanscron run (this one).
63 variable_set('poormanscron_lastrun', $t);
64
65 // Delete any messages added during the cron run (and existing prior
66 // messages).
67 drupal_get_messages();
68
69 // Restore any prior messages.
70 if (isset($saved_messages)) {
71 foreach ($saved_messages as $type => $types_messages) {
72 foreach ($types_messages as $message) {
73 drupal_set_message($message, $type);
74 }
75 }
76 }
77 }
78 }
79
80 /**
81 * Implmentation of hook_menu().
82 */
83 function poormanscron_menu() {
84 $items = array();
85 $items['admin/settings/poormanscron'] = array(
86 'title' => 'Poormanscron',
87 'description' => 'A module which runs Drupal cron jobs without the cron application.',
88 'page callback' => 'drupal_get_form',
89 'page arguments' => array('poormanscron_admin_settings'),
90 'access arguments' => array('administer site configuration'),
91 'file' => 'poormanscron.admin.inc',
92 );
93 return $items;
94 }

  ViewVC Help
Powered by ViewVC 1.1.2