Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / whineatnews.pl
blob39361fa45fc4ca78fa841f1af800935d9dd274d1
1 #!/usr/bin/env perl -w
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Netscape Communications
17 # Corporation. Portions created by Netscape are
18 # Copyright (C) 1998 Netscape Communications Corporation. All
19 # Rights Reserved.
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
22 # Joseph Heenan <joseph@heenan.me.uk>
23 # Frédéric Buclin <LpSolit@gmail.com>
26 # This is a script suitable for running once a day from a cron job. It
27 # looks at all the bugs, and sends whiny mail to anyone who has a bug
28 # assigned to them that has status NEW or REOPENED that has not been
29 # touched for more than the number of days specified in the whinedays param.
31 use strict;
32 use lib qw(. lib);
34 use Bugzilla;
35 use Bugzilla::Mailer;
36 use Bugzilla::Util;
37 use Bugzilla::User;
39 # Whining is disabled if whinedays is zero
40 exit unless Bugzilla->params->{'whinedays'} >= 1;
42 my $dbh = Bugzilla->dbh;
43 my $query = q{SELECT bug_id, short_desc, login_name
44 FROM bugs
45 INNER JOIN profiles
46 ON userid = assigned_to
47 WHERE (bug_status = ? OR bug_status = ?)
48 AND disable_mail = 0
49 AND } . $dbh->sql_to_days('NOW()') . " - " .
50 $dbh->sql_to_days('delta_ts') . " > " .
51 Bugzilla->params->{'whinedays'} .
52 " ORDER BY bug_id";
54 my %bugs;
55 my %desc;
57 my $slt_bugs = $dbh->selectall_arrayref($query, undef, 'NEW', 'REOPENED');
59 foreach my $bug (@$slt_bugs) {
60 my ($id, $desc, $email) = @$bug;
61 if (!defined $bugs{$email}) {
62 $bugs{$email} = [];
64 if (!defined $desc{$email}) {
65 $desc{$email} = [];
67 push @{$bugs{$email}}, $id;
68 push @{$desc{$email}}, $desc;
72 foreach my $email (sort (keys %bugs)) {
73 my $user = new Bugzilla::User({name => $email});
74 next if $user->email_disabled;
76 my $vars = {'email' => $email};
78 my @bugs = ();
79 foreach my $i (@{$bugs{$email}}) {
80 my $bug = {};
81 $bug->{'summary'} = shift(@{$desc{$email}});
82 $bug->{'id'} = $i;
83 push @bugs, $bug;
85 $vars->{'bugs'} = \@bugs;
87 my $msg;
88 my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
89 $template->process("email/whine.txt.tmpl", $vars, \$msg)
90 or die($template->error());
92 Bugzilla->template_inner("");
93 MessageToMTA($msg);
95 print "$email " . join(" ", @{$bugs{$email}}) . "\n";