]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Patch for bug 274428: Make checksetup.pl fixup flagtypes with spaces or commas; patch...
authorjocuri%softhome.net <>
Tue, 14 Dec 2004 09:27:52 +0000 (09:27 +0000)
committerjocuri%softhome.net <>
Tue, 14 Dec 2004 09:27:52 +0000 (09:27 +0000)
checksetup.pl

index b158caf6460e8d921e0984453b7934805d25f10b..1eaf0618f0a05e59bd2d250d3041b95889085de8 100755 (executable)
@@ -3747,6 +3747,54 @@ if (TableExists("attachstatuses") && TableExists("attachstatusdefs")) {
     print "done.\n";
 }
 
+# 2004-12-13 Nick.Barnes@pobox.com bug 262268
+# Check flag type names for spaces and commas, and rename them.
+if (TableExists("flagtypes")) {
+    print "Checking flag type names for spaces and commas...\n";
+    
+    # Get names and IDs which are broken.
+    $sth = $dbh->prepare("SELECT name, id FROM flagtypes");
+    $sth->execute();
+
+    my %flagtypes;
+    my @badflagnames;
+    
+    while (my ($name, $id) = $sth->fetchrow_array()) {
+        $flagtypes{$name} = $id;
+        if ($name =~ /[ ,]/) {
+            push(@badflagnames, $name);
+        }
+    }
+    if (@badflagnames) {
+        my ($flagname, $tryflagname);
+        my $sth = $dbh->prepare("UPDATE flagtypes SET name = ? WHERE id = ?");
+        foreach $flagname (@badflagnames) {
+            print "  Bad flag type name \"$flagname\" ...\n";
+            ($tryflagname = $flagname) =~ tr/ ,/__/;
+            while (defined($flagtypes{$tryflagname})) {
+                print "  ... can't rename as \"$tryflagname\" ...\n";
+                $tryflagname .= "'";
+                if (length($tryflagname) > 50) {
+                    my $lastchanceflagname = (substr $tryflagname, 0, 47) . '...';
+                    if (defined($flagtypes{$lastchanceflagname})) {
+                        print "  ... last attempt as \"$lastchanceflagname\" still failed.'\n";
+                        print "Rename the flag by hand and run checksetup.pl again.\n";
+                        die("Bad flag type name $flagname");
+                    }
+                    $tryflagname = $lastchanceflagname;
+                }
+            }
+            $sth->execute($tryflagname, $flagtypes{$flagname});
+            print "  renamed flag type \"$flagname\" as \"$tryflagname\"\n";
+            $flagtypes{$tryflagname} = $flagtypes{$flagname};
+            delete $flagtypes{$flagname};
+        }
+        print "... done.\n";
+    } else {
+        print "... all flag type names are good.\n";
+    }
+}
+
 # 2002-11-24 - bugreport@peshkin.net - bug 147275 
 #
 # If group_control_map is empty, backward-compatbility