[Rt-commit] rt branch, 4.2/cf-loadbyname-too-many-lookuptypes, created. rt-4.2.2-20-g4d47030

Kevin Falcone falcone at bestpractical.com
Fri Feb 7 17:56:38 EST 2014


The branch, 4.2/cf-loadbyname-too-many-lookuptypes has been created
        at  4d470303fd932beb0a42d59e920f69cee1903825 (commit)

- Log -----------------------------------------------------------------
commit 4d470303fd932beb0a42d59e920f69cee1903825
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Feb 7 17:27:20 2014 -0500

    Don't search both Queue and Ticket CFs when passed a Queue.
    
    In e2c21b55 (new in 4.2) we began calculating LookupType from the
    ContextObj set in bb24a9f4 (back in 4.0).  This resulted in a LookupType
    of RT::Queue if you said:
    
        $cf->LoadByName( Name => 'foo', Queue => 'General' );
    
    because the ContextObj was set to General and then used to calculate a
    LookupType.
    
    Then we call LimitToQueue which force-applies a LookupType of
    RT::Queue-RT::Ticket, meaning that we now search for:
    
        (main.LookupType IN ('RT::Queue') OR main.LookupType = 'RT::Queue-RT::Ticket')
    
    This enforces the backwards compatible 'intended' change that
    
        $cf->LoadByName( Name => 'foo', Queue => 'General' );
    
    searches for a ticket CF applied to the General queue and named foo.
    Current 4.2 would also find a foo Queue CF applied to General.
    
    This is seen best by code using RT::Queue->CustomField to load a
    specific Custom Field applied to a Queue (but not globally).  This
    commit also fixes those docs because they could confusingly lead you to
    believe that $Queue->CustomField('foo') would get you the Queue custom
    field named foo.  It has always retrieved the Ticket CF dating back to
    the original CF implementation, but the docs were never updated when we
    began allowing Custom Fields on Queues.
    
    If you want a Queue's Foo CF you need to call
    
        $cf->LoadByName( Name => 'foo', Queue => 'General', LookupType => 'RT::Queue' );

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index fe4e5f6..fe3ea05 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -422,6 +422,12 @@ sub LoadByName {
         $self->SetContextObject( $QueueObj )
             unless $self->ContextObject;
     }
+    if ( defined $args{'Queue'} ) {
+        # Set a LookupType for backcompat, otherwise we'll calculate
+        # one of RT::Queue from your ContextObj.  Older code was relying
+        # on us defaulting to RT::Queue-RT::Ticket in old LimitToQueue call.
+        $args{LookupType} ||= 'RT::Queue-RT::Ticket';
+    }
 
     # XXX - really naive implementation.  Slow. - not really. still just one query
 
@@ -446,7 +452,8 @@ sub LoadByName {
     # Don't limit to queue if queue is 0.  Trying to do so breaks
     # RT::Group type CFs.
     if ( defined $args{'Queue'} ) {
-        $CFs->LimitToQueue( $args{'Queue'} );
+        # don't use LimitToQueue because it forces a LookupType
+        $CFs->Limit ( ALIAS => $CFs->_OCFAlias, FIELD => 'ObjectId', VALUE => $args{'Queue'} );
     }
 
     # When loading by name, we _can_ load disabled fields, but prefer
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 9b680fd..6ca78c4 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -440,7 +440,8 @@ sub Templates {
 
 =head2 CustomField NAME
 
-Load the queue-specific custom field named NAME
+Load the Ticket Custom Field applied to this Queue named NAME.
+Does not load Global custom fields.
 
 =cut
 

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


More information about the rt-commit mailing list