X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FTickets_Overlay_SQL.pm;h=4531a16908db839a7f95ec4c74bc23c462e03fc3;hp=6773917026fda998858c615083d69927e4e60832;hb=ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4;hpb=d4d0590bef31071e8809ec046717444b95b3f30a diff --git a/rt/lib/RT/Tickets_Overlay_SQL.pm b/rt/lib/RT/Tickets_Overlay_SQL.pm index 677391702..4531a1690 100644 --- a/rt/lib/RT/Tickets_Overlay_SQL.pm +++ b/rt/lib/RT/Tickets_Overlay_SQL.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -22,7 +22,9 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/copyleft/gpl.html. # # # CONTRIBUTION SUBMISSION POLICY: @@ -51,12 +53,12 @@ use warnings; # Import configuration data from the lexcial scope of __PACKAGE__ (or # at least where those two Subroutines are defined.) -my %FIELDS = %{FIELDS()}; +my %FIELD_METADATA = %{FIELDS()}; my %dispatch = %{dispatch()}; my %can_bundle = %{can_bundle()}; # Lower Case version of FIELDS, for case insensitivity -my %lcfields = map { ( lc($_) => $_ ) } (keys %FIELDS); +my %lcfields = map { ( lc($_) => $_ ) } (keys %FIELD_METADATA); sub _InitSQL { my $self = shift; @@ -85,11 +87,13 @@ sub _InitSQL { sub _SQLLimit { my $self = shift; my %args = (@_); - if ($args{'FIELD'} eq 'EffectiveId') { + if ($args{'FIELD'} eq 'EffectiveId' && + (!$args{'ALIAS'} || $args{'ALIAS'} eq 'main' ) ) { $self->{'looking_at_effective_id'} = 1; } - if ($args{'FIELD'} eq 'Type') { + if ($args{'FIELD'} eq 'Type' && + (!$args{'ALIAS'} || $args{'ALIAS'} eq 'main' ) ) { $self->{'looking_at_type'} = 1; } @@ -288,7 +292,7 @@ sub _parser { # print "$ea Key=[$key] op=[$op] val=[$val]\n"; - my $subkey; + my $subkey = ''; if ($key =~ /^(.+?)\.(.+)$/) { $key = $1; $subkey = $2; @@ -297,7 +301,7 @@ sub _parser { my $class; if (exists $lcfields{lc $key}) { $key = $lcfields{lc $key}; - $class = $FIELDS{$key}->[0]; + $class = $FIELD_METADATA{$key}->[0]; } # no longer have a default, since CF's are now a real class, not fallthrough # fixme: "default class" is not Generic. @@ -377,11 +381,11 @@ sub ClausesToSQL { my $first = 1; # Build SQL from the data hash - for my $data ( @{ $clauses->{$f} } ) { - $sql .= $data->[0] unless $first; $first=0; - $sql .= " '". $data->[2] . "' "; - $sql .= $data->[3] . " "; - $sql .= "'". $data->[4] . "' "; + for my $data ( @{ $clauses->{$f} } ) { + $sql .= $data->[0] unless $first; $first=0; # ENTRYAGGREGATOR + $sql .= " '". $data->[2] . "' "; # FIELD + $sql .= $data->[3] . " "; # OPERATOR + $sql .= "'". $data->[4] . "' "; # VALUE } push @sql, " ( " . $sql . " ) "; @@ -401,63 +405,66 @@ failure. =begin testing use RT::Tickets; - - +use strict; my $tix = RT::Tickets->new($RT::SystemUser); +{ + my $query = "Status = 'open'"; + my ($status, $msg) = $tix->FromSQL($query); + ok ($status, "correct query") or diag("error: $msg"); +} -my $query = "Status = 'open'"; -my ($id, $msg) = $tix->FromSQL($query); - -ok ($id, $msg); - - -my (@ids, @expectedids); - -my $t = RT::Ticket->new($RT::SystemUser); +my (@created,%created); my $string = 'subject/content SQL test'; -ok( $t->Create(Queue => 'General', Subject => $string), "Ticket Created"); - -push @ids, $t->Id; - -my $Message = MIME::Entity->build( - Subject => 'this is my subject', - From => 'jesse@example.com', - Data => [ $string ], - ); - -ok( $t->Create(Queue => 'General', Subject => 'another ticket', MIMEObj => $Message, MemberOf => $ids[0]), "Ticket Created"); - -push @ids, $t->Id; - -$query = ("Subject LIKE '$string' OR Content LIKE '$string'"); - -my ($id, $msg) = $tix->FromSQL($query); - - -ok ($id, $msg); - -is ($tix->Count, scalar @ids, "number of returned tickets same as entered"); -while (my $tick = $tix->Next) { - push @expectedids, $tick->Id; +{ + my $t = RT::Ticket->new($RT::SystemUser); + ok( $t->Create(Queue => 'General', Subject => $string), "Ticket Created"); + $created{ $t->Id }++; push @created, $t->Id; } -ok (eq_array(\@ids, \@expectedids), "returned expected tickets"); -$query = ("id = $ids[0] OR MemberOf = $ids[0]"); +{ + my $Message = MIME::Entity->build( + Subject => 'this is my subject', + From => 'jesse@example.com', + Data => [ $string ], + ); + + my $t = RT::Ticket->new($RT::SystemUser); + ok( $t->Create( Queue => 'General', + Subject => 'another ticket', + MIMEObj => $Message, + MemberOf => $created[0] + ), + "Ticket Created" + ); + $created{ $t->Id }++; push @created, $t->Id; +} -my ($id, $msg) = $tix->FromSQL($query); +{ + my $query = ("Subject LIKE '$string' OR Content LIKE '$string'"); + my ($status, $msg) = $tix->FromSQL($query); + ok ($status, "correct query") or diag("error: $msg"); -ok ($id, $msg); + my $count = 0; + while (my $tick = $tix->Next) { + $count++ if $created{ $tick->id }; + } + is ($count, scalar @created, "number of returned tickets same as entered"); +} -is ($tix->Count, scalar @ids, "number of returned tickets same as entered"); +{ + my $query = "id = $created[0] OR MemberOf = $created[0]"; + my ($status, $msg) = $tix->FromSQL($query); + ok ($status, "correct query") or diag("error: $msg"); -@expectedids = (); -while (my $tick = $tix->Next) { - push @expectedids, $tick->Id; + my $count = 0; + while (my $tick = $tix->Next) { + $count++ if $created{ $tick->id }; + } + is ($count, scalar @created, "number of returned tickets same as entered"); } -ok (eq_array(\@ids, \@expectedids), "returned expected tickets"); =end testing