Skip to content

Commit

Permalink
Merge branch '4.2/cf-is-null-warnings' into 4.2-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmv committed Jun 13, 2014
2 parents cb16284 + f9a0394 commit 55c6d2a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 25 deletions.
48 changes: 25 additions & 23 deletions lib/RT/SearchBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,31 @@ sub _LimitCustomField {
return %args;
};

# Special Limit (we can exit early)
# IS NULL and IS NOT NULL checks
if ( $op =~ /^IS( NOT)?$/i ) {
my ($ocfvalias, $CFs) = $self->_CustomFieldJoin( $cfkey, $cf, $ltype );
$self->_OpenParen( $args{SUBCLAUSE} );
$self->Limit(
%args,
ALIAS => $ocfvalias,
FIELD => ($column || 'id'),
OPERATOR => $op,
VALUE => $value,
);
# See below for an explanation of this limit
$self->Limit(
ALIAS => $CFs,
FIELD => 'Name',
OPERATOR => 'IS NOT',
VALUE => 'NULL',
ENTRYAGGREGATOR => 'AND',
SUBCLAUSE => $args{SUBCLAUSE},
) if $CFs;
$self->_CloseParen( $args{SUBCLAUSE} );
return;
}

########## Content pre-parsing if we know things about the CF
if ( blessed($cf) and delete $args{PREPARSE} ) {
my $type = $cf->Type;
Expand Down Expand Up @@ -652,29 +677,6 @@ sub _LimitCustomField {
}

########## Limits
# IS NULL and IS NOT NULL checks
if ( $op =~ /^IS( NOT)?$/i ) {
my ($ocfvalias, $CFs) = $self->_CustomFieldJoin( $cfkey, $cf, $ltype );
$self->_OpenParen( $args{SUBCLAUSE} );
$self->Limit(
%args,
ALIAS => $ocfvalias,
FIELD => ($column || 'id'),
OPERATOR => $op,
VALUE => $value,
);
# See below for an explanation of this limit
$self->Limit(
ALIAS => $CFs,
FIELD => 'Name',
OPERATOR => 'IS NOT',
VALUE => 'NULL',
ENTRYAGGREGATOR => 'AND',
SUBCLAUSE => $args{SUBCLAUSE},
) if $CFs;
$self->_CloseParen( $args{SUBCLAUSE} );
return;
}

my $single_value = !blessed($cf) || $cf->SingleValue;
my $negative_op = ($op eq '!=' || $op =~ /\bNOT\b/i);
Expand Down
25 changes: 24 additions & 1 deletion t/customfields/date_search.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use Test::MockTime qw(set_fixed_time restore_time);
use warnings;
use strict;

use RT::Test nodata => 1, tests => 21;
use RT::Test nodata => 1, tests => undef;

RT::Test->set_rights(
{ Principal => 'Everyone', Right => [qw(
Expand Down Expand Up @@ -134,6 +134,28 @@ is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' );
}

{
my $tickets = RT::Tickets->new(RT->SystemUser);
$tickets->LimitCustomField(
CUSTOMFIELD => $cf->id,
OPERATOR => 'IS',
VALUE => 'NULL',
);

is( $tickets->Count, 0, 'did not find the ticket with date IS NULL' );
}

{
my $tickets = RT::Tickets->new(RT->SystemUser);
$tickets->LimitCustomField(
CUSTOMFIELD => $cf->id,
OPERATOR => 'IS NOT',
VALUE => 'NULL',
);

is( $tickets->Count, 1, 'did find the ticket with date IS NOT NULL' );
}

# relative search by users in different TZs
{
my $ticket = RT::Ticket->new(RT->SystemUser);
Expand Down Expand Up @@ -164,3 +186,4 @@ is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
is( $tickets->Count, 1, 'found the tickets' );
}

done_testing;
26 changes: 25 additions & 1 deletion t/customfields/datetime_search.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use Test::MockTime qw(set_fixed_time restore_time);
use warnings;
use strict;

use RT::Test nodata => 1, tests => 30;
use RT::Test nodata => 1, tests => undef;
RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00

RT::Test->set_rights(
Expand Down Expand Up @@ -206,6 +206,29 @@ while( my $ticket = $tickets->Next ) {
is( $tickets->Count, 0);
}

{
my $tickets = RT::Tickets->new(RT->SystemUser);
$tickets->LimitCustomField(
CUSTOMFIELD => $cf->id,
OPERATOR => 'IS',
VALUE => 'NULL',
);

is( $tickets->Count, 0, 'did not find the ticket with date IS NULL' );
}

{
my $tickets = RT::Tickets->new(RT->SystemUser);
$tickets->LimitCustomField(
CUSTOMFIELD => $cf->id,
OPERATOR => 'IS NOT',
VALUE => 'NULL',
);

is( $tickets->Count, 2, 'did find the ticket with date IS NOT NULL' );
}


# search by relative date with '=', but date only
{
my $ticket = RT::Ticket->new(RT->SystemUser);
Expand Down Expand Up @@ -237,3 +260,4 @@ while( my $ticket = $tickets->Next ) {
is( $tickets->Count, 0);
}

done_testing;

0 comments on commit 55c6d2a

Please sign in to comment.