whineatnews.pl 2.69 KB
Newer Older
1
#!/usr/bin/perl -w
2 3
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
4 5 6 7 8 9 10 11 12 13
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
16
# The Initial Developer of the Original Code is Netscape Communications
17 18 19 20
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
#                 Joseph Heenan <joseph@heenan.me.uk>
23 24 25 26


# 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 
27
# assigned to them that has status NEW or REOPENED that has not been 
28
# touched for more than the number of days specified in the whinedays param.
29 30

use strict;
31
use lib '.';
32

33
use Bugzilla;
34
use Bugzilla::Mailer;
35
use Bugzilla::Util;
36

37
# Whining is disabled if whinedays is zero
38
exit unless Bugzilla->params->{'whinedays'} >= 1;
39

40
my $dbh = Bugzilla->dbh;
41 42 43 44 45
my $query = q{SELECT bug_id, short_desc, login_name
                FROM bugs
          INNER JOIN profiles
                  ON userid = assigned_to
               WHERE (bug_status = ? OR bug_status = ?)
46
                 AND disable_mail = 0
47 48
                 AND } . $dbh->sql_to_days('NOW()') . " - " .
                       $dbh->sql_to_days('delta_ts') . " > " .
49
                       Bugzilla->params->{'whinedays'} .
50
          " ORDER BY bug_id";
51 52

my %bugs;
53
my %desc;
54

55 56 57 58
my $slt_bugs = $dbh->selectall_arrayref($query, undef, 'NEW', 'REOPENED');

foreach my $bug (@$slt_bugs) {
    my ($id, $desc, $email) = @$bug;
59 60 61
    if (!defined $bugs{$email}) {
        $bugs{$email} = [];
    }
62 63 64
    if (!defined $desc{$email}) {
        $desc{$email} = [];
    }
65
    push @{$bugs{$email}}, $id;
66
    push @{$desc{$email}}, $desc;
67 68 69 70
}


foreach my $email (sort (keys %bugs)) {
71 72 73
    my $vars = {
        'email' => $email
    };
74

75
    my @bugs = ();
76
    foreach my $i (@{$bugs{$email}}) {
77 78 79 80
        my $bug = {};
        $bug->{'summary'} = shift(@{$desc{$email}});
        $bug->{'id'} = $i;
        push @bugs, $bug;
81
    }
82 83 84 85 86
    $vars->{'bugs'} = \@bugs;

    my $msg;
    my $template = Bugzilla->template;
    $template->process("email/whine.txt.tmpl", $vars, \$msg);
87

88
    MessageToMTA($msg);
89

90 91
    print "$email      " . join(" ", @{$bugs{$email}}) . "\n";
}