Commit dbaf1c3a authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 398308: Make Search.pm take a hashref for its "params" argument

instead of taking a CGI object. r=mkanat, a=mkanat (module owner)
parent 6a2a01fb
......@@ -110,7 +110,6 @@ sub new {
sub canonicalise_query {
my ($self, @exclude) = @_;
$self->convert_old_params();
# Reconstruct the URL by concatenating the sorted param=value pairs
my @parameters;
foreach my $key (sort($self->param())) {
......@@ -135,17 +134,6 @@ sub canonicalise_query {
return join("&", @parameters);
}
sub convert_old_params {
my $self = shift;
# bugidtype is now bug_id_type.
if ($self->param('bugidtype')) {
my $value = $self->param('bugidtype') eq 'exclude' ? 'nowords' : 'anyexact';
$self->param('bug_id_type', $value);
$self->delete('bugidtype');
}
}
sub clean_search_url {
my $self = shift;
# Delete any empty URL parameter.
......
......@@ -849,7 +849,7 @@ my @orderstrings = split(/,\s*/, $order);
# Generate the basic SQL query that will be used to generate the bug list.
my $search = new Bugzilla::Search('fields' => \@selectcolumns,
'params' => $params,
'params' => scalar $params->Vars,
'order' => \@orderstrings);
my $query = $search->sql;
$vars->{'search_description'} = $search->search_description;
......
......@@ -509,7 +509,7 @@ sub CollectSeriesData {
# Do not die if Search->new() detects invalid data, such as an obsolete
# login name or a renamed product or component, etc.
eval {
my $search = new Bugzilla::Search('params' => $cgi,
my $search = new Bugzilla::Search('params' => scalar $cgi->Vars,
'fields' => ["bug_id"],
'user' => $user);
my $sql = $search->sql;
......
......@@ -127,7 +127,7 @@ my @axis_fields = ($row_field || EMPTY_COLUMN,
# Clone the params, so that Bugzilla::Search can modify them
my $params = new Bugzilla::CGI($cgi);
my $search = new Bugzilla::Search('fields' => \@axis_fields,
'params' => $params);
'params' => scalar $params->Vars);
my $query = $search->sql;
$::SIG{TERM} = 'DEFAULT';
......
......@@ -446,7 +446,7 @@ sub run_queries {
my $searchparams = new Bugzilla::CGI($savedquery);
my $search = new Bugzilla::Search(
'fields' => \@searchfields,
'params' => $searchparams,
'params' => scalar $searchparams->Vars,
'user' => $args->{'recipient'}, # the search runs as the recipient
);
my $sqlquery = $search->sql;
......
......@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::AndTest;
use base qw(Bugzilla::Test::Search::OrTest);
use Bugzilla::Test::Search::Constants;
use Bugzilla::Test::Search::FakeCGI;
use List::MoreUtils qw(all);
use constant type => 'AND';
......@@ -55,15 +54,15 @@ sub _join_broken_constant { {} }
sub search_params {
my ($self) = @_;
my @all_params = map { $_->search_params } $self->field_tests;
my $params = new Bugzilla::Test::Search::FakeCGI;
my %params;
my $chart = 0;
foreach my $item (@all_params) {
$params->param("field0-$chart-0", $item->param('field0-0-0'));
$params->param("type0-$chart-0", $item->param('type0-0-0'));
$params->param("value0-$chart-0", $item->param('value0-0-0'));
$params{"field0-$chart-0"} = $item->{'field0-0-0'};
$params{"type0-$chart-0"} = $item->{'type0-0-0'};
$params{"value0-$chart-0"} = $item->{'value0-0-0'};
$chart++;
}
return $params;
return \%params;
}
1;
\ No newline at end of file
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Everything Solved, Inc.
# Portions created by the Initial Developer are Copyright (C) 2010 the
# Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Max Kanat-Alexander <mkanat@bugzilla.org>
# Calling CGI::param over and over turned out to be one of the slowest
# parts of search.t. So we create a simpler thing here that just supports
# "param" in a fast way.
package Bugzilla::Test::Search::FakeCGI;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub param {
my ($self, $name, @values) = @_;
if (!defined $name) {
return keys %$self;
}
if (@values) {
if (ref $values[0] eq 'ARRAY') {
$self->{$name} = $values[0];
}
else {
$self->{$name} = \@values;
}
}
return () if !exists $self->{$name};
my $item = $self->{$name};
return wantarray ? @{ $item || [] } : $item->[0];
}
sub delete {
my ($self, $name) = @_;
delete $self->{$name};
}
# We don't need to do this, because we don't use old params in search.t.
sub convert_old_params {}
1;
\ No newline at end of file
......@@ -26,7 +26,6 @@ package Bugzilla::Test::Search::FieldTest;
use strict;
use warnings;
use Bugzilla::Test::Search::FakeCGI;
use Bugzilla::Search;
use Bugzilla::Test::Search::Constants;
......@@ -278,19 +277,16 @@ sub join_broken {
# The CGI object that will get passed to Bugzilla::Search as its arguments.
sub search_params {
my $self = shift;
my ($self) = @_;
return $self->{search_params} if $self->{search_params};
my $field = $self->field;
my $operator = $self->operator;
my $value = $self->translated_value;
my $cgi = new Bugzilla::Test::Search::FakeCGI;
$cgi->param("field0-0-0", $field);
$cgi->param('type0-0-0', $operator);
$cgi->param('value0-0-0', $value);
my %params = (
"field0-0-0" => $self->field,
"type0-0-0" => $self->operator,
"value0-0-0" => $self->translated_value,
);
$self->{search_params} = $cgi;
$self->{search_params} = \%params;
return $self->{search_params};
}
......
......@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::OrTest;
use base qw(Bugzilla::Test::Search::FieldTest);
use Bugzilla::Test::Search::Constants;
use Bugzilla::Test::Search::FakeCGI;
use List::MoreUtils qw(any uniq);
use constant type => 'OR';
......@@ -172,15 +171,15 @@ sub search_columns {
sub search_params {
my ($self) = @_;
my @all_params = map { $_->search_params } $self->field_tests;
my $params = new Bugzilla::Test::Search::FakeCGI;
my %params;
my $chart = 0;
foreach my $item (@all_params) {
$params->param("field0-0-$chart", $item->param('field0-0-0'));
$params->param("type0-0-$chart", $item->param('type0-0-0'));
$params->param("value0-0-$chart", $item->param('value0-0-0'));
$params{"field0-0-$chart"} = $item->{'field0-0-0'};
$params{"type0-0-$chart"} = $item->{'type0-0-0'};
$params{"value0-0-$chart"} = $item->{'value0-0-0'};
$chart++;
}
return $params;
return \%params;
}
1;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment