[Rt-commit] r9514 - rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools

ruz at bestpractical.com ruz at bestpractical.com
Wed Oct 31 08:50:02 EDT 2007


Author: ruz
Date: Wed Oct 31 08:49:58 2007
New Revision: 9514

Modified:
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/ScriptedAction.html

Log:
* fix ScriptedActions when template hasn't been selected

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/ScriptedAction.html
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/ScriptedAction.html	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/ScriptedAction.html	Wed Oct 31 08:49:58 2007
@@ -378,42 +378,51 @@
             ARGSRef => { %ARGS, AddRequestor => $addr },
         );
 
-        # find the Create transaction, so we can pass it to the template
-        my $transaction;
-        while ( $transaction = $Ticket->Transactions->Next ) {
-            last if $transaction->Type eq 'Create';
+        my $TemplateObj = RT::Template->new( $session{'CurrentUser'} );
+        if ( $ARGS{'Template'} ) {
+            $TemplateObj->Load( $ARGS{'Template'} );
+            $RT::Logger->error("Couldn't load template '$ARGS{'Template'}'")
+                unless $TemplateObj->id;
         }
 
-        # if the template's argument contains _ADDR_ or _IP_
-        # substitute appropriately
-        my $arg = $ARGS{'TemplateArg'};
-        $arg =~ s/_ADDR_/$addr/g;
-        $arg =~ s/_IP_/$ip/g;
+        my @updateresults;
+        if ( $TemplateObj->id ) {
 
-        # load the selected template
-        my $TemplateObj = RT::Template->new( $session{'CurrentUser'} );
-        $TemplateObj->Load( $ARGS{'Template'} );
-        # XXX: why don't we handle return values?
-        my ( $result, $message ) = $TemplateObj->Parse(
-            Argument       => $arg,
-            TicketObj      => $Ticket,
-            TransactionObj => $transaction,
-        );
-        unless ( $result ) {
-            $RT::Logger->error("Couldn't parse template: $message");
+            # find the Create transaction, so we can pass it to the template
+            my $transaction;
+            while ( $transaction = $Ticket->Transactions->Next ) {
+                last if $transaction->Type eq 'Create';
+            }
+
+            # if the template's argument contains _ADDR_ or _IP_
+            # substitute appropriately
+            my $arg = $ARGS{'TemplateArg'};
+            $arg =~ s/_ADDR_/$addr/g;
+            $arg =~ s/_IP_/$ip/g;
+
+            my ( $result, $message ) = $TemplateObj->Parse(
+                Argument       => $arg,
+                TicketObj      => $Ticket,
+                TransactionObj => $transaction,
+            );
+            unless ( $result ) {
+                $RT::Logger->error("Couldn't parse template: $message");
+            }
+
+            # add the template's MIMEObj to the Attachments list
+            $session{'Attachments'} = {
+                %{$session{'Attachments'} || {}},
+                _Body => $TemplateObj->MIMEObj,
+            };
+
+            # the content will be part of the template, if desired
+            $ARGS{'UpdateContent'} = " ";
+            $ARGS{'UpdateAttachments'} = $session{'Attachments'};
+            @updateresults = ProcessUpdateMessage(
+                TicketObj => $Ticket, ARGSRef => \%ARGS,
+            );
         }
 
-        # add the template's MIMEObj to the Attachments list
-        $session{'Attachments'} = { _Body => $TemplateObj->MIMEObj,
-                                    %{$session{'Attachments'} || {}} };
-
-        # the content will be part of the template, if desired
-        $ARGS{'UpdateContent'} = " ";
-        $ARGS{'UpdateAttachments'} = delete $session{'Attachments'};
-        my @updateresults = ProcessUpdateMessage(
-            TicketObj => $Ticket, ARGSRef => \%ARGS,
-        );
-
         push @finalresults, map { loc("Ticket [_1]: [_2]", $Ticket->Id, $_) }
             @watchresults, @updateresults;
 


More information about the Rt-commit mailing list