summaryrefslogtreecommitdiffstats
path: root/extensions/RequestWhiner/bin
diff options
context:
space:
mode:
authorGervase Markham <written.to.the.glory.of.god@gerv.net>2011-11-07 22:10:18 +0100
committerDave Lawrence <dkl@mozilla.com>2011-11-07 22:10:18 +0100
commit05e14287f356c8f1308c339e9dbac83011940430 (patch)
treebc1eaa20639e20bf706392f9478ec713970d7f31 /extensions/RequestWhiner/bin
parent316d0ce36713e466c4958aba30eaf4f02b53379f (diff)
downloadbugzilla-05e14287f356c8f1308c339e9dbac83011940430.tar.gz
bugzilla-05e14287f356c8f1308c339e9dbac83011940430.tar.xz
Bug 682847 - Create request flag whining extension
r=dkl
Diffstat (limited to 'extensions/RequestWhiner/bin')
-rw-r--r--extensions/RequestWhiner/bin/whineatrequests.pl152
1 files changed, 152 insertions, 0 deletions
diff --git a/extensions/RequestWhiner/bin/whineatrequests.pl b/extensions/RequestWhiner/bin/whineatrequests.pl
new file mode 100644
index 000000000..622438b4f
--- /dev/null
+++ b/extensions/RequestWhiner/bin/whineatrequests.pl
@@ -0,0 +1,152 @@
+#!/usr/bin/perl -wT
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# 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.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Erik Stambaugh <erik@dasbistro.com>
+# Gervase Markham <gerv@gerv.net>
+
+use strict;
+
+BEGIN {
+ use lib qw(lib .);
+ use Bugzilla;
+ Bugzilla->extensions;
+}
+
+use lib qw(. lib);
+
+use Bugzilla;
+use Bugzilla::User;
+use Bugzilla::Mailer;
+use Bugzilla::Extension::RequestWhiner::Constants;
+
+my $dbh = Bugzilla->dbh;
+
+my $sth_get_requests =
+ $dbh->prepare("SELECT profiles.login_name,
+ flagtypes.name,
+ bugs.bug_id,
+ bugs.short_desc, " .
+ $dbh->sql_to_days('NOW()') .
+ " - " .
+ $dbh->sql_to_days('flags.modification_date') . "
+ AS age_in_days
+ FROM flags
+ JOIN bugs ON bugs.bug_id = flags.bug_id,
+ flagtypes,
+ profiles
+ WHERE flags.status = '?'
+ AND flags.requestee_id = profiles.userid
+ AND flags.type_id = flagtypes.id
+ AND " . $dbh->sql_to_days('NOW()') .
+ " - " .
+ $dbh->sql_to_days('flags.modification_date') .
+ " > " .
+ WHINE_AFTER_DAYS . "
+ ORDER BY flags.modification_date");
+
+$sth_get_requests->execute();
+
+# Build data structure
+my $requests = {};
+
+while (my ($login_name,
+ $flag_name,
+ $bug_id,
+ $short_desc,
+ $age_in_days) = $sth_get_requests->fetchrow_array())
+{
+ if (!defined($requests->{$login_name})) {
+ $requests->{$login_name} = {};
+ }
+
+ if (!defined($requests->{$login_name}->{$flag_name})) {
+ $requests->{$login_name}->{$flag_name} = [];
+ }
+
+ push(@{ $requests->{$login_name}->{$flag_name} }, {
+ id => $bug_id,
+ summary => $short_desc,
+ age => $age_in_days
+ });
+}
+
+$sth_get_requests->finish();
+
+foreach my $recipient (keys %$requests) {
+ my $user = new Bugzilla::User({ name => $recipient });
+
+ next if $user->email_disabled;
+
+ mail({
+ from => Bugzilla->params->{'mailfrom'},
+ recipient => $user,
+ subject => "Outstanding Requests",
+ requests => $requests->{$recipient},
+ threshold => WHINE_AFTER_DAYS
+ });
+}
+
+exit;
+
+###############################################################################
+# Functions
+#
+# Note: this function is exactly the same as the one in whine.pl, just using
+# different templates for the messages themselves.
+###############################################################################
+sub mail {
+ my $args = shift;
+ my $addressee = $args->{recipient};
+
+ my $template =
+ Bugzilla->template_inner($addressee->settings->{'lang'}->{'value'});
+ my $msg = ''; # it's a temporary variable to hold the template output
+ $args->{'alternatives'} ||= [];
+
+ # Put together the different multipart MIME segments
+ $template->process("requestwhiner/mail.txt.tmpl", $args, \$msg)
+ or die($template->error());
+ push @{$args->{'alternatives'}},
+ {
+ 'content' => $msg,
+ 'type' => 'text/plain',
+ };
+ $msg = '';
+
+ $template->process("requestwhiner/mail.html.tmpl", $args, \$msg)
+ or die($template->error());
+ push @{$args->{'alternatives'}},
+ {
+ 'content' => $msg,
+ 'type' => 'text/html',
+ };
+ $msg = '';
+
+ # Now produce a ready-to-mail MIME-encoded message
+ $args->{'boundary'} = "----------" . $$ . "--" . time() . "-----";
+
+ $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
+ or die($template->error());
+
+ MessageToMTA($msg);
+
+ delete $args->{'boundary'};
+ delete $args->{'alternatives'};
+}