[Rt-commit] r18429 - in rt/3.999/branches/lorzy: lib/RT lib/RT/Model lib/RT/ScripAction lib/RT/Shredder t

clkao at bestpractical.com clkao at bestpractical.com
Tue Feb 17 10:28:32 EST 2009


Author: clkao
Date: Tue Feb 17 10:28:32 2009
New Revision: 18429

Modified:
   rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
   rt/3.999/branches/lorzy/lib/RT/Model/Ticket.pm
   rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm
   rt/3.999/branches/lorzy/lib/RT/Rule.pm
   rt/3.999/branches/lorzy/lib/RT/ScripAction/SendEmail.pm
   rt/3.999/branches/lorzy/lib/RT/Shredder/Queue.pm
   rt/3.999/branches/lorzy/t/00-compile.t
   rt/3.999/branches/lorzy/t/lorzy/condition.t

Log:
intermediate change for removing mode::scrip.


Modified: rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm	Tue Feb 17 10:28:32 2009
@@ -457,31 +457,40 @@
         #print "done.\n";
     }
     if (@Scrips) {
-
-        #print "Creating scrips...";
-
+        # XXX: put into RT::Model::Rules
+        require RT::Lorzy;
+        require Lorzy::Builder;
+        my $sigs = { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+                     transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) };
+        my $builder = Lorzy::Builder->new();
         for my $item (@Scrips) {
-            my $new_entry = RT::Model::Scrip->new( current_user => RT->system_user );
-
-            my @queues
-                = ref $item->{'queue'} eq 'ARRAY'
-                ? @{ $item->{'queue'} }
-                : $item->{'queue'} || 0;
-            push @queues, 0 unless @queues;    # add global queue at least
-
-            foreach my $q (@queues) {
-                my ( $return, $msg ) = $new_entry->create( %$item, queue => $q );
-                if ($return) {
-
-                    #print $return. ".";
-                } else {
-
-                    #print "(Error: $msg)\n";
-                }
-            }
+            my $condition  = $builder->defun(
+                ops => [{ name => 'RT.Condition.Applicable',
+                          args => {
+                              name => $item->{scrip_condition},
+                              ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+                              transaction => { name => 'Symbol', args => { symbol => 'transaction' } }
+                          } }
+                    ],
+                signature => $sigs,
+
+            );
+
+            my $action  = $builder->defun(
+                ops => [ { name => 'RT.ScripAction.Run',
+                           args => {
+                               name => $item->{scrip_action},
+                               template => $item->{template},
+                               ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+                               transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
+                           } } ],
+                signature => $sigs);
+
+            RT::Lorzy::Dispatcher->add_rule(
+                RT::Lorzy::Rule->new( { condition => $condition,
+                                        action => $action } )
+                );
         }
