[Rt-commit] [svn] r1474 - in rt/branches/3.2-RELEASE: . lib/RT

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Fri Sep 10 15:40:41 EDT 2004


Author: jesse
Date: Fri Sep 10 15:40:40 2004
New Revision: 1474

Modified:
   rt/branches/3.2-RELEASE/   (props changed)
   rt/branches/3.2-RELEASE/lib/RT/Scrip_Overlay.pm
Log:
-l



Modified: rt/branches/3.2-RELEASE/lib/RT/Scrip_Overlay.pm
==============================================================================
--- rt/branches/3.2-RELEASE/lib/RT/Scrip_Overlay.pm	(original)
+++ rt/branches/3.2-RELEASE/lib/RT/Scrip_Overlay.pm	Fri Sep 10 15:40:40 2004
@@ -344,27 +344,32 @@
 
     $RT::Logger->debug("Now applying scrip ".$self->Id . " for transaction ".$args{'TransactionObj'}->id);
 
-    unless ( $self->IsApplicable( TicketObj      => $args{'TicketObj'},
-                                  TransactionObj => $args{'TransactionObj'} )
-      ) {
+    my $ApplicableTransactionObj = $self->IsApplicable( TicketObj      => $args{'TicketObj'},
+                                                        TransactionObj => $args{'TransactionObj'} );
+    unless ( $ApplicableTransactionObj ) {
         return undef;
     }
 
+    if ( $ApplicableTransactionObj->id != $args{'TransactionObj'}->id ) {
+        $RT::Logger->debug("Found an applicable transaction ".$ApplicableTransactionObj->Id . " in the same batch with transaction ".$args{'TransactionObj'}->id);
+    }
+
     #If it's applicable, prepare and commit it
-    $RT::Logger->debug("Now preparing scrip ".$self->Id . " for transaction ".$args{'TransactionObj'}->id);
+    $RT::Logger->debug("Now preparing scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id);
     unless ( $self->Prepare( TicketObj      => $args{'TicketObj'},
-                             TransactionObj => $args{'TransactionObj'} )
+                             TransactionObj => $ApplicableTransactionObj )
       ) {
         return undef;
     }
 
-    $RT::Logger->debug("Now commiting scrip ".$self->Id . " for transaction ".$args{'TransactionObj'}->id);
-    unless ( $self->Commit(TicketObj => $args{'TicketObj'},
-                            TransactionObj => $args{'TransactionObj'}) ) {
+    $RT::Logger->debug("Now commiting scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id);
+    unless ( $self->Commit( TicketObj => $args{'TicketObj'},
+                            TransactionObj => $ApplicableTransactionObj)
+      ) {
         return undef;
     }
 
-    $RT::Logger->debug("We actually finished scrip ".$self->Id . " for transaction ".$args{'TransactionObj'}->id);
+    $RT::Logger->debug("We actually finished scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id);
     return (1);
 
 }
@@ -377,6 +382,16 @@
 
 Calls the  Condition object\'s IsApplicable method
 
+Upon success, returns the applicable Transaction object.
+Otherwise, undef is returned.
+
+If the Scrip is in the TransactionCreate Stage (the usual case), only test
+the associated Transaction object to see if it is applicable.
+
+For Scrips in the TransactionBatch Stage, test all Transaction objects
+created during the Ticket object's lifetime, and returns the first one
+that is applicable.
+
 =cut
 
 sub IsApplicable {
@@ -388,14 +403,35 @@
     my $return;
     eval {
 
-        #Load the scrip's Condition object
-       $self->ConditionObj->LoadCondition(
-                                      ScripObj       => $self,
-                                      TicketObj      => $args{'TicketObj'},
-                                      TransactionObj => $args{'TransactionObj'},
-        );
+	my @Transactions;
 
-        $return =  $self->ConditionObj->IsApplicable();
+        if ( $self->Stage eq 'TransactionCreate') {
+	    # Only look at our current Transaction
+	    @Transactions = ( $args{'TransactionObj'} );
+        }
+        elsif ( $self->Stage eq 'TransactionBatch') {
+	    # Look at all Transactions in this Batch
+            @Transactions = @{ $args{'TicketObj'}->TransactionBatch || [] };
+        }
+	else {
+	    $RT::Logger->error( "Unknown Scrip stage:" . $self->Stage );
+	    return (undef);
+	}
+
+	foreach my $TransactionObj ( @Transactions ) {
+	    # Load the scrip's Condition object
+	    $self->ConditionObj->LoadCondition(
+		ScripObj       => $self,
+		TicketObj      => $args{'TicketObj'},
+		TransactionObj => $TransactionObj,
+	    );
+
+            if ( $self->ConditionObj->IsApplicable() ) {
+	        # We found an application Transaction -- return it
+                $return = $TransactionObj;
+                last;
+            }
+	}
     };
     if ($@) {
         $RT::Logger->error( "Scrip IsApplicable " . $self->Id . " died. - " . $@ );


More information about the Rt-commit mailing list