whineatnews.pl 2.43 KB
Newer Older
1
#!/usr/bin/perl -w
2 3 4
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
#
6 7
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
8 9 10 11


# This is a script suitable for running once a day from a cron job.  It 
# looks at all the bugs, and sends whiny mail to anyone who has a bug 
12 13 14 15
# assigned to them that has status CONFIRMED, NEW, or REOPENED that has not
# been touched for more than the number of days specified in the whinedays
# param. (We have NEW and REOPENED in there to keep compatibility with old
# Bugzillas.)
16 17

use strict;
18
use lib qw(. lib);
19

20
use Bugzilla;
21
use Bugzilla::Mailer;
22
use Bugzilla::Util;
23
use Bugzilla::User;
24

25
# Whining is disabled if whinedays is zero
26
exit unless Bugzilla->params->{'whinedays'} >= 1;
27

28
my $dbh = Bugzilla->dbh;
29 30 31 32
my $query = q{SELECT bug_id, short_desc, login_name
                FROM bugs
          INNER JOIN profiles
                  ON userid = assigned_to
33
               WHERE bug_status IN (?,?,?)
34
                 AND disable_mail = 0
35 36
                 AND } . $dbh->sql_to_days('NOW()') . " - " .
                       $dbh->sql_to_days('delta_ts') . " > " .
37
                       Bugzilla->params->{'whinedays'} .
38
          " ORDER BY bug_id";
39 40

my %bugs;
41
my %desc;
42

43 44
my $slt_bugs = $dbh->selectall_arrayref($query, undef, 'CONFIRMED', 'NEW',
                                                       'REOPENED');
45 46 47

foreach my $bug (@$slt_bugs) {
    my ($id, $desc, $email) = @$bug;
48 49 50
    if (!defined $bugs{$email}) {
        $bugs{$email} = [];
    }
51 52 53
    if (!defined $desc{$email}) {
        $desc{$email} = [];
    }
54
    push @{$bugs{$email}}, $id;
55
    push @{$desc{$email}}, $desc;
56 57 58 59
}


foreach my $email (sort (keys %bugs)) {
60
    my $user = new Bugzilla::User({name => $email});
61
    next if $user->email_disabled;
62 63

    my $vars = {'email' => $email};
64

65
    my @bugs = ();
66
    foreach my $i (@{$bugs{$email}}) {
67 68 69 70
        my $bug = {};
        $bug->{'summary'} = shift(@{$desc{$email}});
        $bug->{'id'} = $i;
        push @bugs, $bug;
71
    }
72 73 74
    $vars->{'bugs'} = \@bugs;

    my $msg;
75
    my $template = Bugzilla->template_inner($user->setting('lang'));
76 77
    $template->process("email/whine.txt.tmpl", $vars, \$msg)
      or die($template->error());
78

79
    MessageToMTA($msg);
80

81
    say "$email      " . join(" ", @{$bugs{$email}});
82
}