[Rt-commit] rt branch, 4.2/search-by-lifecycle, created. rt-4.2.9-154-g6876523

Jesse Vincent jesse at bestpractical.com
Fri Feb 6 02:13:20 EST 2015


The branch, 4.2/search-by-lifecycle has been created
        at  6876523b8d7a889575bf61d304db6cb2ba9bc47f (commit)

- Log -----------------------------------------------------------------
commit 6876523b8d7a889575bf61d304db6cb2ba9bc47f
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Thu Feb 5 14:33:18 2015 -0800

    Add the ability to search for tickets based on queue lifecycle
    
    It's sometimes useful to be able to search for all tickets in a
    specific lifecycle.  This commit adds the 'Lifecycle' field to
    TicketSQL, as well as associated tests.
    
    Code by Alex Vandiver. Tests by Jesse Vincent.

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 58900a2..c641cd2 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -154,6 +154,7 @@ our %FIELD_METADATA = (
     TxnCF            => [ 'CUSTOMFIELD' => 'Transaction' ], #loc_left_pair
     TransactionCF    => [ 'CUSTOMFIELD' => 'Transaction' ], #loc_left_pair
     QueueCF          => [ 'CUSTOMFIELD' => 'Queue' ], #loc_left_pair
+    Lifecycle        => [ 'LIFECYCLE' ], #loc_left_pair
     Updated          => [ 'TRANSDATE', ], #loc_left_pair
     UpdatedBy        => [ 'TRANSCREATOR', ], #loc_left_pair
     OwnerGroup       => [ 'MEMBERSHIPFIELD' => 'Owner', ], #loc_left_pair
@@ -191,6 +192,7 @@ our %dispatch = (
     MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
     CUSTOMFIELD     => \&_CustomFieldLimit,
     HASATTRIBUTE    => \&_HasAttributeLimit,
+    LIFECYCLE       => \&_LifecycleLimit,
 );
 
 # Default EntryAggregator per type
@@ -1236,6 +1238,26 @@ sub _HasAttributeLimit {
 }
 
 
+sub _LifecycleLimit {
+    my ( $self, $field, $op, $value, %rest ) = @_;
+
+    die "Invalid Operator $op for $field" if $op =~ /^(IS|IS NOT)$/io;
+    my $queue = $self->{_sql_aliases}{queues} ||= $_[0]->Join(
+        ALIAS1 => 'main',
+        FIELD1 => 'Queue',
+        TABLE2 => 'Queues',
+        FIELD2 => 'id',
+    );
+
+    $self->Limit(
+        ALIAS    => $queue,
+        FIELD    => 'Lifecycle',
+        OPERATOR => $op,
+        VALUE    => $value,
+        %rest,
+    );
+}
+
 # End Helper Functions
 
 # End of SQL Stuff -------------------------------------------------
diff --git a/t/ticket/search.t b/t/ticket/search.t
index 852241f..a43433f 100644
--- a/t/ticket/search.t
+++ b/t/ticket/search.t
@@ -283,4 +283,35 @@ like($tix->BuildSelectCountQuery, qr/\bNULL\b/, "Contains upper-case NULL");
 unlike($tix->BuildSelectCountQuery, qr/\bnull\b/, "Lacks lower-case NULL");
 
 
+# tests for searching by queue lifecycle
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle="default"');
+is($tix->Count,7,"We found all 7 tickets in a queue with the default lifecycle");
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle ="approvals" OR Lifecycle="default"');
+is($tix->Count,7,"We found 7 tickets in a queue with a lifecycle of default or approvals");
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle ="approvals" AND Lifecycle="default"');
+is($tix->Count,0,"We found 0 tickets in a queue with a lifecycle of default AND approvals...(because that's impossible");
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Queue="'.$queue.'" AND Lifecycle="default"');
+is($tix->Count,7,"We found 7 tickets in $queue with a lifecycle of default");
+
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle !="approvals"');
+is($tix->Count,7,"We found 7 tickets in a queue with a lifecycle other than approvals");
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle!="default"');
+is($tix->Count,0,"We found 0 tickets in a queue with a lifecycle other than default");
+
+$tix = RT::Tickets->new(RT->SystemUser);
+$tix->FromSQL('Lifecycle="approvals"');
+is($tix->Count,0,"We found 0 tickets in a queue with the approvals lifecycle");
+
+
 done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list