whineatnews.pl 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env perl -w
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  4. # The contents of this file are subject to the Mozilla Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is the Bugzilla Bug Tracking System.
  15. #
  16. # The Initial Developer of the Original Code is Netscape Communications
  17. # Corporation. Portions created by Netscape are
  18. # Copyright (C) 1998 Netscape Communications Corporation. All
  19. # Rights Reserved.
  20. #
  21. # Contributor(s): Terry Weissman <terry@mozilla.org>
  22. # Joseph Heenan <joseph@heenan.me.uk>
  23. # Frédéric Buclin <LpSolit@gmail.com>
  24. # This is a script suitable for running once a day from a cron job. It
  25. # looks at all the bugs, and sends whiny mail to anyone who has a bug
  26. # assigned to them that has status NEW or REOPENED that has not been
  27. # touched for more than the number of days specified in the whinedays param.
  28. use strict;
  29. use lib qw(. lib);
  30. use Bugzilla;
  31. use Bugzilla::Mailer;
  32. use Bugzilla::Util;
  33. use Bugzilla::User;
  34. # Whining is disabled if whinedays is zero
  35. exit unless Bugzilla->params->{'whinedays'} >= 1;
  36. my $dbh = Bugzilla->dbh;
  37. my $query = q{SELECT bug_id, short_desc, login_name
  38. FROM bugs
  39. INNER JOIN profiles
  40. ON userid = assigned_to
  41. WHERE (bug_status = ? OR bug_status = ?)
  42. AND disable_mail = 0
  43. AND } . $dbh->sql_to_days('NOW()') . " - " .
  44. $dbh->sql_to_days('delta_ts') . " > " .
  45. Bugzilla->params->{'whinedays'} .
  46. " ORDER BY bug_id";
  47. my %bugs;
  48. my %desc;
  49. my $slt_bugs = $dbh->selectall_arrayref($query, undef, 'NEW', 'REOPENED');
  50. foreach my $bug (@$slt_bugs) {
  51. my ($id, $desc, $email) = @$bug;
  52. if (!defined $bugs{$email}) {
  53. $bugs{$email} = [];
  54. }
  55. if (!defined $desc{$email}) {
  56. $desc{$email} = [];
  57. }
  58. push @{$bugs{$email}}, $id;
  59. push @{$desc{$email}}, $desc;
  60. }
  61. foreach my $email (sort (keys %bugs)) {
  62. my $user = new Bugzilla::User({name => $email});
  63. next if $user->email_disabled;
  64. my $vars = {'email' => $email};
  65. my @bugs = ();
  66. foreach my $i (@{$bugs{$email}}) {
  67. my $bug = {};
  68. $bug->{'summary'} = shift(@{$desc{$email}});
  69. $bug->{'id'} = $i;
  70. push @bugs, $bug;
  71. }
  72. $vars->{'bugs'} = \@bugs;
  73. my $msg;
  74. my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
  75. $template->process("email/whine.txt.tmpl", $vars, \$msg)
  76. or die($template->error());
  77. Bugzilla->template_inner("");
  78. MessageToMTA($msg);
  79. print "$email " . join(" ", @{$bugs{$email}}) . "\n";
  80. }