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 { ...@@ -110,7 +110,6 @@ sub new {
sub canonicalise_query { sub canonicalise_query {
my ($self, @exclude) = @_; my ($self, @exclude) = @_;
$self->convert_old_params();
# Reconstruct the URL by concatenating the sorted param=value pairs # Reconstruct the URL by concatenating the sorted param=value pairs
my @parameters; my @parameters;
foreach my $key (sort($self->param())) { foreach my $key (sort($self->param())) {
...@@ -135,17 +134,6 @@ sub canonicalise_query { ...@@ -135,17 +134,6 @@ sub canonicalise_query {
return join("&", @parameters); 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 { sub clean_search_url {
my $self = shift; my $self = shift;
# Delete any empty URL parameter. # Delete any empty URL parameter.
......
...@@ -849,7 +849,7 @@ my @orderstrings = split(/,\s*/, $order); ...@@ -849,7 +849,7 @@ my @orderstrings = split(/,\s*/, $order);
# Generate the basic SQL query that will be used to generate the bug list. # Generate the basic SQL query that will be used to generate the bug list.
my $search = new Bugzilla::Search('fields' => \@selectcolumns, my $search = new Bugzilla::Search('fields' => \@selectcolumns,
'params' => $params, 'params' => scalar $params->Vars,
'order' => \@orderstrings); 'order' => \@orderstrings);
my $query = $search->sql; my $query = $search->sql;
$vars->{'search_description'} = $search->search_description; $vars->{'search_description'} = $search->search_description;
......
...@@ -509,7 +509,7 @@ sub CollectSeriesData { ...@@ -509,7 +509,7 @@ sub CollectSeriesData {
# Do not die if Search->new() detects invalid data, such as an obsolete # Do not die if Search->new() detects invalid data, such as an obsolete
# login name or a renamed product or component, etc. # login name or a renamed product or component, etc.
eval { eval {
my $search = new Bugzilla::Search('params' => $cgi, my $search = new Bugzilla::Search('params' => scalar $cgi->Vars,
'fields' => ["bug_id"], 'fields' => ["bug_id"],
'user' => $user); 'user' => $user);
my $sql = $search->sql; my $sql = $search->sql;
......
...@@ -127,7 +127,7 @@ my @axis_fields = ($row_field || EMPTY_COLUMN, ...@@ -127,7 +127,7 @@ my @axis_fields = ($row_field || EMPTY_COLUMN,
# Clone the params, so that Bugzilla::Search can modify them # Clone the params, so that Bugzilla::Search can modify them
my $params = new Bugzilla::CGI($cgi); my $params = new Bugzilla::CGI($cgi);
my $search = new Bugzilla::Search('fields' => \@axis_fields, my $search = new Bugzilla::Search('fields' => \@axis_fields,
'params' => $params); 'params' => scalar $params->Vars);
my $query = $search->sql; my $query = $search->sql;
$::SIG{TERM} = 'DEFAULT'; $::SIG{TERM} = 'DEFAULT';
......
...@@ -446,7 +446,7 @@ sub run_queries { ...@@ -446,7 +446,7 @@ sub run_queries {
my $searchparams = new Bugzilla::CGI($savedquery); my $searchparams = new Bugzilla::CGI($savedquery);
my $search = new Bugzilla::Search( my $search = new Bugzilla::Search(
'fields' => \@searchfields, 'fields' => \@searchfields,
'params' => $searchparams, 'params' => scalar $searchparams->Vars,
'user' => $args->{'recipient'}, # the search runs as the recipient 'user' => $args->{'recipient'}, # the search runs as the recipient
); );
my $sqlquery = $search->sql; my $sqlquery = $search->sql;
......
...@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::AndTest; ...@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::AndTest;
use base qw(Bugzilla::Test::Search::OrTest); use base qw(Bugzilla::Test::Search::OrTest);
use Bugzilla::Test::Search::Constants; use Bugzilla::Test::Search::Constants;
use Bugzilla::Test::Search::FakeCGI;
use List::MoreUtils qw(all); use List::MoreUtils qw(all);
use constant type => 'AND'; use constant type => 'AND';
...@@ -55,15 +54,15 @@ sub _join_broken_constant { {} } ...@@ -55,15 +54,15 @@ sub _join_broken_constant { {} }
sub search_params { sub search_params {
my ($self) = @_; my ($self) = @_;
my @all_params = map { $_->search_params } $self->field_tests; my @all_params = map { $_->search_params } $self->field_tests;
my $params = new Bugzilla::Test::Search::FakeCGI; my %params;
my $chart = 0; my $chart = 0;
foreach my $item (@all_params) { foreach my $item (@all_params) {
$params->param("field0-$chart-0", $item->param('field0-0-0')); $params{"field0-$chart-0"} = $item->{'field0-0-0'};
$params->param("type0-$chart-0", $item->param('type0-0-0')); $params{"type0-$chart-0"} = $item->{'type0-0-0'};
$params->param("value0-$chart-0", $item->param('value0-0-0')); $params{"value0-$chart-0"} = $item->{'value0-0-0'};
$chart++; $chart++;
} }
return $params; return \%params;
} }
1; 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; ...@@ -26,7 +26,6 @@ package Bugzilla::Test::Search::FieldTest;
use strict; use strict;
use warnings; use warnings;
use Bugzilla::Test::Search::FakeCGI;
use Bugzilla::Search; use Bugzilla::Search;
use Bugzilla::Test::Search::Constants; use Bugzilla::Test::Search::Constants;
...@@ -278,19 +277,16 @@ sub join_broken { ...@@ -278,19 +277,16 @@ sub join_broken {
# The CGI object that will get passed to Bugzilla::Search as its arguments. # The CGI object that will get passed to Bugzilla::Search as its arguments.
sub search_params { sub search_params {
my $self = shift; my ($self) = @_;
return $self->{search_params} if $self->{search_params}; return $self->{search_params} if $self->{search_params};
my $field = $self->field; my %params = (
my $operator = $self->operator; "field0-0-0" => $self->field,
my $value = $self->translated_value; "type0-0-0" => $self->operator,
"value0-0-0" => $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);
$self->{search_params} = $cgi; $self->{search_params} = \%params;
return $self->{search_params}; return $self->{search_params};
} }
......
...@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::OrTest; ...@@ -25,7 +25,6 @@ package Bugzilla::Test::Search::OrTest;
use base qw(Bugzilla::Test::Search::FieldTest); use base qw(Bugzilla::Test::Search::FieldTest);
use Bugzilla::Test::Search::Constants; use Bugzilla::Test::Search::Constants;
use Bugzilla::Test::Search::FakeCGI;
use List::MoreUtils qw(any uniq); use List::MoreUtils qw(any uniq);
use constant type => 'OR'; use constant type => 'OR';
...@@ -172,15 +171,15 @@ sub search_columns { ...@@ -172,15 +171,15 @@ sub search_columns {
sub search_params { sub search_params {
my ($self) = @_; my ($self) = @_;
my @all_params = map { $_->search_params } $self->field_tests; my @all_params = map { $_->search_params } $self->field_tests;
my $params = new Bugzilla::Test::Search::FakeCGI; my %params;
my $chart = 0; my $chart = 0;
foreach my $item (@all_params) { foreach my $item (@all_params) {
$params->param("field0-0-$chart", $item->param('field0-0-0')); $params{"field0-0-$chart"} = $item->{'field0-0-0'};
$params->param("type0-0-$chart", $item->param('type0-0-0')); $params{"type0-0-$chart"} = $item->{'type0-0-0'};
$params->param("value0-0-$chart", $item->param('value0-0-0')); $params{"value0-0-$chart"} = $item->{'value0-0-0'};
$chart++; $chart++;
} }
return $params; return \%params;
} }
1; 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