| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: cron.inc,v 1.6 2009/03/21 18:50:18 thehunmonkgroup Exp $ 3 4 5 /** 6 * @file 7 * Contains the code required during cron runs for periodic functionality. 8 * 9 * This code is either invoked via hook_cron() or project-issue-cron.php 10 * depending on the value of the 'project_issue_hook_cron' variable. 11 */ 12 13 /** 14 * Private helper function to run periodic functionality. 15 * 16 * This code is either invoked by hook_cron() or via project-issue-cron.php 17 * depending on the value of the 'project_issue_hook_cron' variable. It is 18 * responsible for auto-closing issues, and sending email digests and 19 * reminders. 20 * 21 * @see project_issue_cron() 22 */ 23 function _project_issue_cron() { 24 if (time() - variable_get('project_issue_digest_last', 0) > variable_get('project_issue_digest_interval', 7 * 24 * 60 * 60)) { 25 variable_set('project_issue_digest_last', time()); 26 project_mail_digest(); 27 } 28 29 if (time() - variable_get('project_issue_reminder_last', 0) > variable_get('project_issue_reminder_interval', 28 * 7 * 24 * 60 * 60)) { 30 variable_set('project_issue_reminder_last', time()); 31 project_mail_reminder(); 32 } 33 34 // Auto-close fixed issues; 35 project_issue_auto_close(); 36 } 37 38 /** 39 * Automatically close issues marked as fixed for a specified number of days 40 * and add a comment to each documenting the change. 41 */ 42 function project_issue_auto_close() { 43 // Set query parameters. 44 $auto_close_days = variable_get('project_issue_auto_close_days', PROJECT_ISSUE_AUTO_CLOSE_DAYS); 45 $seconds = 24 * 60 * 60 * $auto_close_days; 46 47 $comment = theme('project_issue_auto_close_message', $auto_close_days); 48 $result = db_query('SELECT pi.nid FROM {project_issues} pi INNER JOIN {node} n ON n.nid = pi.nid WHERE pi.sid = %d AND n.changed < %d', PROJECT_ISSUE_STATE_FIXED, time() - $seconds); 49 while ($issue = db_fetch_object($result)) { 50 project_issue_add_auto_followup(array( 51 'nid' => $issue->nid, 52 'sid' => PROJECT_ISSUE_STATE_CLOSED, 53 'comment' => $comment, 54 'followup_no_mail' => TRUE, // Temporary hack to get around sending of auto-close emails. 55 )); 56 } 57 } 58 59 function project_mail_reminder() { 60 61 if (defined('PROJECT_NOMAIL')) { 62 return; 63 } 64 65 $projects = array(); 66 $result = db_query(db_rewrite_sql('SELECT p.nid, n.title FROM {project_issue_projects} p INNER JOIN {node} n ON p.nid = n.nid WHERE p.mail_reminder = 1 AND n.status = 1', 'p')); 67 while ($project = db_fetch_object($result)) { 68 $projects[$project->nid] = $project->title; 69 } 70 71 if (!empty($projects)) { 72 // Note: We can INNER JOIN on {users} on uid = p.assigned since there's 73 // still a record in {users} for uid 0 (anonymous), so we'll still get a 74 // (bogus) value, even if the issue is unassigned. 75 $pids = array_keys($projects); 76 $placeholders = db_placeholders($pids); 77 $result = db_query(db_rewrite_sql("SELECT p.nid, n.*, p.*, u.name, u.mail, u.language, u2.name AS assigned_name FROM {project_issues} p INNER JOIN {node} n ON p.nid = n.nid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {users} u2 ON u2.uid = p.assigned WHERE n.status = 1 AND u.status = 1 AND p.pid IN ($placeholders) AND u.mail <> '' AND (p.sid = 1 OR p.sid = 2) ORDER BY u.uid, p.pid, p.component, p.sid, n.changed DESC", 'p'), $pids); 78 79 $body = $mail = $pid = NULL; 80 81 // TODO: This logic sucks, is inefficient, and is fragile. It'd be nice 82 // to rewrite this someday when I have more time to not be so crazy. -dww 83 while (($node = db_fetch_object($result)) || !empty($body)) { 84 85 // If we already have a message we're planning to send, and either we 86 // ran out of issues, or the e-mail address of the user changed 87 // (different user's issues), send out what we've got already. 88 if ($body && $mail && ((!$node) || ($mail != $node->mail))) { 89 $params['body'] = $body; 90 drupal_mail('project_issue', 'project_issue_reminder', $mail, $language, $params); 91 $body = ''; 92 } 93 94 if ($node) { 95 // If this is a new project, a new component, or a new user, start a 96 // new banner to indicate what this issue belongs to. 97 if ($pid != $node->pid || $component != $node->component || $mail != $node->mail) { 98 $pid = $node->pid; 99 $component = $node->component; 100 $banner = "$projects[$pid] / $component"; 101 $body .= "[ $banner ]". str_repeat('=', 72 - 4 - strlen($banner)) ."\n"; 102 } 103 $body .= "$node->title\n"; 104 if ($node->assigned) { 105 $body .= " assigned: $node->assigned_name\n"; 106 } 107 $body .= ' state: '. project_issue_state($node->sid) ."\n"; 108 $body .= ' age: '. format_interval(time() - $node->created) ."\n"; 109 $body .= ' url: '. url("node/$node->nid", array('absolute' => TRUE)) ."\n"; 110 $body .= "\n"; 111 112 // Remember the e-mail and language of this issue's user so that when 113 // we next decide to send what we've got, we'll have the right values. 114 $mail = $node->mail; 115 // We can pass $node here because user_preferred_language() 116 // only needs $account->language to function, and we have that 117 // loaded into the $node object. 118 $language = user_preferred_language($node); 119 } 120 } 121 } 122 } 123 124 function project_mail_digest() { 125 if (defined('PROJECT_NOMAIL')) { 126 return; 127 } 128 129 $projects = db_query(db_rewrite_sql("SELECT n.nid, n.title, p.*, u.language FROM {node} n INNER JOIN {project_issue_projects} p ON n.nid = p.nid INNER JOIN {users} u ON u.uid = n.uid WHERE n.status = 1 AND p.mail_digest <> '' ORDER BY n.title, p.mail_digest")); 130 131 while ($project = db_fetch_object($projects)) { 132 $category = ''; 133 $body = ''; 134 $issues = db_query(db_rewrite_sql('SELECT p.nid, n.title, n.created, p.sid, p.category, p.component, p.priority, p.assigned, u.name AS assigned_name FROM {project_issues} p INNER JOIN {node} n ON p.nid = n.nid INNER JOIN {users} u ON u.uid = p.assigned WHERE n.status = 1 AND p.pid = %d AND p.sid = 1 AND p.priority = 1 ORDER BY p.category, n.created DESC', 'p'), $project->nid); 135 while ($node = db_fetch_object($issues)) { 136 if ($category != $node->category) { 137 $category = $node->category; 138 $banner = "$project->title / ". project_issue_category($node->category); 139 $body .= "$banner\n". str_repeat('-', $banner) ."\n"; 140 } 141 $body .= "$node->title\n"; 142 if ($node->assigned) { 143 $body .= ' assigned: '. $node->assigned_name ."\n"; 144 } 145 $body .= ' age: '. format_interval(time() - $node->created) ."\n"; 146 $body .= ' url: '. url("node/$node->nid", array('absolute' => TRUE)) ."\n"; 147 $body .= "\n"; 148 } 149 150 if (!empty($body)) { 151 // We can pass $project here because user_preferred_language() 152 // only needs $account->language to function, and we have that 153 // loaded into the $project object. 154 $language = user_preferred_language($project); 155 $mailto = $project->mail_digest; 156 $params['project'] = $project; 157 $params['body'] = $body; 158 drupal_mail('project_issue', 'project_issue_critical_summary', $mailto, $language, $params, $mailto); 159 } 160 } 161 } 162
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |