[Rt-commit] [rtir] 12/24: Switch more of the API to depend on lifecycles

Jesse Vincent jesse at bestpractical.com
Mon Feb 9 00:25:20 EST 2015


This is an automated email from the git hooks/post-receive script.

jesse pushed a commit to branch 3.4/remove_old_constituencies
in repository rtir.

commit b8bc20ce949d709db7e96e2c0e3b3a9aaa6c0e09
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Feb 8 18:40:47 2015 -0800

    Switch more of the API to depend on lifecycles
    
    Switch more of the API to depend on lifecycles rather than queues
---
 lib/RT/IR.pm | 83 ++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index e38c5db..55f3215 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -73,6 +73,14 @@ my %TYPE = (
     'blocks'           => 'Block',
 );
 
+my %FRIENDLY_LIFECYCLE = (
+    'incidents'        => 'Incidents',
+    'incident_reports' => 'Incident Reports',
+    'investigations'   => 'Investigations',
+    'blocks'           => 'Blocks',
+
+);
+
 use Parse::BooleanLogic;
 my $ticket_sql_parser = Parse::BooleanLogic->new;
 
@@ -168,6 +176,28 @@ sub Queues {
     return @QUEUES;
 }
 
+=head2 Lifecycles
+
+Return a list of the core RTIR lifecycle names
+
+=cut
+
+sub Lifecycles {
+    return @LIFECYCLES;
+}
+
+=head2 FriendlyLifecycle
+
+XXX TODO 
+
+=cut
+
+sub FriendlyLifecycle {
+    my $lifecycle = shift;
+    return $FRIENDLY_LIFECYCLE{$lifecycle};
+
+}
+
 =head2 TicketType
 
 Returns type of a ticket. Takes Ticket, Lifecycle or Queue as an argument.
@@ -209,15 +239,15 @@ sub TicketType {
 
 Return sorted list of unique statuses for one, many or all RTIR queues.
 
-Takes arguments 'Queue', 'Active' and 'Inactive'. By default returns
-initial and active statuses. Queue can be an array reference to list several
-queues.
+Takes arguments 'Lifecycle', 'Active' and 'Inactive'. By default returns
+initial and active statuses. Lifecycle can be an array reference to list several
+lifecycles.
 
 Examples:
 
     RT::IR->Statuses()
-    RT::IR->Statuses( Queue => 'Blocks' );
-    RT::IR->Statuses( Queue => [ 'Blocks', 'Incident Reports' ] );
+    RT::IR->Statuses( Lifecycle => 'blocks' );
+    RT::IR->Statuses( Lifecycle => [ 'blocks', 'incident_reports' ] );
     RT::IR->Statuses( Active => 0, Inactive => 1 );
 
 =cut
@@ -233,27 +263,25 @@ my $flat = sub {
 
 sub Statuses {
     my $self = shift;
-    my %arg = ( Queue => undef, Initial => 1, Active => 1, Inactive => 0, @_ );
-
-    my @queues = $flat->( $arg{'Queue'} || \@QUEUES );
+    my %arg = ( Lifecycle => undef, Initial => 1, Active => 1, Inactive => 0, @_ );
 
     my (@initial, @active, @inactive);
-    foreach my $queue (@queues) {
-        unless ( blessed $queue ) {
-            my $tmp = RT::Queue->new(RT->SystemUser);
-            $tmp->Load( $queue );
-            RT->Logger->error( "failed to load queue $queue" )
-                unless $tmp->id;
-            $queue = $tmp;
-        }
-        next unless $queue->id;
-
-        my $cycle = $queue->LifecycleObj;
-        push @initial, $cycle->Initial if $arg{'Initial'};
-        push @active, $cycle->Active if $arg{'Active'};
-        push @inactive, $cycle->Inactive if $arg{'Inactive'};
-    }
 
+        my @lifecycles = $flat->( $arg{'Lifecycle'} || \@LIFECYCLES );
+    
+        foreach my $cycle (@lifecycles) {
+            unless ( blessed $cycle ) {
+                my $tmp = RT::Lifecycle->Load( Name => $cycle);
+                RT->Logger->error( "failed to load lifecycle $cycle" )
+                    unless $tmp->Name;
+                $cycle = $tmp;
+            }
+            next unless $cycle->Name;
+    
+            push @initial, $cycle->Initial if $arg{'Initial'};
+            push @active, $cycle->Active if $arg{'Active'};
+            push @inactive, $cycle->Inactive if $arg{'Inactive'};
+        }
     my %seen = ();
     return grep !$seen{$_}++, @initial, @active, @inactive;
 }
@@ -266,7 +294,6 @@ sub Query {
     my $self = shift;
     my %args = (
         Lifecycle    => undef,
-        Queue        => undef, # TODO 3.4: remove this in favor of lifecycle
         Status       => undef,
         Active       => undef,
         Inactive     => undef,
@@ -282,14 +309,10 @@ sub Query {
     my @res;
     if ( $args{'Lifecycle'} ) {
         push @res, map "($_)", join ' OR ', map "Lifecycle = '$_'",
-            $flat->( $args{'Lifecycle'}, 'Name' );
-    }
-    elsif ( $args{'Queue'} ) {
-        push @res, map "($_)", join ' OR ', map "Queue = '$_'",
-            $flat->( $args{'Queue'}, 'Name' );
+            $flat->( $args{'Lifecycle'});
     }
     if ( !$args{'Status'} && ( $args{'Initial'} || $args{'Active'} || $args{'Inactive'} ) ) {
-        $args{'Status'} = [ $self->Statuses( %args ) ];
+        $args{'Status'} = [ $self->Statuses( Lifecycle => $args{'Lifecycle'}, Active => $args{'Active'}, Inactive => $args{'Inactive'}, Initial => $args{'Initial'})];
     }
     if ( my $s = $args{'Status'} ) {
         push @res, join ' OR ', map "Status = '$_'", $flat->( $s );

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list