summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Search
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-08 02:15:45 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-08 02:15:45 +0200
commitab04fe6c61b5fd55ca4b838ccb7abfd542bd2128 (patch)
tree8a0250608a9e1d566916a2576fcd3ef4464e6cf5 /Bugzilla/Search
parent8c9cd344c4153e9032e5c1b695bcfe9cb8144d80 (diff)
downloadbugzilla-ab04fe6c61b5fd55ca4b838ccb7abfd542bd2128.tar.gz
bugzilla-ab04fe6c61b5fd55ca4b838ccb7abfd542bd2128.tar.xz
Bug 577149: Make convert-workflow rename values in saved searches
r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla/Search')
-rw-r--r--Bugzilla/Search/Saved.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/Bugzilla/Search/Saved.pm b/Bugzilla/Search/Saved.pm
index cb6371469..32a24eae1 100644
--- a/Bugzilla/Search/Saved.pm
+++ b/Bugzilla/Search/Saved.pm
@@ -174,6 +174,37 @@ sub create {
return $obj;
}
+sub rename_field_value {
+ my ($class, $field, $old_value, $new_value) = @_;
+
+ my $old = url_quote($old_value);
+ my $new = url_quote($new_value);
+ my $old_sql = $old;
+ $old_sql =~ s/([_\%])/\\$1/g;
+
+ my $dbh = Bugzilla->dbh;
+ $dbh->bz_start_transaction();
+
+ my %queries = @{ $dbh->selectcol_arrayref(
+ "SELECT id, query FROM namedqueries WHERE query LIKE ?",
+ {Columns=>[1,2]}, "\%$old_sql\%") };
+ foreach my $id (keys %queries) {
+ my $query = $queries{$id};
+ $query =~ s/\b$field=\Q$old\E\b/$field=$new/gi;
+ # Fix boolean charts.
+ while ($query =~ /\bfield(\d+-\d+-\d+)=\Q$field\E\b/gi) {
+ my $chart_id = $1;
+ # Note that this won't handle lists or substrings inside of
+ # boolean charts. Users will have to fix those themselves.
+ $query =~ s/\bvalue\Q$chart_id\E=\Q$old\E\b/value$chart_id=$new/i;
+ }
+ $dbh->do("UPDATE namedqueries SET query = ? WHERE id = ?",
+ undef, $query, $id);
+ }
+
+ $dbh->bz_commit_transaction();
+}
+
sub preload {
my ($searches) = @_;
my $dbh = Bugzilla->dbh;