whineatnews.pl 2.46 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 31 32 33

use strict;

require "globals.pl";

34 35
use Bugzilla::BugMail;

36
my $dbh = Bugzilla->dbh;
37 38 39 40 41 42 43
SendSQL("SELECT bug_id, short_desc, login_name " .
        "FROM bugs INNER JOIN profiles ON userid = assigned_to " .
        "WHERE (bug_status = 'NEW' OR bug_status = 'REOPENED') " .
        "AND " . $dbh->sql_to_days('NOW()') . " - " .
                 $dbh->sql_to_days('delta_ts') . " > " .
                 Param('whinedays') . " " .
        "ORDER BY bug_id");
44 45

my %bugs;
46
my %desc;
47 48 49
my @row;

while (@row = FetchSQLData()) {
50
    my ($id, $desc, $email) = (@row);
51 52 53
    if (!defined $bugs{$email}) {
        $bugs{$email} = [];
    }
54 55 56
    if (!defined $desc{$email}) {
        $desc{$email} = [];
    }
57
    push @{$bugs{$email}}, $id;
58
    push @{$desc{$email}}, $desc;
59 60 61 62 63
}


my $template = Param('whinemail');
my $urlbase = Param('urlbase');
64
my $emailsuffix = Param('emailsuffix');
65 66 67

foreach my $email (sort (keys %bugs)) {
    my %substs;
68
    $substs{'email'} = $email . $emailsuffix;
69
    $substs{'userid'} = $email;
70 71 72
    my $msg = PerformSubsts($template, \%substs);

    foreach my $i (@{$bugs{$email}}) {
73 74
        $msg .= "  " . shift(@{$desc{$email}}) . "\n";
        $msg .= "    -> ${urlbase}show_bug.cgi?id=$i\n";
75
    }
76

77 78
    Bugzilla::BugMail::MessageToMTA($msg);

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