/[drupal]/contributions/modules/signup/includes/cron.inc
ViewVC logotype

Contents of /contributions/modules/signup/includes/cron.inc

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


Revision 1.3 - (show annotations) (download) (as text)
Fri Aug 14 23:26:00 2009 UTC (3 months, 2 weeks ago) by dww
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
#549646 by dww: Exposed signup-related node and signup data to token.module.
1 <?php
2 // $Id: cron.inc,v 1.2 2008/12/20 04:28:06 dww Exp $
3
4
5 /**
6 * @file
7 * Code required during regular cron runs.
8 */
9
10 /**
11 * Helper function that sends cron-based reminder e-mails.
12 *
13 * Invokes the method for the installed event/date backend module to get the
14 * right query fragments, and builds a query to find all nodes that need a
15 * reminder email. For each one, it loops over the users signed up for that
16 * node and send off the emails.
17 *
18 * @see signup_cron()
19 * @see signup_reminder_sql()
20 * @see _signup_build_query()
21 */
22 function _signup_cron_send_reminders() {
23 $type_reminder_sql = array();
24 foreach (signup_content_types() as $type) {
25 $type_sql = signup_reminder_sql($type);
26 if (!empty($type_sql)) {
27 $type_reminder_sql[$type] = $type_sql;
28 }
29 }
30 if (empty($type_reminder_sql)) {
31 // No node types support reminder emails, so bail out now.
32 return;
33 }
34
35 $reminder_common_sql = array(
36 'primary' => '{node} n',
37 'fields' => array('n.title', 'n.nid', 'n.type', 's.reminder_email', 's.forwarding_email'),
38 'where' => array('s.send_reminder = 1', "n.type = '%s'"),
39 'joins' => array('INNER JOIN {signup} s ON s.nid = n.nid'),
40 );
41
42 $from = variable_get('site_mail', ini_get('sendmail_from'));
43
44 foreach ($type_reminder_sql as $type => $reminder_sql) {
45 $sql = _signup_build_query($reminder_common_sql, $reminder_sql);
46 $result = db_query($sql, $type);
47
48 // Grab each node, construct the email header and subject, and query
49 // the signup log to pull all users who are signed up for this node.
50 while ($node = db_fetch_object($result)) {
51 $subject = t('!node_type reminder: !title', array('!node_type' => node_get_types('name', $type), '!title' => $node->title));
52 $signups = db_query("SELECT u.name, u.mail, s_l.sid, s_l.anon_mail, s_l.form_data FROM {signup_log} s_l INNER JOIN {users} u ON u.uid = s_l.uid WHERE s_l.nid = %d", $node->nid);
53
54 // Loop through the users, composing their customized message
55 // and sending the email.
56 while ($signup = db_fetch_object($signups)) {
57 $user_mail = _signup_get_email($signup);
58 $params = array(
59 'subject' => $subject,
60 'body' => $node->reminder_email,
61 'node' => $node,
62 'signup' => $signup,
63 );
64 if (module_exists('token')) {
65 $params['body'] = token_replace_multiple($params['body'], array('node' => node_load($node->nid), 'signup' => $signup, 'global' => NULL));
66 }
67 $language = user_preferred_language($signup);
68 drupal_mail('signup', 'signup_reminder_mail', $user_mail, $language, $params, $from);
69 watchdog('signup', 'Reminder for %title sent to %user_mail.', array('%title' => $node->title, '%user_mail' => $user_mail), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
70 }
71
72 // Reminders for this node are all sent, so mark it in the
73 // database so they're not sent again.
74 db_query("UPDATE {signup} SET send_reminder = 0 WHERE nid = %d", $node->nid);
75 }
76 }
77 }
78
79 /**
80 * Helper function that handles auto-closing time-based nodes during cron.
81 *
82 * Loops over all the node types that are signup-enabled. For each one, it
83 * invokes the method for the installed event/date backend module to get the
84 * right query fragments, and builds a query to find all nodes of that type
85 * where signups should be closed (e.g. events that already started, etc).
86 *
87 * @see signup_cron()
88 * @see signup_autoclose_sql()
89 * @see _signup_build_query()
90 */
91 function _signup_cron_autoclose() {
92 $type_autoclose_sql = array();
93 foreach (signup_content_types() as $type) {
94 $type_sql = signup_autoclose_sql($type);
95 if (!empty($type_sql)) {
96 $type_autoclose_sql[$type] = $type_sql;
97 }
98 }
99 if (empty($type_autoclose_sql)) {
100 // No node types support auto-close, so bail out now.
101 return;
102 }
103
104 $autoclose_common_sql = array(
105 'primary' => '{node} n',
106 'fields' => array('n.nid', 'n.type'),
107 'where' => array('s.status = 1', "n.type = '%s'"),
108 'joins' => array('INNER JOIN {signup} s ON s.nid = n.nid'),
109 );
110
111 foreach ($type_autoclose_sql as $type => $autoclose_sql) {
112 $sql = _signup_build_query($autoclose_common_sql, $autoclose_sql);
113 $result = db_query($sql, $type);
114
115 // Loop through the results, calling the signup closing function.
116 while ($signup = db_fetch_object($result)) {
117 signup_close_signup($signup->nid, $cron = 'yes');
118 $node = node_load($signup->nid);
119 foreach (module_implements('signup_close') as $module) {
120 $function = $module .'_signup_close';
121 $function($node);
122 }
123 watchdog('signup', 'Signups closed for %title by cron.', array('%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
124 }
125 }
126 }
127

  ViewVC Help
Powered by ViewVC 1.1.2