whineatnews.pl 2.67 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 34

require "globals.pl";

35
use Bugzilla;
36
use Bugzilla::Mailer;
37
use Bugzilla::Util;
38

39 40 41
# Whining is disabled if whinedays is zero
exit unless Param('whinedays') >= 1;

42
my $dbh = Bugzilla->dbh;
43 44 45 46 47 48 49 50 51
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 = ?)
                 AND } . $dbh->sql_to_days('NOW()') . " - " .
                       $dbh->sql_to_days('delta_ts') . " > " .
                       Param('whinedays') .
          " ORDER BY bug_id";
52 53

my %bugs;
54
my %desc;
55

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

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


my $template = Param('whinemail');
my $urlbase = Param('urlbase');
73
my $emailsuffix = Param('emailsuffix');
74 75 76

foreach my $email (sort (keys %bugs)) {
    my %substs;
77
    $substs{'email'} = $email . $emailsuffix;
78
    $substs{'userid'} = $email;
79
    my $msg = perform_substs($template, \%substs);
80 81

    foreach my $i (@{$bugs{$email}}) {
82 83
        $msg .= "  " . shift(@{$desc{$email}}) . "\n";
        $msg .= "    -> ${urlbase}show_bug.cgi?id=$i\n";
84
    }
85

86
    MessageToMTA($msg);
87

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