[Rt-devel] Updated PATCH for transaction-cfs-for-scrips.patch

Jason Long jlong at messiah.edu
Wed Oct 4 15:19:56 EDT 2006


I've updated transaction-cfs-for-scrips.patch, which I found here

http://www.gossamer-threads.com/lists/rt/users/54500#54500

to apply cleanly to 3.6.1 and made it work when a ticket is first 
created too.

To summarize, this patch makes per-transaction custom fields available 
to Scrips. This way Scrips (which are per-transaction) can be controlled 
by per-transaction custom fields.


(I know there were reservations about the original patch, and I don't 
expect this update to change that, but I figured I'd share this update 
since I find this functionality useful.)

Jason
-------------- next part --------------
diff -ru lib.orig/RT/Interface/Web.pm lib/RT/Interface/Web.pm
--- lib.orig/RT/Interface/Web.pm	2006-10-04 14:24:31.000000000 -0400
+++ lib/RT/Interface/Web.pm	2006-10-04 14:24:46.000000000 -0400
@@ -555,16 +555,23 @@
           foreach values %{ $args{ARGSRef}->{'UpdateAttachments'} };
     }
 
+    # Only pass custom field related args up the stack
+    my %cfargs = %{$args{'ARGSRef'}};
+    for (keys %cfargs) {
+        delete $cfargs{$_} unless /CustomField/;
+    }
+
+
     ## TODO: Implement public comments
     if ( $args{ARGSRef}->{'UpdateType'} =~ /^(private|public)$/ ) {
         my ( $Transaction, $Description, $Object ) = $args{TicketObj}->Comment(
             CcMessageTo  => $args{ARGSRef}->{'UpdateCc'},
             BccMessageTo => $args{ARGSRef}->{'UpdateBcc'},
             MIMEObj      => $Message,
-            TimeTaken    => $args{ARGSRef}->{'UpdateTimeWorked'}
+            TimeTaken    => $args{ARGSRef}->{'UpdateTimeWorked'},
+            %cfargs
         );
         push( @{ $args{Actions} }, $Description );
-        $Object->UpdateCustomFields( ARGSRef => $args{ARGSRef} ) if $Object;
     }
     elsif ( $args{ARGSRef}->{'UpdateType'} eq 'response' ) {
         my ( $Transaction, $Description, $Object ) =
@@ -572,10 +579,10 @@
             CcMessageTo  => $args{ARGSRef}->{'UpdateCc'},
             BccMessageTo => $args{ARGSRef}->{'UpdateBcc'},
             MIMEObj      => $Message,
-            TimeTaken    => $args{ARGSRef}->{'UpdateTimeWorked'}
+            TimeTaken    => $args{ARGSRef}->{'UpdateTimeWorked'},
+            %cfargs
           );
         push( @{ $args{Actions} }, $Description );
-        $Object->UpdateCustomFields( ARGSRef => $args{ARGSRef} ) if $Object;
     }
     else {
         push(
diff -ru lib.orig/RT/Record.pm lib/RT/Record.pm
--- lib.orig/RT/Record.pm	2006-10-04 14:24:30.000000000 -0400
+++ lib/RT/Record.pm	2006-10-04 14:24:46.000000000 -0400
@@ -64,10 +64,11 @@
 =cut
 
 package RT::Record;
+use RT::Base;
 use RT::Date;
+use RT::Transaction;
 use RT::User;
 use RT::Attributes;
-use RT::Base;
 use DBIx::SearchBuilder::Record::Cachable;
 
 use strict;
@@ -1441,23 +1442,16 @@
 	$new_ref = $new_ref->Id if ref($new_ref);
     }
 
-    require RT::Transaction;
+    delete $args{id};
+
     my $trans = new RT::Transaction( $self->CurrentUser );
     my ( $transaction, $msg ) = $trans->Create(
-	ObjectId  => $self->Id,
+        %args, # push up basic data and custom fields
+        ObjectId  => $self->Id,
 	ObjectType => ref($self),
-        TimeTaken => $args{'TimeTaken'},
-        Type      => $args{'Type'},
-        Data      => $args{'Data'},
-        Field     => $args{'Field'},
-        NewValue  => $args{'NewValue'},
-        OldValue  => $args{'OldValue'},
         NewReference  => $new_ref,
         OldReference  => $old_ref,
         ReferenceType => $ref_type,
-        MIMEObj   => $args{'MIMEObj'},
-        ActivateScrips => $args{'ActivateScrips'},
-        CommitScrips => $args{'CommitScrips'},
     );
 
     # Rationalize the object since we may have done things to it during the caching.
diff -ru lib.orig/RT/Ticket_Overlay.pm lib/RT/Ticket_Overlay.pm
--- lib.orig/RT/Ticket_Overlay.pm	2006-10-04 14:24:30.000000000 -0400
+++ lib/RT/Ticket_Overlay.pm	2006-10-04 14:56:47.000000000 -0400
@@ -742,7 +742,13 @@
     if ( $args{'_RecordTransaction'} ) {
 
         # {{{ Add a transaction for the create
+
+        # pass transaction custom fields to the transaction
+        my %cfargs = map { $_ => $args{$_} }
+            grep /^Object-RT::Transaction--CustomField-/, keys %args;
+
         my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+                                                     %cfargs,
                                                      Type      => "Create",
                                                      TimeTaken => $args{'TimeWorked'},
                                                      MIMEObj => $args{'MIMEObj'}
@@ -750,8 +756,6 @@
 
         if ( $self->Id && $Trans ) {
 
-            $TransObj->UpdateCustomFields(ARGSRef => \%args);
-
             $RT::Logger->info( "Ticket " . $self->Id . " created in queue '" . $QueueObj->Name . "' by " . $self->CurrentUser->Name );
             $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name );
             $ErrStr = join( "\n", $ErrStr, @non_fatal_errors );
@@ -2440,11 +2444,9 @@
 
     #Record the correspondence (write the transaction)
     my ( $Trans, $msg, $TransObj ) = $self->_NewTransaction(
+             %args, # basic info, custom fields    
              Type => $args{'NoteType'},
              Data => ( $args{'MIMEObj'}->head->get('subject') || 'No Subject' ),
-             TimeTaken => $args{'TimeTaken'},
-             MIMEObj   => $args{'MIMEObj'}, 
-             CommitScrips => $args{'CommitScrips'},
     );
 
     unless ($Trans) {
diff -ru lib.orig/RT/Transaction_Overlay.pm lib/RT/Transaction_Overlay.pm
--- lib.orig/RT/Transaction_Overlay.pm	2006-10-04 14:24:30.000000000 -0400
+++ lib/RT/Transaction_Overlay.pm	2006-10-04 14:53:57.000000000 -0400
@@ -159,6 +159,7 @@
             return ( 0, $self->loc("Couldn't add attachment") );
         }
     }
+    $self->UpdateCustomFields(%args);
 
 
     #Provide a way to turn off scrips if we need to


More information about the Rt-devel mailing list