[Bps-public-commit] r10991 - RT-Action-LinearEscalate/lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Tue Mar 4 10:24:44 EST 2008


Author: ruz
Date: Tue Mar  4 10:24:42 2008
New Revision: 10991

Modified:
   RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm

Log:
* cleanup code a little

Modified: RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm
==============================================================================
--- RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm	(original)
+++ RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm	Tue Mar  4 10:24:42 2008
@@ -87,7 +87,6 @@
 =cut
 
 package RT::Action::LinearEscalate;
-require RT::Action::Generic;
 
 use strict;
 use warnings;
@@ -119,14 +118,14 @@
     my $ticket = $self->TicketObj;
     if ( $ticket->Priority >= $ticket->FinalPriority ) {
         # no update necessary.
-        return 0;
+        return 1;
     }
 
-    #compute the number of business days until the ticket is due
+    # TODO: compute the number of business days until the ticket is due
 
     # If we don't have a due date, get out
-    my $due = $ticket->DueObj->Unix; 
-    return 0 unless $due > 0;
+    my $due = $ticket->DueObj->Unix;
+    return 1 unless $due > 0;
 
     # now we know we have a due date. for every day that passes,
     # increment priority according to the formula
@@ -141,27 +140,23 @@
 
     my $new_priority = int($percent_complete * $standard_range) + $ticket->InitialPriority;
 	$new_priority = $ticket->FinalPriority if $new_priority > $ticket->FinalPriority;
-    # if the priority hasn't changed do nothing
-    if ( $ticket->Priority == $new_priority ) {
-        return 0;
-    }
-
     $self->{'new_priority'} = $new_priority;
 
     return 1;
 }
 
-# }}}
-
 sub Commit {
     my $self = shift;
 
-    my $ticket = $ticket->TicketObj;
+    my $new_value = $self->{'new_priority'};
+    return 1 unless defined $new_value;
 
-    my ( $val, $msg );
+    my $ticket = $self->TicketObj;
+    # if the priority hasn't changed do nothing
+    return 1 if $ticket->Priority == $new_value;
 
-    #testing purposes only, it's a dirty ugly hack
-    if ($self->Argument =~ /RecordTransaction:(\d); UpdateLastUpdated:(\d)/) {
+    # testing purposes only, it's a dirty ugly hack
+    if ( $self->Argument =~ /RecordTransaction:(\d); UpdateLastUpdated:(\d)/ ) {
         $RecordTransaction = (defined $1 ? $1 : $RecordTransaction);
         $UpdateLastUpdated = (defined $2 ? $2 : $UpdateLastUpdated);
         $RT::Logger->warning("Overrode RecordTransaction: $RecordTransaction") 
@@ -170,34 +165,36 @@
             if defined $2;
     }
 
-    if ( $ticket->Priority < $self->{'prio'} ) {
-        unless ($RecordTransaction) {
+    $RT::Logger->debug(
+        'Linearly escalating priority of ticket #'. $ticket->Id
+        .' from '. $ticket->Priority .' to '. $new_value
+    );
 
-        $RT::Logger->warning( "Updating priority of ticket",
-                              $ticket->Id,
-                              "from", $ticket->Priority,
-                              "to", $self->{'prio'} );
-
-
-            unless ($UpdateLastUpdated) {
-                ( $val, $msg ) = $ticket->__Set( Field => 'Priority',
-                                                          Value => $self->{'prio'},
-                                                         );
-            }
-            else {
-                ( $val, $msg ) = $ticket->_Set( Field => 'Priority',
-                                                         Value => $self->{'prio'},
-                                                         RecordTransaction => 0,
-                                                        );
-            }
+    my ( $val, $msg );
+    unless ( $RecordTransaction ) {
+        unless ($UpdateLastUpdated) {
+            ( $val, $msg ) = $ticket->__Set(
+                Field => 'Priority',
+                Value => $new_value,
+            );
         }
         else {
-            ( $val, $msg ) = $ticket->SetPriority( $self->{'prio'} );
-        }
-        unless ($val) {
-            $RT::Logger->debug( $self . " $msg\n" );
+            ( $val, $msg ) = $ticket->_Set(
+                Field => 'Priority',
+                Value => $new_value,
+                RecordTransaction => 0,
+            );
         }
     }
+    else {
+        ( $val, $msg ) = $ticket->SetPriority( $new_value );
+    }
+
+    unless ($val) {
+        $RT::Logger->error( "Couldn't set new priority value: $msg" );
+        return (0, $msg);
+    }
+    return 1;
 }
 
 eval "require RT::Action::LinearEscalate_Vendor";



More information about the Bps-public-commit mailing list