[Rt-commit] r19858 - in rt/3.999/trunk: . lib/RT lib/RT/Condition lib/RT/Lorzy/Package lib/RT/Model lib/RT/Shredder lib/RT/Shredder/Plugin t
clkao at bestpractical.com
clkao at bestpractical.com
Wed Jun 3 05:19:42 EDT 2009
Author: clkao
Date: Wed Jun 3 05:19:42 2009
New Revision: 19858
Removed:
rt/3.999/trunk/lib/RT/Condition/AnyTransaction.pm
rt/3.999/trunk/lib/RT/Model/ScripCondition.pm
rt/3.999/trunk/lib/RT/Model/ScripConditionCollection.pm
rt/3.999/trunk/lib/RT/Shredder/ScripCondition.pm
Modified:
rt/3.999/trunk/ (props changed)
rt/3.999/trunk/lib/RT/Bootstrap.pm
rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm
rt/3.999/trunk/lib/RT/Shredder.pm
rt/3.999/trunk/lib/RT/Shredder/Plugin/Summary.pm
rt/3.999/trunk/lib/RT/Shredder/User.pm
rt/3.999/trunk/t/00-compile.t
rt/3.999/trunk/t/api/action-createtickets.t
Log:
r43162 at mtl-2: clkao | 2009-06-03 00:15:15 +0800
- Create branch condition-refactor
r43163 at mtl-2: clkao | 2009-06-03 00:42:34 +0800
thank god model scrip reference was removed last time.
r43206 at mtl-2: clkao | 2009-06-03 15:50:24 +0800
remove scripcondition, use the hash directly in RT.Condition.Applicable for now.
r43207 at mtl-2: clkao | 2009-06-03 17:05:11 +0800
migrate On Create to lorzy.
r43208 at mtl-2: clkao | 2009-06-03 17:09:41 +0800
migrate On Create to lorzy.
r43209 at mtl-2: clkao | 2009-06-03 17:11:10 +0800
grr
r43210 at mtl-2: clkao | 2009-06-03 17:16:52 +0800
replace all condition::anytransaction-based ones with native lorzy code.
r43211 at mtl-2: clkao | 2009-06-03 17:18:27 +0800
config.yml changes unwanted
Modified: rt/3.999/trunk/lib/RT/Bootstrap.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Bootstrap.pm (original)
+++ rt/3.999/trunk/lib/RT/Bootstrap.pm Wed Jun 3 05:19:42 2009
@@ -431,20 +431,6 @@
#print "done.\n";
}
- if (@scrip_conditions) {
-
- #print "Creating scrip_conditions...";
-
- for my $item (@scrip_conditions) {
- my $new_entry = RT::Model::ScripCondition->new( current_user => RT->system_user );
- my $return = $new_entry->create(%$item);
-
- #print $return. ".";
- }
-
- #print "done.\n";
- }
-
if (@Templates) {
#print "Creating templates...";
Modified: rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm (original)
+++ rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm Wed Jun 3 05:19:42 2009
@@ -2,6 +2,89 @@
use strict;
use base 'Lorzy::Package';
+my %mymap = ( 'On Create' => 'OnCreate',
+ 'On Transaction' => 'OnTransaction',
+ 'On Correspond' => 'OnCorrespond',
+ 'On comment' => 'OnComment',
+ 'On Status Change' => 'OnStatusChange',
+ );
+
+my @scrip_conditions = (
+ {
+
+ name => 'On priority Change', # loc
+ description => 'Whenever a ticket\'s priority changes', # loc
+ applicable_trans_types => 'set',
+ exec_module => 'priorityChange',
+ },
+ {
+
+ name => 'On owner Change', # loc
+ description => 'Whenever a ticket\'s owner changes', # loc
+ applicable_trans_types => 'any',
+ exec_module => 'OwnerChange',
+
+ },
+ {
+
+ name => 'On queue Change', # loc
+ description => 'Whenever a ticket\'s queue changes', # loc
+ applicable_trans_types => 'set',
+ exec_module => 'QueueChange',
+
+ },
+ # not tested
+ { name => 'On Resolve', # loc
+ description => 'Whenever a ticket is resolved', # loc
+ applicable_trans_types => 'status',
+ exec_module => 'StatusChange',
+ argument => 'resolved'
+
+ },
+
+ # not tested
+ { name => 'On Close', # loc
+ description => 'Whenever a ticket is closed', # loc
+ applicable_trans_types => 'status,set',
+ exec_module => 'CloseTicket',
+ },
+ { name => 'On Reopen', # loc
+ description => 'Whenever a ticket is reopened', # loc
+ applicable_trans_types => 'status,set',
+ exec_module => 'ReopenTicket',
+ },
+
+);
+
+__PACKAGE__->defun( 'Condition.OnTransaction',
+ signature => {
+ 'ticket' => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+ 'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+ },
+ native => sub {
+ return 1;
+ },
+);
+
+my %simple_txn_cond = ( 'OnCreate' => 'create',
+ 'OnCorrespond' => 'correspond',
+ 'OnComment' => 'comment',
+ 'OnStatusChange' => 'status',
+ );
+
+for my $name ( keys %simple_txn_cond ) {
+ __PACKAGE__->defun( "Condition.$name",
+ signature => {
+ 'ticket' => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+ 'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+ },
+ native => sub {
+ my $args = shift;
+ return $args->{transaction}->type eq $simple_txn_cond{$name};
+ },
+ );
+}
+
__PACKAGE__->defun( 'Condition.Applicable',
signature => {
'name' => Lorzy::FunctionArgument->new( name => 'name' ),
@@ -9,24 +92,38 @@
'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
},
native => sub {
- my $args = shift;
- my $scrip_condition = RT::Model::ScripCondition->new;
- $scrip_condition->load($args->{name}) or die "Can't load scrip condition: $args->{name}";
- $scrip_condition->load_condition(
- ticket_obj => $args->{'ticket'},
- transaction_obj => $args->{'transaction'},
- ) or die "Can't load condition: $args->{name}";
+ my $args = shift;
+ my $eval = shift;
-
- # XXX: this is so wrong, the applicable_trans_type check is
- # done in scrip level rather than condition level. see
- # RT::Model::Scrip.
+ if (my $lorzy_cond = $mymap{$args->{name}}) {
+ $lorzy_cond = 'RT.Condition.'.$lorzy_cond;
+ return $eval->resolve_symbol_name($lorzy_cond)->apply
+ ( $eval,
+ { transaction => $args->{transaction},
+ ticket => $args->{ticket}
+ });
+ }
my $txn_type = $args->{transaction}->type;
+
+ my ($condition_config) = grep { $args->{name} eq $_->{name} } @scrip_conditions
+ or die "Can't load scrip condition: $args->{name}";
+
+ my $type = "RT::Condition::" . $condition_config->{exec_module};
+
+ Jifty::Util->require($type);
+
+ my $condition = $type->new(
+ ticket_obj => $args->{'ticket'},
+ transaction_obj => $args->{'transaction'},
+ 'argument' => $condition_config->{argument},
+ 'applicable_trans_types' => $condition_config->{applicable_trans_types},
+ );
+
return 0
- unless ( $scrip_condition->applicable_trans_types =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
+ unless ( $condition_config->{applicable_trans_types} =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
- return $scrip_condition->is_applicable();
+ return $condition->is_applicable();
},
);
Modified: rt/3.999/trunk/lib/RT/Shredder.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder.pm (original)
+++ rt/3.999/trunk/lib/RT/Shredder.pm Wed Jun 3 05:19:42 2009
@@ -219,7 +219,6 @@
require RT::Shredder::Principal;
require RT::Shredder::Queue;
require RT::Shredder::ScripAction;
- require RT::Shredder::ScripCondition;
require RT::Shredder::Template;
require RT::Shredder::ObjectCustomFieldValue;
require RT::Shredder::Ticket;
@@ -239,7 +238,6 @@
Principal
Queue
ScripAction
- ScripCondition
Template
ObjectCustomFieldValue
Ticket
Modified: rt/3.999/trunk/lib/RT/Shredder/Plugin/Summary.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/Plugin/Summary.pm (original)
+++ rt/3.999/trunk/lib/RT/Shredder/Plugin/Summary.pm Wed Jun 3 05:19:42 2009
@@ -99,7 +99,6 @@
# User.pm
# ScripAction.pm - works fine with defaults
-# ScripCondition.pm - works fine with defaults
# Template.pm - works fine with defaults
sub write_down_cached_group_member { return 1 }
Modified: rt/3.999/trunk/lib/RT/Shredder/User.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/User.pm (original)
+++ rt/3.999/trunk/lib/RT/Shredder/User.pm Wed Jun 3 05:19:42 2009
@@ -68,7 +68,6 @@
PrincipalCollection
QueueCollection
ScripActionCollection
- ScripConditionCollection
TemplateCollection
ObjectCustomFieldValueCollection
TicketCollection
Modified: rt/3.999/trunk/t/00-compile.t
==============================================================================
--- rt/3.999/trunk/t/00-compile.t (original)
+++ rt/3.999/trunk/t/00-compile.t Wed Jun 3 05:19:42 2009
@@ -2,7 +2,7 @@
use strict;
use warnings;
use RT::Test;
-use Test::More tests => 31;
+use Test::More tests => 26;
require_ok("RT");
require_ok("RT::Test");
@@ -21,12 +21,7 @@
require_ok("RT::Model::GroupMemberCollection");
require_ok("RT::Model::ScripActionCollection");
require_ok("RT::Model::TransactionCollection");
-require_ok("RT::Model::ScripCondition");
require_ok("RT::ScripAction::Generic");
-require_ok("RT::Model::ScripConditionCollection");
-require_ok("RT::Search::Generic");
-require_ok("RT::Search::Generic");
-require_ok("RT::Search::Generic");
require_ok("RT::Search::Generic");
require_ok("RT::ScripAction::SendEmail");
require_ok("RT::Model::CachedGroupMemberCollection");
Modified: rt/3.999/trunk/t/api/action-createtickets.t
==============================================================================
--- rt/3.999/trunk/t/api/action-createtickets.t (original)
+++ rt/3.999/trunk/t/api/action-createtickets.t Wed Jun 3 05:19:42 2009
@@ -2,7 +2,7 @@
use strict;
use warnings;
use RT::Test; use Test::More;
-plan tests => 43;
+plan tests => 42;
use RT;
@@ -12,7 +12,6 @@
ok (require RT::ScripAction::CreateTickets);
use_ok('RT::Model::Template');
use_ok('RT::Model::ScripAction');
-use_ok('RT::Model::ScripCondition');
use_ok('RT::Model::Ticket');
my $approvalsq = RT::Model::Queue->new(current_user => RT->system_user);
More information about the Rt-commit
mailing list