]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 438810: Whines fail when a group or user that was receiving whines is manually...
authorlpsolit%gmail.com <>
Sat, 14 Jun 2008 16:22:24 +0000 (16:22 +0000)
committerlpsolit%gmail.com <>
Sat, 14 Jun 2008 16:22:24 +0000 (16:22 +0000)
sanitycheck.cgi
template/en/default/admin/sanitycheck/messages.html.tmpl

index 171029b2ed91f4426bed9d8d632700af98ea9127..93228fc67dd03e5134e1ddd3b3428487e235c167 100755 (executable)
@@ -341,6 +341,36 @@ if ($cgi->param('remove_invalid_attach_references')) {
     Status('attachment_reference_deletion_end');
 }
 
+###########################################################################
+# Remove all references to deleted users or groups from whines
+###########################################################################
+
+if ($cgi->param('remove_old_whine_targets')) {
+    Status('whines_obsolete_target_deletion_start');
+
+    $dbh->bz_start_transaction();
+
+    foreach my $target (['groups', 'id', MAILTO_GROUP],
+                        ['profiles', 'userid', MAILTO_USER])
+    {
+        my ($table, $col, $type) = @$target;
+        my $old_ids =
+          $dbh->selectcol_arrayref("SELECT DISTINCT mailto
+                                      FROM whine_schedules
+                                 LEFT JOIN $table
+                                        ON $table.$col = whine_schedules.mailto
+                                     WHERE mailto_type = $type AND $table.$col IS NULL");
+
+        if (scalar(@$old_ids)) {
+            $dbh->do("DELETE FROM whine_schedules
+                       WHERE mailto_type = $type AND mailto IN (" .
+                       join(',', @$old_ids) . ")");
+        }
+    }
+    $dbh->bz_commit_transaction();
+    Status('whines_obsolete_target_deletion_end');
+}
+
 Status('checks_start');
 
 ###########################################################################
@@ -995,6 +1025,30 @@ if (scalar(@$badbugs > 0)) {
     Status('unsent_bugmail_fix');
 }
 
+###########################################################################
+# Whines
+###########################################################################
+
+Status('whines_obsolete_target_start');
+
+my $display_repair_whines_link = 0;
+foreach my $target (['groups', 'id', MAILTO_GROUP],
+                    ['profiles', 'userid', MAILTO_USER])
+{
+    my ($table, $col, $type) = @$target;
+    my $old = $dbh->selectall_arrayref("SELECT whine_schedules.id, mailto
+                                          FROM whine_schedules
+                                     LEFT JOIN $table
+                                            ON $table.$col = whine_schedules.mailto
+                                         WHERE mailto_type = $type AND $table.$col IS NULL");
+
+    if (scalar(@$old)) {
+        Status('whines_obsolete_target_alert', {schedules => $old, type => $type}, 'alert');
+        $display_repair_whines_link = 1;
+    }
+}
+Status('whines_obsolete_target_fix') if $display_repair_whines_link;
+
 ###########################################################################
 # End
 ###########################################################################
index 4300f7815481e80401b0dc0e1cbad42516f1035d..d33c12040c7cc1f4fe43756ec7a48375fc90b8cf 100644 (file)
   [% ELSIF san_tag == "vote_count_alert" %]
     Bad vote sum for [% terms.bug %] [%+ id FILTER html %].
 
+  [% ELSIF san_tag == "whines_obsolete_target_deletion_start" %]
+    OK, now removing non-existent users/groups from whines.
+
+  [% ELSIF san_tag == "whines_obsolete_target_deletion_end" %]
+    Non-existent users/groups have been removed from whines.
+
+  [% ELSIF san_tag == "whines_obsolete_target_start" %]
+    Checking for whines with non-existent users/groups.
+
+  [% ELSIF san_tag == "whines_obsolete_target_alert" %]
+    [% FOREACH schedule = schedules %]
+      Non-existent [% (type == constants.MAILTO_USER) ? "user" : "group" FILTER html %]
+      [%+ schedule.1 FILTER html %] for whine schedule [% schedule.0 FILTER html %]<br>
+    [% END %]
+
+  [% ELSIF san_tag == "whines_obsolete_target_fix" %]
+    <a href="sanitycheck.cgi?remove_old_whine_targets=1">Click here to
+    remove old users/groups</a>
+
   [% END %]
 [% END %]