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 => {
DELETE => 'CASCADE'}},
subject => {TYPE => 'varchar(128)'},
body => {TYPE => 'MEDIUMTEXT'},
mailifnobugs => {TYPE => 'BOOLEAN', NOTNULL => 1,
DEFAULT => 'FALSE'},
],
},
......
......@@ -564,6 +564,10 @@ sub update_table_definitions {
$dbh->bz_alter_column('group_control_map', 'canedit',
{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 #
################################################################
......
......@@ -143,20 +143,22 @@ if ($cgi->param('update')) {
$sth->execute($eventid, $userid);
}
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 $body = ($cgi->param("event_${eventid}_body") or '');
my $mailifnobugs = $cgi->param("event_${eventid}_mailifnobugs") ? 1 : 0;
trick_taint($subject) if $subject;
trick_taint($body) if $body;
if ( ($subject ne $events->{$eventid}->{'subject'})
|| ($mailifnobugs != $events->{$eventid}->{'mailifnobugs'})
|| ($body ne $events->{$eventid}->{'body'}) ) {
$sth = $dbh->prepare("UPDATE whine_events " .
"SET subject=?, body=? " .
"SET subject=?, body=?, mailifnobugs=? " .
"WHERE id=?");
$sth->execute($subject, $body, $eventid);
$sth->execute($subject, $body, $mailifnobugs, $eventid);
}
# add a schedule
......@@ -438,14 +440,15 @@ sub get_events {
my $dbh = Bugzilla->dbh;
my $events = {};
my $sth = $dbh->prepare("SELECT DISTINCT id, subject, body " .
my $sth = $dbh->prepare("SELECT DISTINCT id, subject, body, mailifnobugs " .
"FROM whine_events " .
"WHERE owner_userid=?");
$sth->execute($userid);
while (my ($ev, $sub, $bod) = $sth->fetchrow_array) {
while (my ($ev, $sub, $bod, $mno) = $sth->fetchrow_array) {
$events->{$ev} = {
'subject' => $sub || '',
'body' => $bod || '',
'mailifnobugs' => $mno || 0,
};
}
return $events;
......
......@@ -124,6 +124,16 @@
</td>
</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 %]
<tr>
......
......@@ -65,7 +65,8 @@ my $sth_next_scheduled_event = $dbh->prepare(
" whine_schedules.eventid, " .
" whine_events.owner_userid, " .
" whine_events.subject, " .
" whine_events.body " .
" whine_events.body, " .
" whine_events.mailifnobugs " .
"FROM whine_schedules " .
"LEFT JOIN whine_events " .
" ON whine_events.id = whine_schedules.eventid " .
......@@ -200,6 +201,7 @@ $sched_h->finish();
# users - array of user objects for recipients
# subject - Subject line for the email
# body - the text inserted above the bug lists
# mailifnobugs - send message even if there are no query or query results
sub get_next_event {
my $event = {};
......@@ -214,7 +216,7 @@ sub get_next_event {
my $fetched = $sth_next_scheduled_event->fetch;
$sth_next_scheduled_event->finish;
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);
......@@ -282,6 +284,7 @@ sub get_next_event {
'mailto' => \@users,
'subject' => $subject,
'body' => $body,
'mailifnobugs' => $mailifnobugs,
};
}
}
......@@ -296,6 +299,7 @@ sub get_next_event {
# mailto (array of user objects for mail targets)
# subject (subject line for 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) {
my $eventid = $event->{'eventid'};
......@@ -316,12 +320,14 @@ while (my $event = get_next_event) {
# run the queries for this schedule
my $queries = run_queries($args);
# check to make sure there is something to output
my $there_are_bugs = 0;
for my $query (@{$queries}) {
$there_are_bugs = 1 if scalar @{$query->{'bugs'}};
# If mailifnobugs is false, make sure there is something to output
if (!$event->{'mailifnobugs'}) {
my $there_are_bugs = 0;
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;
......
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