-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathassigned_bugs.php
executable file
·89 lines (75 loc) · 2.59 KB
/
assigned_bugs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* This script sends reminder emails to assignees of all open bugs.
*
* @category Reminder plugin
* @since 1.23
* @license http://www.gnu.org/licenses/gpl.html GPL
* @author Sam Wilson <sam@samwilson.id.au>
*/
# Make sure this script doesn't run via the webserver
if( php_sapi_name() != 'cli' ) {
echo "This script must be run from the command line.\n";
exit( 1 );
}
# Set up environment
require_once( dirname( __FILE__, 4 ) . DIRECTORY_SEPARATOR . 'core.php' );
$t_login = config_get( 'plugin_Reminder_reminder_login' );
auth_attempt_script_login( $t_login );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path.'email_api.php' );
# Build and bind query
$t_resolved = config_get( 'bug_resolved_status_threshold' );
$query = "SELECT DISTINCT bugs.id bug_id, bugs.summary, bugs.handler_id, users.realname, users.email "
." FROM {bug} bugs JOIN {user} users ON (bugs.handler_id = users.id) "
." WHERE status < ".db_param();
$t_rem_include = config_get('plugin_Reminder_reminder_include');
$t_rem_projects = "(";
$t_rem_projects .= config_get('plugin_Reminder_reminder_project_id');
$t_rem_projects .= ")";
if (ON==$t_rem_include){
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) {
$query .= " and bugs.project_id IN ". $t_rem_projects;
}
} else {
if (!empty( config_get( 'plugin_Reminder_reminder_project_id' ) )) {
$query .= " and bugs.project_id NOT IN ".$t_rem_projects;
}
}
$results = db_query( $query, array($t_resolved) );
if ( ! $results) {
echo 'Query failed.';
exit( 1 );
}
# Loop through all assigned bugs, building a list of what to email
$emails = array();
while ($row = db_fetch_array($results)) {
# New recipient
if ( ! isset($emails[$row['handler_id']])) {
$emails[$row['handler_id']] = array(
'recipient' => array(
'email' => $row['email'],
'name' => $row['realname'],
),
'bugs' => array(),
);
}
# Add current bug to this recipient's list
$emails[$row['handler_id']]['bugs'][$row['bug_id']] = $row['summary'];
}
# Construct and send emails
foreach ($emails as $email) {
# Build list of issues with summary and link
$list = '';
foreach ($email['bugs'] as $bug_id => $summary) {
$url = string_get_bug_view_url_with_fqdn( $bug_id );
$list .= " * $summary\n $url\n";
}
# Queue email for sending (and send it, if cron sending is disabled)
$message = "Assigned to ".$email['recipient']['name'].":\n\n$list\n";
$subject= config_get( 'plugin_Reminder_reminder_subject' );
email_store( $email['recipient']['email'], $subject, $message );
if( OFF == config_get( 'email_send_using_cronjob' ) ) {
email_send_all();
}
}