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

Jesse Vincent jesse at bestpractical.com
Thu Feb 5 17:35:42 EST 2015


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

- Log -----------------------------------------------------------------
commit e2de24ab34d7a6ebdda53cd97e92505a99900b22
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 a6b07e4..e8f909f 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
@@ -1214,6 +1216,25 @@ sub _HasAttributeLimit {
 }
 
 
+sub _LifecycleLimit {
+    my ( $self, $field, $op, $value, %rest ) = @_;
+
+    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..dface5c 100644
--- a/t/ticket/search.t
+++ b/t/ticket/search.t
@@ -283,4 +283,20 @@ 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"');
+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