[freeside-commits] freeside/rt/lib/RT Tickets_Overlay.pm, 1.5.2.1, 1.5.2.2

Mark Wells mark at wavetail.420.am
Wed Jan 26 13:35:43 PST 2011


Update of /home/cvs/cvsroot/freeside/rt/lib/RT
In directory wavetail.420.am:/tmp/cvs-serv2732/lib/RT

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	Tickets_Overlay.pm 
Log Message:
fix customfield date search, RT#8449

Index: Tickets_Overlay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/lib/RT/Tickets_Overlay.pm,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -w -d -r1.5.2.1 -r1.5.2.2
--- Tickets_Overlay.pm	20 Nov 2010 02:35:47 -0000	1.5.2.1
+++ Tickets_Overlay.pm	26 Jan 2011 21:35:41 -0000	1.5.2.2
@@ -136,7 +136,6 @@
     QueueAdminCc     => [ 'WATCHERFIELD'    => 'AdminCc' => 'Queue', ], #loc_left_pair
     QueueWatcher     => [ 'WATCHERFIELD'    => undef     => 'Queue', ], #loc_left_pair
     CustomFieldValue => [ 'CUSTOMFIELD', ], #loc_left_pair
-    DateCustomFieldValue => [ 'DATECUSTOMFIELD', ],
     CustomField      => [ 'CUSTOMFIELD', ], #loc_left_pair
     CF               => [ 'CUSTOMFIELD', ], #loc_left_pair
     Updated          => [ 'TRANSDATE', ], #loc_left_pair
@@ -164,7 +163,6 @@
     WATCHERFIELD    => \&_WatcherLimit,
     MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
     CUSTOMFIELD     => \&_CustomFieldLimit,
-    DATECUSTOMFIELD => \&_DateCustomFieldLimit,
     HASATTRIBUTE    => \&_HasAttributeLimit,
     FREESIDEFIELD   => \&_FreesideFieldLimit,
 );
@@ -525,6 +523,14 @@
     die "Incorrect Meta Data for $field"
         unless ( defined $meta->[1] );
 
+    $sb->_DateFieldLimit( $meta->[1], $op, $value, @rest );
+}
+
+# Factor this out for use by custom fields
+
+sub _DateFieldLimit {
+    my ( $sb, $field, $op, $value, @rest ) = @_;
+
     my $date = RT::Date->new( $sb->CurrentUser );
     $date->Set( Format => 'unknown', Value => $value );
 
@@ -542,14 +548,14 @@
         $sb->_OpenParen;
 
         $sb->_SQLLimit(
-            FIELD    => $meta->[1],
+            FIELD    => $field,
             OPERATOR => ">=",
             VALUE    => $daystart,
             @rest,
         );
 
         $sb->_SQLLimit(
-            FIELD    => $meta->[1],
+            FIELD    => $field,
             OPERATOR => "<",
             VALUE    => $dayend,
             @rest,
@@ -561,7 +567,7 @@
     }
     else {
         $sb->_SQLLimit(
-            FIELD    => $meta->[1],
+            FIELD    => $field,
             OPERATOR => $op,
             VALUE    => $date->ISO,
             @rest,
@@ -1346,101 +1352,6 @@
     return ($TicketCFs, $CFs);
 }
 
-=head2 _DateCustomFieldLimit
-
-Limit based on CustomFields of type Date
-
-Meta Data:
-  none
-
-=cut
-
-sub _DateCustomFieldLimit {
-    my ( $self, $_field, $op, $value, %rest ) = @_;
-
-    my $field = $rest{'SUBKEY'} || die "No field specified";
-
-    # For our sanity, we can only limit on one queue at a time
-
-    my ($queue, $cfid, $column);
-    ($queue, $field, $cfid, $column) = $self->_CustomFieldDecipher( $field );
-
-# 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 =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
-        $null_columns_ok = 1;
-    }
-
-    my $cfkey = $cfid ? $cfid : "$queue.$field";
-    my ($TicketCFs, $CFs) = $self->_CustomFieldJoin( $cfkey, $cfid, $field );
-
-    $self->_OpenParen;
-
-    if ( $CFs && !$cfid ) {
-        $self->SUPER::Limit(
-            ALIAS           => $CFs,
-            FIELD           => 'Name',
-            VALUE           => $field,
-            ENTRYAGGREGATOR => 'AND',
-        );
-    }
-
-    $self->_OpenParen if $null_columns_ok;
-
-    my $date = RT::Date->new( $self->CurrentUser );
-    $date->Set( Format => 'unknown', Value => $value );
-
-    if ( $op eq "=" ) {
-
-        # if we're specifying =, that means we want everything on a
-        # particular single day.  in the database, we need to check for >
-        # and < the edges of that day.
-
-        $date->SetToMidnight( Timezone => 'server' );
-        my $daystart = $date->ISO;
-        $date->AddDay;
-        my $dayend = $date->ISO;
-
-        $self->_OpenParen;
-
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => ">=",
-            VALUE    => $daystart,
-            %rest,
-        );
-
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => "<=",
-            VALUE    => $dayend,
-            %rest,
-            ENTRYAGGREGATOR => 'AND',
-        );
-
-        $self->_CloseParen;
-
-    }
-    else {
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => $op,
-            VALUE    => $date->ISO,
-            %rest,
-        );
-    }
-
-    $self->_CloseParen;
-
-}
-
 =head2 _CustomFieldLimit
 
 Limit based on CustomFields
@@ -1461,6 +1372,11 @@
     ($queue, $field, $cf, $column) = $self->_CustomFieldDecipher( $field );
     $cfid = $cf ? $cf->id  : 0 ;
 
+    # Handle date custom fields specially
+    if ( $cf->Type eq 'Date' ) {
+      return $self->_DateCustomFieldLimit($_field, $op, $value, %rest);
+    }
+
 # 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
@@ -1524,6 +1440,15 @@
                 %rest
             );
         }
+        elsif ( $cf->Type eq 'Date' ) {
+            $self->_DateFieldLimit( 
+                'Content',
+                $op,
+                $value,
+                ALIAS => $TicketCFs,
+                %rest
+            );
+        }
         elsif ( $op eq '=' || $op eq '!=' || $op eq '<>' ) {
             unless ( length( Encode::encode_utf8($value) ) > 255 ) {
                 $self->_SQLLimit(



More information about the freeside-commits mailing list