]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 302420: Allow whining messages to be sent even without any results - Patch by...
authorwicked%sci.fi <>
Mon, 6 Apr 2009 20:57:13 +0000 (20:57 +0000)
committerwicked%sci.fi <>
Mon, 6 Apr 2009 20:57:13 +0000 (20:57 +0000)
Bugzilla/DB/Schema.pm
Bugzilla/Install/DB.pm
editwhines.cgi
template/en/default/whine/schedule.html.tmpl
whine.pl

index fc4361d1758e993e358780b231a48587493c0c34..aacbe386b2a41209256954ca8dbc559f27f35f11 100644 (file)
@@ -1334,6 +1334,8 @@ use constant ABSTRACT_SCHEMA => {
                                             DELETE => 'CASCADE'}},
             subject      => {TYPE => 'varchar(128)'},
             body         => {TYPE => 'MEDIUMTEXT'},
+            mailifnobugs => {TYPE => 'BOOLEAN', NOTNULL => 1,
+                             DEFAULT => 'FALSE'},
         ],
     },
 
index de1d48361d863bdc18cf9c77f694b96dbfade04c..2247e58b398934b938d69bedcb8d3081873c597f 100644 (file)
@@ -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 #
     ################################################################
index 06717fe2c5f586a3b09c4df8643b6078875e933f..37f52349ed570853f881dccb97b44e452a5844ee 100755 (executable)
@@ -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;
index 6fe19957bf88ce4d4be5ddbdcd1908864b07fe7f..245a3e4a96a7cf5b8596ed3fdbfaf3b8ae1691ae 100644 (file)
     </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>
index 3eb757dd4d154c46bebfdd82930937dfa52f422f..36cf9c5af065bf20f840cdfd769ff20b183133b8 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -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;