From 79542d43011ee798f0b9b72976b6cb0ef033b84f Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Mon, 13 Jun 2011 20:14:01 -0700 Subject: Bug 660866: Allow editing of old "boolean chart" searches using the new "custom search" UI controls on the advanced search form. r=mkanat, a=mkanat (module owner) --- Bugzilla/Search.pm | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'Bugzilla/Search.pm') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 3ec5394b9..ffbc28f9f 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -719,6 +719,25 @@ sub search_description { return $self->{'search_description'}; } +sub boolean_charts_to_custom_search { + my ($self, $cgi_buffer) = @_; + my @as_params = $self->_boolean_charts->as_params; + + # We need to start our new ids after the last custom search "f" id. + # We can just pick the last id in the array because they are sorted + # numerically. + my $last_id = ($self->_field_ids)[-1]; + my $count = defined($last_id) ? $last_id + 1 : 0; + foreach my $param_set (@as_params) { + foreach my $name (keys %$param_set) { + my $value = $param_set->{$name}; + next if !defined $value; + $cgi_buffer->param($name . $count, $value); + } + $count++; + } +} + ###################### # Internal Accessors # ###################### @@ -1542,15 +1561,10 @@ sub _boolean_charts { sub _custom_search { my ($self) = @_; my $params = $self->_params; - my @param_list = keys %$params; - - my @field_params = grep { /^f\d+$/ } @param_list; - my @field_ids = map { /(\d+)/; $1 } @field_params; - @field_ids = sort { $a <=> $b } @field_ids; - + my $current_clause = new Bugzilla::Search::Clause($params->{j_top}); my @clause_stack; - foreach my $id (@field_ids) { + foreach my $id ($self->_field_ids) { my $field = $params->{"f$id"}; if ($field eq 'OP') { my $joiner = $params->{"j$id"}; @@ -1581,6 +1595,17 @@ sub _custom_search { return $clause_stack[0] || $current_clause; } +sub _field_ids { + my ($self) = @_; + my $params = $self->_params; + my @param_list = keys %$params; + + my @field_params = grep { /^f\d+$/ } @param_list; + my @field_ids = map { /(\d+)/; $1 } @field_params; + @field_ids = sort { $a <=> $b } @field_ids; + return @field_ids; +} + sub _handle_chart { my ($self, $chart_id, $condition) = @_; my $dbh = Bugzilla->dbh; -- cgit v1.2.3-24-g4f1b