summaryrefslogtreecommitdiffstats
path: root/sanitycheck.cgi
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2008-06-14 18:15:22 +0200
committerlpsolit%gmail.com <>2008-06-14 18:15:22 +0200
commit1ad55bf5f14320795f3dae361b7bb0654c2c60d9 (patch)
treec99cc9eadc61f93a8810acb70de8fed0231ea02c /sanitycheck.cgi
parent7634b5f6cd563471fdeb9c9cb7ae101289a1b0de (diff)
downloadbugzilla-1ad55bf5f14320795f3dae361b7bb0654c2c60d9.tar.gz
bugzilla-1ad55bf5f14320795f3dae361b7bb0654c2c60d9.tar.xz
Bug 438810: Whines fail when a group or user that was receiving whines is manually deleted, and sanitycheck.cgi should report this problem - Patch by Frédéric Buclin <LpSolit@gmail.com> r/a=mkanat
Diffstat (limited to 'sanitycheck.cgi')
-rwxr-xr-xsanitycheck.cgi54
1 files changed, 54 insertions, 0 deletions
diff --git a/sanitycheck.cgi b/sanitycheck.cgi
index 171029b2e..93228fc67 100755
--- a/sanitycheck.cgi
+++ b/sanitycheck.cgi
@@ -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');
###########################################################################
@@ -996,6 +1026,30 @@ if (scalar(@$badbugs > 0)) {
}
###########################################################################
+# 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
###########################################################################