[Rt-commit] r4247 - in rtir/branches/1.9-EXPERIMENTAL: . lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Sun Dec 4 19:09:43 EST 2005


Author: ruz
Date: Sun Dec  4 19:09:42 2005
New Revision: 4247

Added:
   rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetState.pm
Modified:
   rtir/branches/1.9-EXPERIMENTAL/   (props changed)
   rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm
   rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentReportState.pm
   rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentState.pm
   rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetInvestigationState.pm
Log:
 r426 at cubic-pc:  cubic | 2005-12-05 03:09:10 +0300
  r405 at cubic-pc:  cubic | 2005-12-05 03:01:02 +0300
  * RTIR_SetState action
 


Modified: rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm	Sun Dec  4 19:09:42 2005
@@ -45,52 +45,27 @@
 # }}} END BPS TAGGED BLOCK
 #
 package RT::Action::RTIR_SetBlockState;
-use strict;
-use base 'RT::Action::RTIR';
-
-=head2 Prepare
-
-Always run this.
-
-=cut
-
-sub Prepare {
-    my $self = shift;
 
-    return 1;
-}
-
-# {{{ sub Commit
+use strict;
+use base 'RT::Action::RTIR_SetState';
 
-=head2 Commit
+=head1 GetState
 
-Set the Block state.
+Returns state of the C<Block>.
 
 =cut
 
