Commit 0665a744 authored by wicked%sci.fi's avatar wicked%sci.fi

Bug 302420: Allow whining messages to be sent even without any results - Patch…

Bug 302420: Allow whining messages to be sent even without any results - Patch by Micheal J. Tosh <michael.j.tosh@lmco.com> r=wicked a=mkanat
parent 1633d983
...@@ -1334,6 +1334,8 @@ use constant ABSTRACT_SCHEMA => { ...@@ -1334,6 +1334,8 @@ use constant ABSTRACT_SCHEMA => {
DELETE => 'CASCADE'}}, DELETE => 'CASCADE'}},
subject => {TYPE => 'varchar(128)'}, subject => {TYPE => 'varchar(128)'},
body => {TYPE => 'MEDIUMTEXT'}, body => {TYPE => 'MEDIUMTEXT'},
mailifnobugs => {TYPE => 'BOOLEAN', NOTNULL => 1,
DEFAULT => 'FALSE'},
], ],
}, },
......
...@@ -564,6 +564,10 @@ sub update_table_definitions { ...@@ -564,6 +564,10 @@ sub update_table_definitions {
$dbh->bz_alter_column('group_control_map', 'canedit', $dbh->bz_alter_column('group_control_map', 'canedit',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'}); {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
# 2009-01-16 oreomike@gmail.com - Bug 302420
$dbh->bz_add_column('whine_events', 'mailifnobugs',
{ TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'});
################################################################ ################################################################
# New --TABLE-- changes should go *** A B O V E *** this point # # New --TABLE-- changes should go *** A B O V E *** this point #
################################################################ ################################################################
......
...@@ -143,20 +143,22 @@ if ($cgi->param('update')) { ...@@ -143,20 +143,22 @@ if ($cgi->param('update')) {
$sth->execute($eventid, $userid); $sth->execute($eventid, $userid);
} }
else { else {
# check the subject and body for changes # check the subject, body and mailifnobugs for changes
my $subject = ($cgi->param("event_${eventid}_subject") or ''); my $subject = ($cgi->param("event_${eventid}_subject") or '');
my $body = ($cgi->param("event_${eventid}_body") or ''); my $body = ($cgi->param("event_${eventid}_body") or '');
my $mailifnobugs = $cgi->param("event_${eventid}_mailifnobugs") ? 1 : 0;
trick_taint($subject) if $subject; trick_taint($subject) if $subject;
trick_taint($body) if $body; trick_taint($body) if $body;
if ( ($subject ne $events->{$eventid}->{'subject'}) if ( ($subject ne $events->{$eventid}->{'subject'})
|| ($mailifnobugs != $events->{$eventid}->{'mailifnobugs'})
|| ($body ne $events->{$eventid}->{'body'}) ) { || ($body ne $events->{$eventid}->{'body'}) ) {
$sth = $dbh->prepare("UPDATE whine_events " . $sth = $dbh->prepare("UPDATE whine_events " .
"SET subject=?, body=? " . "SET subject=?, body=?, mailifnobugs=? " .
"WHERE id=?"); "WHERE id=?");
$sth->execute($subject, $body, $eventid); $sth->execute($subject, $body, $mailifnobugs, $eventid);
} }
# add a schedule # add a schedule
...@@ -438,14 +440,15 @@ sub get_events { ...@@ -438,14 +440,15 @@ sub get_events {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $events = {}; my $events = {};
my $sth = $dbh->prepare("SELECT DISTINCT id, subject, body " . my $sth = $dbh->prepare("SELECT DISTINCT id, subject, body, mailifnobugs " .
"FROM whine_events " . "FROM whine_events " .
"WHERE owner_userid=?"); "WHERE owner_userid=?");
$sth->execute($userid); $sth->execute($userid);
while (my ($ev, $sub, $bod) = $sth->fetchrow_array) { while (my ($ev, $sub, $bod, $mno) = $sth->fetchrow_array) {
$events->{$ev} = { $events->{$ev} = {
'subject' => $sub || '', 'subject' => $sub || '',
'body' => $bod || '', 'body' => $bod || '',
'mailifnobugs' => $mno || 0,
}; };
} }
return $events; return $events;
......
...@@ -124,6 +124,16 @@ ...@@ -124,6 +124,16 @@
</td> </td>
</tr> </tr>
<tr>
<td valign="top" align="right">
Send a message even if there are no [% terms.bugs %] in the search result:
</td>
<td colspan="2">
<input type="checkbox" name="event_[% event.key %]_mailifnobugs"
[%- IF event.value.mailifnobugs == 1 %] checked [% END %]>
</td>
</tr>
[% IF event.value.schedule.size == 0 %] [% IF event.value.schedule.size == 0 %]
<tr> <tr>
......
...@@ -65,7 +65,8 @@ my $sth_next_scheduled_event = $dbh->prepare( ...@@ -65,7 +65,8 @@ my $sth_next_scheduled_event = $dbh->prepare(
" whine_schedules.eventid, " . " whine_schedules.eventid, " .
" whine_events.owner_userid, " . " whine_events.owner_userid, " .
" whine_events.subject, " . " whine_events.subject, " .
" whine_events.body " . " whine_events.body, " .
" whine_events.mailifnobugs " .
"FROM whine_schedules " . "FROM whine_schedules " .
"LEFT JOIN whine_events " . "LEFT JOIN whine_events " .
" ON whine_events.id = whine_schedules.eventid " . " ON whine_events.id = whine_schedules.eventid " .
...@@ -200,6 +201,7 @@ $sched_h->finish(); ...@@ -200,6 +201,7 @@ $sched_h->finish();
# users - array of user objects for recipients # users - array of user objects for recipients
# subject - Subject line for the email # subject - Subject line for the email
# body - the text inserted above the bug lists # body - the text inserted above the bug lists
# mailifnobugs - send message even if there are no query or query results
sub get_next_event { sub get_next_event {
my $event = {}; my $event = {};
...@@ -214,7 +216,7 @@ sub get_next_event { ...@@ -214,7 +216,7 @@ sub get_next_event {
my $fetched = $sth_next_scheduled_event->fetch; my $fetched = $sth_next_scheduled_event->fetch;
$sth_next_scheduled_event->finish; $sth_next_scheduled_event->finish;
return undef unless $fetched; return undef unless $fetched;
my ($eventid, $owner_id, $subject, $body) = @{$fetched}; my ($eventid, $owner_id, $subject, $body, $mailifnobugs) = @{$fetched};
my $owner = Bugzilla::User->new($owner_id); my $owner = Bugzilla::User->new($owner_id);
...@@ -282,6 +284,7 @@ sub get_next_event { ...@@ -282,6 +284,7 @@ sub get_next_event {
'mailto' => \@users, 'mailto' => \@users,
'subject' => $subject, 'subject' => $subject,
'body' => $body, 'body' => $body,
'mailifnobugs' => $mailifnobugs,
}; };
} }
} }
...@@ -296,6 +299,7 @@ sub get_next_event { ...@@ -296,6 +299,7 @@ sub get_next_event {
# mailto (array of user objects for mail targets) # mailto (array of user objects for mail targets)
# subject (subject line for message) # subject (subject line for message)
# body (text blurb at top of message) # body (text blurb at top of message)
# mailifnobugs (send message even if there are no query or query results)
while (my $event = get_next_event) { while (my $event = get_next_event) {
my $eventid = $event->{'eventid'}; my $eventid = $event->{'eventid'};
...@@ -316,12 +320,14 @@ while (my $event = get_next_event) { ...@@ -316,12 +320,14 @@ while (my $event = get_next_event) {
# run the queries for this schedule # run the queries for this schedule
my $queries = run_queries($args); my $queries = run_queries($args);
# check to make sure there is something to output # If mailifnobugs is false, make sure there is something to output
my $there_are_bugs = 0; if (!$event->{'mailifnobugs'}) {
for my $query (@{$queries}) { my $there_are_bugs = 0;
$there_are_bugs = 1 if scalar @{$query->{'bugs'}}; for my $query (@{$queries}) {
$there_are_bugs = 1 if scalar @{$query->{'bugs'}};
}
next unless $there_are_bugs;
} }
next unless $there_are_bugs;
$args->{'queries'} = $queries; $args->{'queries'} = $queries;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment