[Rt-commit] [rtir] 01/01: First step in switching RTIR logic from queue name to lifecycle

Jesse Vincent jesse at bestpractical.com
Thu Feb 5 18:57:45 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 90b33d76cb69eb191d64fdb458017627f34537e4
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Thu Feb 5 15:51:43 2015 -0800

    First step in switching RTIR logic from queue name to lifecycle
    
    This commit starts to switch over code that depends on RTIR queue
    names to depend on queue lifecycle names. This will help pave the
    way for multiple fully-functional queues of a given type in RTIR.
    
    There are still plenty of places the old logic is in place, but
    this code passes the same tests as the previous rev
    
    With this commit, this branch depends on RT branch
    4.2/search-by-lifecycle
---
 html/RTIR/Tools/Elements/LookupSummary |  2 +-
 lib/RT/Action/RTIR_OpenParent.pm       |  2 +-
 lib/RT/IR.pm                           | 34 ++++++++++++++++++++--------------
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/html/RTIR/Tools/Elements/LookupSummary b/html/RTIR/Tools/Elements/LookupSummary
index c5f3b4e..c7a1fe3 100644
--- a/html/RTIR/Tools/Elements/LookupSummary
+++ b/html/RTIR/Tools/Elements/LookupSummary
@@ -56,7 +56,7 @@
 % } else {
 <& /RTIR/Search/Elements/ShowResults,
     Queue         => $Queue,
-    BaseQuery     => RT::IR->Query( Queue => $Queue ),
+    BaseQuery     => RT::IR->Query( Lifecycle => $Queue->Lifecycle ),
     Query         => $Query,
     Format        => $Format,
     AllowSorting  => 0,
diff --git a/lib/RT/Action/RTIR_OpenParent.pm b/lib/RT/Action/RTIR_OpenParent.pm
index 9d95212..beb024c 100644
--- a/lib/RT/Action/RTIR_OpenParent.pm
+++ b/lib/RT/Action/RTIR_OpenParent.pm
@@ -68,7 +68,7 @@ sub Commit {
 
     my $parents = RT::Tickets->new( $txn->CurrentUser );
     $parents->FromSQL( RT::IR->Query(
-        Queue     => 'Incidents',
+        Lifecycle     => 'incidents',
         HasMember => $ticket,
         Inactive  => 1,
     ) );
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 81b315e..6cb8dfe 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -62,6 +62,7 @@ use Scalar::Util qw(blessed);
 use RT::IR::Config;
 RT::IR::Config::Init();
 
+my @LIFECYCLES = ('incidents', 'incident_reports', 'investigations','blocks');
 my @QUEUES = ('Incidents', 'Incident Reports', 'Investigations', 'Blocks');
 my %QUEUES = map { lc($_) => $_ } @QUEUES;
 my %TYPE = (
@@ -244,7 +245,8 @@ sub ActiveQuery {
 sub Query {
     my $self = shift;
     my %args = (
-        Queue        => undef,
+        Lifecycle    => undef,
+        Queue        => undef, # TODO 3.4: remove this in favor of lifecycle
         Status       => undef,
         Active       => undef,
         Inactive     => undef,
@@ -258,7 +260,11 @@ sub Query {
     );
 
     my @res;
-    if ( $args{'Queue'} ) {
+    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' );
     }
@@ -312,8 +318,8 @@ sub ParseSimpleSearch {
         TicketsObj => RT::Tickets->new( $args{'CurrentUser'} ),
     );
     my $res = $search->QueryToSQL;
-    if ( $res && $res !~ /\bQueue\b/ ) {
-        $res = "Queue = 'Incidents' AND ($res)";
+    if ( $res && $res !~ /\bQueue\b/ && $res !~ /\bLifecycle\b/ ) {
+        $res = "Lifecycle = 'incidents' AND ($res)";
     }
     return $res;
 }
@@ -360,7 +366,7 @@ sub Incidents {
     my $ticket = shift;
 
     my $res = RT::Tickets->new( $ticket->CurrentUser );
-    $res->FromSQL( $self->Query( Queue => 'Incidents', HasMember => $ticket ) );
+    $res->FromSQL( $self->Query( Lifecycle => 'incidents', HasMember => $ticket ) );
     return $res;
 }
 
@@ -375,7 +381,7 @@ sub RelevantIncidentsQuery {
     my $self = shift;
     my $ticket = shift;
 
-    return "Queue = 'Incidents' AND HasMember = ". $ticket->id
+    return "Lifecycle = 'incidents' AND HasMember = ". $ticket->id
         ." AND Status != 'abandoned'"
     ;
 }
@@ -392,7 +398,7 @@ sub RelevantIncidents {
 sub IncidentChildren {
     my $self = shift;
     my $ticket = shift;
-    my %args = (Queue => \@QUEUES, @_);
+    my %args = (Lifecycle => \@LIFECYCLES, @_);
 
     my $res = RT::Tickets->new( $ticket->CurrentUser );
     $res->FromSQL( $self->Query( %args, MemberOf => $ticket->id ) );
@@ -408,7 +414,7 @@ sub IncidentHasActiveChildren {
     my $incident = shift;
 
     my $children = RT::Tickets->new( $incident->CurrentUser );
-    $children->FromSQL( $self->ActiveQuery( Queue => \@QUEUES, MemberOf => $incident->id ) );
+    $children->FromSQL( $self->ActiveQuery( Lifecycle => \@LIFECYCLES, MemberOf => $incident->id ) );
     while ( my $child = $children->Next ) {
         next if $self->IsLinkedToActiveIncidents( $child, $incident );
         return 1;
@@ -434,7 +440,7 @@ sub IsLinkedToActiveIncidents {
 
     my $tickets = RT::Tickets->new( $child->CurrentUser );
     $tickets->FromSQL( $self->ActiveQuery(
-        Queue     => 'Incidents',
+        Lifecycle     => 'incidents',
         HasMember => $child,
         ($parent ? (Exclude   => $parent->id) : ()),
     ) );
@@ -691,7 +697,7 @@ package RT::Search::Simple;
 
 sub HandleRtirip {
     return 'RTIR IP' => RT::IR->Query(
-        Queue => ['Incidents', 'Incident Reports', 'Investigations', 'Blocks'],
+        Lifecycle => ['incidents', 'incident_reports', 'investigations', 'blocks'],
         And => "'CustomField.{IP}' = '$_[1]'",
     );
 }
@@ -702,9 +708,9 @@ sub HandleRtirrequestor {
 
     my $children = RT::Tickets->new( $self->TicketsObj->CurrentUser );
     $children->FromSQL(
-        "( Queue = 'Incident Reports' OR
-           Queue = 'Investigations' OR
-           Queue = 'Blocks'
+        "( Lifecycle = 'incident_reports' OR
+           Lifecycle = 'investigations' OR
+           Lifecycle = 'blocks'
          ) AND Requestor LIKE '$value'"
     );
     my $query = '';
@@ -713,7 +719,7 @@ sub HandleRtirrequestor {
         $query .= "HasMember = " . $child->Id;
     }
     $query ||= 'id = 0';
-    return 'RTIR Requestor' => "Queue = 'Incidents' AND ($query)";
+    return 'RTIR Requestor' => "Lifecycle = 'incidents' AND ($query)";
 }
 
 package RT::IR;

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


More information about the rt-commit mailing list