-my %state = (
-    new      => 'pending activation',
-    open     => 'active',
-    stalled  => 'pending removal',
-    resolved => 'removed',
-);
-
-sub Commit {
+sub GetState {
     my $self = shift;
-
-    my $cf = new RT::CustomField( $self->TransactionObj->CurrentUser );
-    $cf->LoadByNameAndQueue( Queue => $self->TicketObj->QueueObj->Id, Name => '_RTIR_State' );
-    return 1 unless $cf->Id;
-
-    my $state = $state{ $self->TicketObj->Status };
-    return 1 unless $state;
-
-    $self->TicketObj->AddCustomFieldValue( Field => $cf->id, Value => $state );
-    return 1;
+    my %state = (
+        new      => 'pending activation',
+        open     => 'active',
+        stalled  => 'pending removal',
+        resolved => 'removed',
+    );
+    return $state{ $self->TicketObj->Status } || '';
 }
 
-# }}}
-
 eval "require RT::Action::RTIR_SetBlockState_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetBlockState_Vendor.pm});
 eval "require RT::Action::RTIR_SetBlockState_Local";

Modified: rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentReportState.pm
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentReportState.pm	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentReportState.pm	Sun Dec  4 19:09:42 2005
@@ -46,41 +46,18 @@
 #
 package RT::Action::RTIR_SetIncidentReportState;
 
-
 use strict;
+use base 'RT::Action::RTIR_SetState';
 
-use base 'RT::Action::RTIR';
-
-=head2 Prepare
-
-Always run this.
-
-=cut
-
-
-sub Prepare {
-    my $self = shift;
-
-    return 1;
-}
-
-# {{{ sub Commit
-
-=head2 Commit
+=head2 GetState
 
-Set the Block state.
+Returns state of the C<Incident Report>.
 
 =cut
 
-sub Commit {
+sub GetState {
     my $self = shift;
 
-    my $cf = RT::CustomField->new($self->TransactionObj->CurrentUser);
-    $cf->LoadByNameAndQueue(Queue => $self->TicketObj->QueueObj->Id, Name => '_RTIR_State');
-    unless ($cf->Id) {
-        return(1);
-    }
-
     my $state;
     my $status = $self->TicketObj->Status;
     if ( $status =~ /^(?:new|open|stalled)$/ ) {
@@ -96,16 +73,10 @@
         $state = 'resolved';
     } elsif ($status eq 'rejected') {
         $state = 'rejected';
-    } else {
-        return (1);
     }
-
-    $self->TicketObj->AddCustomFieldValue(Field => $cf->id, Value => $state);
-    return 1;
+    return $state || '';
 }
 
-# }}}
-
 eval "require RT::Action::RTIR_SetIncidentReportState_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetIncidentReportState_Vendor.pm});
 eval "require RT::Action::RTIR_SetIncidentReportState_Local";

Modified: rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentState.pm
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentState.pm	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetIncidentState.pm	Sun Dec  4 19:09:42 2005
@@ -47,54 +47,26 @@
 package RT::Action::RTIR_SetIncidentState;
 
 use strict;
-use base 'RT::Action::RTIR';
+use base 'RT::Action::RTIR_SetState';
 
-=head2 Prepare
+=head2 GetState
 
-Always run this.
+Returns state of the C<Incident>.
 
 =cut
 
-sub Prepare {
+sub GetState {
     my $self = shift;
-
-    return 1;
-}
-
-# {{{ sub Commit
-
-=head2 Commit
-
-Set the Block state.
-
-=cut
-
-my %state = (
-    new      => 'open',
-    open     => 'open',
-    stalled  => 'open',
-    resolved => 'resolved',
-    rejected => 'abandoned',
-);
-
-sub Commit {
-    my $self = shift;
-    my $t = $self->TicketObj;
-
-    my $cf = RT::CustomField->new($self->TransactionObj->CurrentUser);
-    $cf->LoadByNameAndQueue(Queue => $t->QueueObj->Id, Name => '_RTIR_State');
-    return 1 unless $cf->Id;
-
-    my $state = $state{ $t->Status };
-    return 1 unless $state;
-
-    my ($res, $msg) = $t->AddCustomFieldValue(Field => $cf->id, Value => $State);
-    $RT::Logger->info("Couldn't add custom field value: $msg") unless $res;
-    return 1;
+    my %state = (
+        new      => 'open',
+        open     => 'open',
+        stalled  => 'open',
+        resolved => 'resolved',
+        rejected => 'abandoned',
+    );
+    return $state{ $self->TicketObj->Status };
 }
 
-# }}}
-
 eval "require RT::Action::RTIR_SetIncidentState_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetIncidentState_Vendor.pm});
 eval "require RT::Action::RTIR_SetIncidentState_Local";

Modified: rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetInvestigationState.pm
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetInvestigationState.pm	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetInvestigationState.pm	Sun Dec  4 19:09:42 2005
@@ -46,54 +46,25 @@
 #
 package RT::Action::RTIR_SetInvestigationState;
 
-
 use strict;
+use base 'RT::Action::RTIR_SetState';
 
-use base 'RT::Action::RTIR';
-
-=head2 Prepare
-
-Always run this.
-
-=cut
-
-
-sub Prepare {
-    my $self = shift;
-
-    return 1;
-}
-
-# {{{ sub Commit
+=head2 GetState
 
-=head2 Commit
-
-Set the Block state.
+Returns state of the C<Investigation>.
 
 =cut
 
-sub Commit {
+sub GetState {
     my $self = shift;
-
-    my $State;
-    my $cf = RT::CustomField->new($self->TransactionObj->CurrentUser);
-    $cf->LoadByNameAndQueue(Queue => $self->TicketObj->QueueObj->Id, Name => '_RTIR_State');
-    unless ($cf->Id) { 
-	return(1);
-    }
-    if ($self->TicketObj->Status eq 'open' or $self->TicketObj->Status eq 'new') {
-	$State = 'open';
-    } elsif ($self->TicketObj->Status eq 'resolved') {
-	$State = 'resolved';
-    } else {
-	return 0;
-    }
-    $self->TicketObj->AddCustomFieldValue(Field => $cf->id, Value => $State);
-    return 1;
+    my %state = (
+        open => 'new',
+        new  => 'new',
+        resolved => 'resolved',
+    );
+    return $state{ $self->TicketObj->Status } || '';
 }
 
-# }}}
-
 eval "require RT::Action::RTIR_SetInvestigationState_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetInvestigationState_Vendor.pm});
 eval "require RT::Action::RTIR_SetInvestigationState_Local";

Added: rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetState.pm
==============================================================================
--- (empty file)
+++ rtir/branches/1.9-EXPERIMENTAL/lib/RT/Action/RTIR_SetState.pm	Sun Dec  4 19:09:42 2005
@@ -0,0 +1,44 @@
+package RT::Action::RTIR_SetState;
+
+use strict;
+use base 'RT::Action::RTIR';
+
+=head2 Prepare
+
+Always run this.
+
+=cut
+
+sub Prepare { return 1 }
+
+=head2 Commit
+
+Set the state according to the status.
+
+=cut
+
+sub Commit {
+    my $self = shift;
+
+    my $t = $self->TicketObj;
+
+    my $cf = RT::CustomField->new($self->TransactionObj->CurrentUser);
+    $cf->LoadByNameAndQueue(Queue => $t->QueueObj->Id, Name => '_RTIR_State');
+    return 1 unless $cf->Id;
+
+    my $state = $self->GetState;
+    return 1 unless $state;
+
+    my ($res, $msg) = $t->AddCustomFieldValue(Field => $cf->id, Value => $state);
+    $RT::Logger->info("Couldn't add custom field value: $msg") unless $res;
+    return 1;
+}
+
+sub GetState { return '' }
+
+eval "require RT::Action::RTIR_SetState_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetState_Vendor.pm});
+eval "require RT::Action::RTIR_SetState_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetState_Local.pm});
+
+1;


More information about the Rt-commit mailing list