-
-        #print "done.\n";
     }
 
     if (@Attributes) {

Modified: rt/3.999/branches/lorzy/lib/RT/Model/Ticket.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Model/Ticket.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/Model/Ticket.pm	Tue Feb 17 10:28:32 2009
@@ -2643,14 +2643,6 @@
     my $batch = $self->transaction_batch or return;
     return unless @$batch;
 
-    require RT::Model::ScripCollection;
-    RT::Model::ScripCollection->new( current_user => RT->system_user )->apply(
-        stage           => 'transaction_batch',
-        ticket_obj      => $self,
-        transaction_obj => $batch->[0],
-        type            => join( ',', map $_->type, grep defined, @{$batch} )
-    );
-
     # Entry point of the rule system
     my $rules = RT::Ruleset->find_all_rules(
         stage           => 'transaction_batch',

Modified: rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm	Tue Feb 17 10:28:32 2009
@@ -304,7 +304,6 @@
 use vars qw( %_brief_descriptions $Preferredcontent_type );
 
 use RT::Model::AttachmentCollection;
-use RT::Model::ScripCollection;
 use RT::Ruleset;
 
 
@@ -375,16 +374,6 @@
     #Provide a way to turn off scrips if we need to
     Jifty->log->debug( 'About to think about scrips for transaction #' . $self->id );
     if ( $activate_scrips and $args{'object_type'} eq 'RT::Model::Ticket' ) {
-        $self->{'scrips'} = RT::Model::ScripCollection->new( current_user => RT->system_user );
-
-        Jifty->log->debug( 'About to prepare scrips for transaction #' . $self->id );
-        $self->{'scrips'}->prepare(
-            stage       => 'transaction_create',
-            type        => $args{'type'},
-            ticket      => $args{'object_id'},
-            transaction => $self->id,
-        );
-
         # Entry point of the rule system
         my $ticket = RT::Model::Ticket->new( current_user => RT->system_user );
         $ticket->load( $args{'object_id'} );
@@ -397,7 +386,6 @@
         
         if ( $commit_scrips ) {
             Jifty->log->debug( 'About to commit scrips for transaction #' . $self->id );
-            $self->{'scrips'}->commit;
             RT::Ruleset->commit_rules($rules);
             
         } else {

Modified: rt/3.999/branches/lorzy/lib/RT/Rule.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Rule.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/Rule.pm	Tue Feb 17 10:28:32 2009
@@ -98,7 +98,6 @@
 
     # XXX: fix template to allow additional arguments to be passed from here
     $action->{'template_obj'} = $template;
-    $action->{'scrip_obj'} = RT::Model::Scrip->new( current_user => $self->current_user); # Stub. sendemail action really wants a scripobj available
     $action->prepare or return;
     $action->commit;
 

Modified: rt/3.999/branches/lorzy/lib/RT/ScripAction/SendEmail.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/ScripAction/SendEmail.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/ScripAction/SendEmail.pm	Tue Feb 17 10:28:32 2009
@@ -291,8 +291,8 @@
 
     Jifty->log->info( $msgid . " #" . $self->ticket_obj->id . "/" .
             $self->transaction_obj->id . " - Scrip "
-            . ( $self->scrip_obj->id || '#rule' ) . " "
-            . ( $self->scrip_obj->description || '' ) );
+            . ( '#rule' ) . " ");
+
 
     my $status = RT::Interface::Email::send_email(
         entity      => $mime_obj,
@@ -585,7 +585,7 @@
         if (    $msgid
             and $msgid =~ s/<(rt-.*?-\d+-\d+)\.(\d+)-\d+-\d+\@\QRT->config->get('Organization')\E>$/
                          "<$1." . $self->ticket_obj->id
-                          . "-" . $self->scrip_obj->id
+                          . "-" . '#rule'
                           . "-" . $self->scrip_action_obj->{_Message_ID}
                           . "@" . RT->config->get('Organization') . ">"/eg
             and $2 == $self->ticket_obj->id
@@ -596,7 +596,7 @@
             $self->set_header(
                 'Message-ID' => RT::Interface::Email::gen_message_id(
                     ticket       => $self->ticket_obj,
-                    scrip        => $self->scrip_obj,
+                    scrip        => '#rule',
                     scrip_action => $self->scrip_action_obj
                 ),
             );
@@ -1003,7 +1003,7 @@
         for ( @references, @in_reply_to ) {
             s/<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@\Q$org\E>$/
           "<$1." . $self->ticket_obj->id .
-             "-" . $self->scrip_obj->id .
+             "-" . '#rule',
              "-" . $self->scrip_action_obj->{_Message_ID} .
              "@" . $org . ">"/eg
         }

Modified: rt/3.999/branches/lorzy/lib/RT/Shredder/Queue.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Shredder/Queue.pm	(original)
+++ rt/3.999/branches/lorzy/lib/RT/Shredder/Queue.pm	Tue Feb 17 10:28:32 2009
@@ -79,11 +79,6 @@
     $objs->limit( column => 'instance', value => $self->id );
     push( @$list, $objs );
 
-    # Scrips
-    $objs = RT::Model::ScripCollection->new;
-    $objs->limit_to_queue( $self->id );
-    push( @$list, $objs );
-
     # Templates
     $objs = $self->templates;
     push( @$list, $objs );

Modified: rt/3.999/branches/lorzy/t/00-compile.t
==============================================================================
--- rt/3.999/branches/lorzy/t/00-compile.t	(original)
+++ rt/3.999/branches/lorzy/t/00-compile.t	Tue Feb 17 10:28:32 2009
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT::Test;
-use Test::More tests => 33;
+use Test::More tests => 32;
 
 require_ok("RT");
 require_ok("RT::Test");
@@ -12,7 +12,6 @@
 require_ok("RT::Interface::Email");
 require_ok("RT::Model::LinkCollection");
 require_ok("RT::Model::QueueCollection");
-require_ok("RT::Model::ScripCollection");
 require_ok("RT::Model::TemplateCollection");
 require_ok("RT::Model::PrincipalCollection");
 require_ok("RT::Model::AttachmentCollection");

Modified: rt/3.999/branches/lorzy/t/lorzy/condition.t
==============================================================================
--- rt/3.999/branches/lorzy/t/lorzy/condition.t	(original)
+++ rt/3.999/branches/lorzy/t/lorzy/condition.t	Tue Feb 17 10:28:32 2009
@@ -18,17 +18,13 @@
 $eval->load_package($_) for qw(Str Native);
 $eval->load_package('RT', 'RT::Lorzy::Package::RT');
 
-my $tree    = [ { name => 'IfThen',
-                  args => { if_true => { name => 'True' },
-                            if_false => { name => 'False' },
-                            condition => { name => 'RT.Condition.Applicable',
-                                args => {
-                                    name => "On Create",
-                                    ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
-                                    transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
-                                    }
-                            }
-                        } } ];
+my $tree    = [ { name => 'RT.Condition.Applicable',
+                  args => {
+                      name => "On Create",
+                      ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+                      transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
+                  }
+              } ];
 
 my $builder = Lorzy::Builder->new();
 my $on_created  = $builder->defun(


More information about the Rt-commit mailing list