[Rt-commit] r9900 - in rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT: Extension

audreyt at bestpractical.com audreyt at bestpractical.com
Tue Dec 11 19:52:00 EST 2007


Author: audreyt
Date: Tue Dec 11 19:52:00 2007
New Revision: 9900

Modified:
   rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Action/RuleManager.pm
   rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Extension/RuleManager.pm

Log:
* RuleManager: Everything should now work. (modulo bugs and tests.)

Modified: rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Action/RuleManager.pm
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Action/RuleManager.pm	(original)
+++ rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Action/RuleManager.pm	Tue Dec 11 19:52:00 2007
@@ -47,11 +47,11 @@
 # END BPS TAGGED BLOCK }}}
 package RT::Action::RuleManager;
 use RT::Extension::RuleManager;
-require RT::Action::Generic;
+require RT::Action::Autoreply;
 
 use strict;
 use vars qw/@ISA/;
- at ISA = qw(RT::Action::Generic);
+ at ISA = qw(RT::Action::Autoreply);
 
 # {{{ sub Describe 
 sub Describe  {
@@ -70,23 +70,85 @@
         push @matched, $rule;
         last if $rule->Final;
     }
-    $self->{Matched} = \@matched;
-    return 0+ at matched;
+
+    if (@matched) {
+        $self->{Matched} = \@matched;
+        return 1;
+    }
+    else {
+        return 0;
+    }
 }
 
 sub MatchRule {
-    # ...compile the Match using globlike syntax...
-    # ...then compare it against TransactionObj fields...
+    my $self = shift;
+    my $rule = shift;
+
+    my $pattern = $rule->PrettyPattern;
+    return 1 if $pattern eq '*';
+
+    my $field = $rule->Field;
+    my $val;
+    if ($self->TransactionObj->can($field)) {
+        $val = $self->TransactionObj->$field;
+    }
+    elsif (my $att = $self->TransactionObj->Attachments->First) {
+        if ($att->can($field)) {
+            $val = $att->$field;
+        }
+        else {
+            $val = $att->GetHeader($field);
+        }
+    }
+    else {
+        return undef;
+    }
+
+    $pattern = quotemeta($pattern);
+    $pattern =~ s/\\\*/.*/;
+    $pattern =~ s/\\\?/./;
+
+    return($val =~ /^$pattern$/);
 }
 
 sub Commit {
     my $self = shift;
     foreach my $rule (@{$self->{Matched} || []}) {
-        # Run a rule depending on the handler.
-        # (this may involve creating other RT::Action::* objects and delegate to them.)
+        my $handler = $rule->Handler;
+        if ($handler eq 'Send no autoreply') {
+            next; # Do nothing.
+        }
+        elsif ($handler eq "Set the ticket's owner as this user:") {
+            $self->TicketObj->SetOwner($rule->Argument);
+        }
+        elsif ($handler eq 'Move the ticket to this queue:') {
+            $self->TicketObj->SetQueue($rule->Argument);
+        }
+        elsif ($handler eq 'Send the autoreply in this template:') {
+            local $self->{TemplateObj} = bless {
+                user    => $self->CurrentUser,
+                fetched => { content => 1, queue => 1 },
+                values  => {
+                    queue   => 0,
+                    content => $rule->Argument,
+                },
+            } => 'RT::Template';
+
+            $self->SUPER::Prepare;
+            $self->SUPER::Commit(@_);
+        }
+        else {
+            $RT::Logger->error("Unknown handler: $handler");
+            next;
+        }
     }
 }
 
+sub TemplateObj {
+    my $self = shift;
+    $self->{TemplateObj};
+}
+
 eval "require RT::Action::RuleManager_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RuleManager_Vendor.pm});
 eval "require RT::Action::RuleManager_Local";

Modified: rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Extension/RuleManager.pm
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Extension/RuleManager.pm	(original)
+++ rt/branches/3.6-EXPERIMENTAL-ABERDEEN/lib/RT/Extension/RuleManager.pm	Tue Dec 11 19:52:00 2007
@@ -7,7 +7,7 @@
 use constant RuleClass => 'RT::Extension::RuleManager::Rule';
 use constant FieldOptions => (
     'Subject', # loc
-    'Sender',  # loc
+    'From',    # loc
     'Body',    # loc
 );
 use constant HandlerOptions => (
@@ -103,6 +103,7 @@
 
 sub _load {
     my $self = shift;
+    local $YAML::Syck::ImplicitUnicode = 1;
     return Load($self->_template->Content);
 }
 
@@ -120,6 +121,7 @@
         push @to_save, \%this;
     }
 
+    local $YAML::Syck::ImplicitUnicode = 1;
     return $self->_template->SetContent(Dump(\@to_save));
 }
 
@@ -129,6 +131,8 @@
     my $rule_manager_template = RT::Template->new($RT::SystemUser);
     $rule_manager_template->Load(RuleManagerTemplate);
     if (!$rule_manager_template->Id) {
+        local $YAML::Syck::ImplicitUnicode = 1;
+
         my $autoreply_template = RT::Template->new($RT::SystemUser);
         $autoreply_template->Load('Autoreply');
         $rule_manager_template->Create(


More information about the Rt-commit mailing list