[Rt-commit] r2756 - in rt/branches/QUEBEC-EXPERIMENTAL: . lib/RT lib/t/regression

jesse at bestpractical.com jesse at bestpractical.com
Sun Apr 17 23:13:27 EDT 2005


Author: jesse
Date: Sun Apr 17 23:13:26 2005
New Revision: 2756

Modified:
   rt/branches/QUEBEC-EXPERIMENTAL/   (props changed)
   rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
   rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/12-search.t
Log:
 r13210 at hualien:  jesse | 2005-04-17 23:07:40 -0400
  r13186 at hualien:  jesse | 2005-04-17 20:24:41 -0400
  RT-Ticket: 6562
  RT-Status: resolved
  RT-Update: correspond
  
  * Patch from Tom Yu to allow negative CF searching and better
    multi-CF search.
  
  * Bumped SearchBuilder dependency to new version
  
 


Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm	(original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm	Sun Apr 17 23:13:26 2005
@@ -1093,13 +1093,15 @@
     $field = $1 if $field =~ /^{(.+)}$/;    # trim { }
 
 
-# If we're trying to find custom fields that don't match something, we want tickets
-# where the custom field has no value at all
+# If we're trying to find custom fields that don't match something, we
+# want tickets where the custom field has no value at all.  Note that
+# we explicitly don't include the "IS NULL" case, since we would
+# otherwise end up with a redundant clause.
 
     my $null_columns_ok;
-    if ( ( $op =~ /^IS$/i ) or ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
+    if ( ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
         $null_columns_ok = 1;
-    } 
+    }
 
     my $cfid = 0;
     if ($queue) {
@@ -1118,24 +1120,53 @@
 
         $cfid = $cf->id;
 
-    } else { # if we have no id, we're going to search on name.
-        $cfid = $field;
     }
 
     my $TicketCFs;
+    my $cfkey = $cfid ? $cfid : "$queue.$field";
 
     # Perform one Join per CustomField
-    if ( $self->{_sql_object_cf_alias}{$cfid} ) {
-        $TicketCFs = $self->{_sql_object_cf_alias}{$cfid};
+    if ( $self->{_sql_object_cf_alias}{$cfkey} ) {
+        $TicketCFs = $self->{_sql_object_cf_alias}{$cfkey};
     }
     else {
-        $TicketCFs = $self->{_sql_object_cf_alias}{$cfid} = $self->Join(
-            TYPE   => 'left',
-            ALIAS1 => 'main',
-            FIELD1 => 'id',
-            TABLE2 => 'ObjectCustomFieldValues',
-            FIELD2 => 'ObjectId'
-        );
+        if ($cfid) {
+            $TicketCFs = $self->{_sql_object_cf_alias}{$cfkey} = $self->Join(
+                TYPE   => 'left',
+                ALIAS1 => 'main',
+                FIELD1 => 'id',
+                TABLE2 => 'ObjectCustomFieldValues',
+                FIELD2 => 'ObjectId',
+            );
+            $self->SUPER::Limit(
+                LEFTJOIN        => $TicketCFs,
+                FIELD           => 'CustomField',
+                VALUE           => $cfid,
+                ENTRYAGGREGATOR => 'AND'
+            );
+        } else {
+            my $cfalias = $self->Join(
+                TYPE   => 'left',
+                EXPRESSION =>   "'$field'",
+                TABLE2 => 'CustomFields',
+                FIELD2 => 'Name',
+            );
+
+            $TicketCFs = $self->{_sql_object_cf_alias}{$cfkey} = $self->Join(
+                TYPE   => 'left',
+                ALIAS1 => $cfalias,
+                FIELD1 => 'id',
+                TABLE2 => 'ObjectCustomFieldValues',
+                FIELD2 => 'CustomField',
+            );
+            $self->SUPER::Limit(
+                LEFTJOIN => $TicketCFs,
+                FIELD => 'ObjectId',
+                VALUE => 'main.id',
+                QUOTEVALUE => 0,
+                ENTRYAGGREGATOR => 'AND',
+            );
+        }
         $self->SUPER::Limit(
             LEFTJOIN => $TicketCFs,
             FIELD    => 'ObjectType',
@@ -1149,30 +1180,6 @@
             OPERATOR    => '=',
             VALUE => '0',
             ENTRYAGGREGATOR => 'AND');
-
-        if ($cfid =~ /^\d+$/) { # we have a numerical cfid. we know which cf we want
-            $self->SUPER::Limit(
-                LEFTJOIN        => $TicketCFs,
-                FIELD           => 'CustomField',
-                VALUE           => $cfid,
-                ENTRYAGGREGATOR => 'AND'
-            );
-        }
-        else { # we're going to need to search on cf name
-            my $cfalias = $self->Join(
-                ALIAS1 => $TicketCFs,
-                TYPE => 'left',
-                FIELD1 => 'CustomField',
-                TABLE2 => 'CustomFields',
-                FIELD2 => 'id'
-            );
-            $self->SUPER::Limit(
-                LEFTJOIN => $cfalias,
-                FIELD    => 'Name',
-                VALUE    => $field,
-            );
-
-        }
     }
 
     $self->_OpenParen if ($null_columns_ok);
@@ -1185,7 +1192,8 @@
         QUOTEVALUE => 1,
         @rest
     );
-    if ($null_columns_ok && ($op ne 'IS' && $value ne 'NULL')) {
+
+    if ($null_columns_ok) {
         $self->_SQLLimit(
             ALIAS           => $TicketCFs,
             FIELD           => 'Content',

Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/12-search.t
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/12-search.t	(original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/12-search.t	Sun Apr 17 23:13:26 2005
@@ -145,17 +145,11 @@
 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
 is($tix->Count, 5, "matched LIKE subject");
 
-#$tix = RT::Tickets->new($RT::SystemUser);
-#$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
-#is($tix->Count, 2, "LIKE null CF");
 
 $tix = RT::Tickets->new($RT::SystemUser);
 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL");
-SKIP: {
     
-        skip "Negative CF searches don't work", 1; 
-    is($tix->Count, 2, "IS null CF");};
-
+    is($tix->Count, 2, "IS null CF");
 
 $tix = RT::Tickets->new($RT::SystemUser);
 $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search1'");
@@ -169,9 +163,14 @@
 $tix->FromSQL("Queue = '$queue' AND Requestors LIKE 'search'");
 is($tix->Count, 6, "LIKE requestor");
 
-$tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$queue' AND Requestors IS NULL");
-SKIP  {skip "Can't search for 'no requestor", 1; is($tix->Count, 1, "Search for no requestor")};
+TODO: {
+    
+    local $TODO = "Can't search for 'no requestor"; 
+    $tix = RT::Tickets->new($RT::SystemUser);
+    $tix->FromSQL("Queue = '$queue' AND Requestors IS NULL");
+    is($tix->Count, 1, "Search for no requestor");
+
+};
 
 $tix = RT::Tickets->new($RT::SystemUser);
 $tix->FromSQL("Queue = '$queue' AND Subject = 'SearchTest1'");
@@ -223,19 +222,14 @@
 is($tix->Count, 4, "like cf and like subject");
 
 $tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar5'");
-SKIP: { 
+$tix->FromSQL("CF.SearchTest IS NULL AND CF.SearchTest2 = 'bar2'");
     
-        skip "Negative CF searches don't work", 1; 
-    is($tix->Count, 1, "null cf and is cf"); };
-
+    is($tix->Count, 1, "null cf and is cf");
 
 
 $tix = RT::Tickets->new($RT::SystemUser);
-$tix->FromSQL("Queue = '$$' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL");
-SKIP: { 
-        skip "Negative CF searches don't work", 1; 
+$tix->FromSQL("Queue = '$queue' AND CF.SearchTest IS NULL AND CF.SearchTest2 IS NULL");
 
-        is($tix->Count, 1, "null cf and null cf"); };
+        is($tix->Count, 1, "null cf and null cf"); 
 
 


More information about the Rt-commit mailing list