[Rt-commit] r5844 - in rt/branches/3.7-EXPERIMENTAL: .

ruz at bestpractical.com ruz at bestpractical.com
Sun Sep 3 20:42:32 EDT 2006


Author: ruz
Date: Sun Sep  3 20:42:32 2006
New Revision: 5844

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm

Log:
 r3684 at cubic-pc:  cubic | 2006-09-03 23:01:02 +0400
 ::Plugin::Tickets
 * add option 'query'
 * drop options queue, status and updated_before


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm	Sun Sep  3 20:42:32 2006
@@ -10,47 +10,35 @@
 
 =head1 ARGUMENTS
 
-=head2 queue - queue name
+=head2 query - query string
 
-Search tickets only in particular queue.
-
-=head2 status - ticket status
-
-Search tickets with specified status only.
-'deleted' status is also supported.
-
-=head2 updated_before - date
-
-Search tickets that were updated before some date.
-Example: '2003-12-31 23:59:59'
+Search tickets with query string.
+Examples:
+  Queue = 'my queue' AND ( Status = 'deleted' OR Status = 'rejected' )
+  LastUpdated < '2003-12-31 23:59:59'
+
+B<Hint:> You can construct query with the query builder in RT's web
+interface and then open advanced page and copy query string.
+
+Arguments C<queue>, C<status> and C<updated_before> have been dropped
+as you can easy make the same search with the C<query> option.
+See examples above.
 
 =cut
 
-sub SupportArgs { return $_[0]->SUPER::SupportArgs, qw(queue status updated_before) }
+sub SupportArgs { return $_[0]->SUPER::SupportArgs, qw(query) }
 
 sub TestArgs
 {
     my $self = shift;
     my %args = @_;
     my $queue;
-    if( $args{'queue'} ) {
-        $queue = RT::Queue->new( $RT::SystemUser );
-        $queue->Load( $args{'queue'} );
-        return( 0, "Couldn't load queue '$args{'queue'}'" ) unless $queue->id;
-        $args{'queue'} = $queue->id;
-    }
-    if( $args{'status'} ) {
-        $queue ||= RT::Queue->new( $RT::SystemUser );
-        my @statuses = qw(new open stalled deleted rejected);
-        @statuses = $queue->StatusArray if $queue->can('StatusArray');
-        unless( grep lc $_ eq lc $args{'status'}, @statuses ) {
-            return( 0, "Invalid status '$args{status}'" );
-        }
-    }
-    if( $args{'updated_before'} ) {
-        unless( $args{'updated_before'} =~ /\d\d\d\d-\d\d-\d\d(?:\s\d\d:\d\d:\d\d)?/ ) {
-            return( 0, "Invalid date '$args{updated_before}'" );
-        }
+    if( $args{'query'} ) {
+        my $objs = RT::Tickets->new( $RT::SystemUser );
+        $objs->{'allow_deleted_search'} = 1;
+        my ($status, $msg) = $queue->FromSQL( $args{'query'} );
+        return( 0, "Bad query argument, error: $msg" ) unless $status;
+        $args{'query'} = $objs;
     }
     return $self->SUPER::TestArgs( %args );
 }
@@ -58,20 +46,8 @@
 sub Run
 {
     my $self = shift;
-    my $objs = RT::Tickets->new( $RT::SystemUser );
-    $objs->{'allow_deleted_search'} = 1;
-    if( $self->{'opt'}{'status'} ) {
-        $objs->LimitStatus( VALUE => $self->{'opt'}{'status'} );
-    }
-    if( $self->{'opt'}{'queue'} ) {
-        $objs->LimitQueue( VALUE => $self->{'opt'}{'queue'} );
-    }
-    if( $self->{'opt'}{'updated_before'} ) {
-        $objs->LimitLastUpdated(
-            OPERATOR => '<',
-            VALUE => $self->{'opt'}{'updated_before'},
-        );
-    }
+    my $objs = $self->{'opt'}{'query'}
+        or return (1, undef);
     if( $self->{'opt'}{'limit'} ) {
         $objs->RowsPerPage( $self->{'opt'}{'limit'} );
     }


More information about the Rt-commit mailing list