EscalatePriorityLinear

From Request Tracker Wiki
Jump to navigation Jump to search

Version 3.8 and above

See action LinearEscalate

Before version 3.8

EscalatePriorityLinear is a ScripAction which is NOT intended to be called per transaction. It's intended to be called by an RT escalation daemon. (The daemon is called escalator).

EscalatePriorityLinear uses the following formula to change a ticket's priority:

Priority = InitialPriority +

(FinalPriority-InitialPriority) * (Now-Starts) / (DueDate-Starts)

Unless the duedate is past, in which case priority gets bumped straight to final priority.

Unlike RT::Action::EscalatePriority, priority is not decreased if it's above FinalPriority.

# BEGIN LICENSE BLOCK # # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com> # Modified version of RT::Action::EscalatePriority # (c) Stanislav Sinyagin <ssinyagin@yahoo.com> # # (Except where explictly superceded by other copyright notices) # # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. # # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Unless otherwise specified, all modifications, corrections or # extensions to this work which alter its source code become the # property of Best Practical Solutions, LLC when submitted for # inclusion in the work. # # # END LICENSE BLOCK =head1 NAME RT::Action::EscalatePriorityLinear =head1 DESCRIPTION EscalatePriorityLinear is a ScripAction which is NOT intended to be called per transaction. It's intended to be called by an RT escalation daemon. (The daemon is called escalator). EsclatePriorityLinear uses the following formula to change a ticket's priority: <code><pre> Priority = FinalPriority * (Now-Starts) / (DueDate-Starts) </pre></code> Unless the duedate is past, in which case priority gets bumped straight to final priority. Unlike RT::Action::EscalatePriority, priority is not decreased if it's above FinalPriority. =cut package RT::Action::EscalatePriorityLinear; require RT::Action::Generic; use strict; use vars qw/@ISA/; @ISA=qw(RT::Action::Generic); #Do what we need to do and send it out. #What does this type of Action does sub Describe { my $self = shift; return (ref $self . " will move a ticket's priority toward its final priority linearly."); } sub Prepare { my $self = shift; <code><pre>if ($self-&gt;TicketObj-&gt;Priority() &gt;= $self-&gt;TicketObj-&gt;FinalPriority()) { # no update necessary. return 0; } my $due = $self-&gt;TicketObj-&gt;DueObj()-&gt;Unix(); # The ticket start is either "Starts" or "Created" my $starts = $self-&gt;TicketObj-&gt;StartsObj()-&gt;Unix(); if( $starts &lt; 1 ) { my $time = new RT::Date( $self-&gt;TicketObj-&gt;CurrentUser ); $time-&gt;Set( Format =&gt; 'sql', Value =&gt; $self-&gt;TicketObj-&gt;Created ); $starts = $time-&gt;Unix(); } # If we don't have a due date, increase the priority by one # until we hit the final priority if ($due &lt; 1 || $starts &lt; 1) { if ( $self-&gt;TicketObj-&gt;Priority &lt; $self-&gt;TicketObj-&gt;FinalPriority ){ $self-&gt;{'prio'} = ($self-&gt;TicketObj-&gt;Priority + 1); return 1; } else { return 0; } } # we've got a due date. now there are other things we should do else { my $now = time(); if( $due &gt; $now ) { $self-&gt;{'prio'} = int( $self-&gt;TicketObj-&gt;FinalPriority() * ($now - $starts) / ($due - $starts)); } else { $self-&gt;{'prio'} = $self-&gt;TicketObj-&gt;FinalPriority(); } } return 1; </pre></code> } sub Commit { my $self = shift; my ($val, $msg) = $self->TicketObj->SetPriority($self->{'prio'}); <code><pre>unless ($val) { $RT::Logger-&gt;debug($self . " $msg\n"); } </pre></code> } eval "require RT::Action::EscalatePriorityLinear_Vendor"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriorityLinear_Vendor.pm}); eval "require RT::Action::EscalatePriorityLinear_Local"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriorityLinear_Local.pm}); 1;


I did not want the escalation changing the "Last Updated By" field. I adjusted the sub Commit section (2nd Line) with the following:

sub Commit {

   my $self = shift;
   my ($val, $msg) = $self->TicketObj->__Set(Field => 'Priority', Value => $self->{'prio'}, RecordTransaction => 0);
unless ($val) {
     $RT::Logger-&gt;debug($self . " $msg\n");
}

}

I have found that this change does not affect the "Last Updated By" field assuming that it will NOT be changed to final priority. IF the change is going to cause it to jump directly to Final Priority (i.e. it is passed due date) then the "Last Updated By" changes to your cron user. -Kevin "gentgeen" Squire (RT 3.6.1 from Debian Repo)


use this:

sub Commit {

   my $self = shift;
   my ($val, $msg) = $self->TicketObj->_Set(Field => 'Priority', Value => $self->{'prio'}, LastUpdate => 0, TimeTaken => undef);
unless ($val) {
     $RT::Logger-&gt;debug($self . " $msg\n");
}

}

with follow patches and you have no last update:

--- /rt-3.8.0/lib/RT/Ticket_Overlay.pm 2008-07-11 17:16:09.000000000 +0200

+++ Ticket_Overlay.pm   2009-03-09 17:05:59.000000000 +0100
@@ -3191,6 +3191,7 @@
                  UpdateTicket      => 1,
                  CheckACL          => 1,
                  TransactionType   => 'Set',
+                 LastUpdate        => 1,
                  @_ );
  if ($args{'CheckACL'}) {

@@ -3214,8 +3215,9 @@

     if ( $args{'UpdateTicket'}  ) {
      #Set the new value

- ( $ret, $msg ) = $self->SUPER::_Set( Field => $args{'Field'},

-                                                Value => $args{'Value'} );
+        ( $ret, $msg ) = $self->SUPER::_Set( Field      => $args{'Field'},
+                                             Value      => $args{'Value'},
+                                             LastUpdate => $args{'LastUpdate'} );
      #If we can't actually set the field to the value, don't record
      # a transaction. instead, get out of here.

@@ -3225,11 +3227,12 @@

     if ( $args{'RecordTransaction'} == 1 ) {
      my ( $Trans, $Msg, $TransObj ) = $self-&gt;_NewTransaction(

- Type => $args{'TransactionType'},

-                                               Field     => $args{'Field'},
-                                               NewValue  => $args{'Value'},
-                                               OldValue  => $Old,
-                                               TimeTaken => $args{'TimeTaken'},
+                                               Type       => $args{'TransactionType'},
+                                               Field      => $args{'Field'},
+                                               NewValue   => $args{'Value'},
+                                               OldValue   => $Old,
+                                               TimeTaken  => $args{'TimeTaken'},
+                                               LastUpdate => $args{'LastUpdate'}
         );
         return ( $Trans, scalar $TransObj->BriefDescription );
     }

--- /rt-3.8.0/lib/RT/Record.pm 2008-07-07 22:21:51.000000000 +0200

+++ lib/RT/Action/Record.pm    2009-03-09 17:06:31.000000000 +0100
@@ -464,9 +464,10 @@
     my $self = shift;
  my %args = (

- Field => undef,

-        Value => undef,
-        IsSQL => undef,
+        Field      => undef,
+        Value      => undef,
+        IsSQL      => undef,
+        LastUpdate => 1,
         @_
     );

@@ -478,11 +479,16 @@

     }
  my $old_val = $self-&gt;__Value($args{'Field'});

- $self->_SetLastUpdated();

+
+    if ($args{'LastUpdate'} == 1) {
+      $self->_SetLastUpdated();
+    }
+
     my $ret = $self->SUPER::_Set(
-        Field => $args{'Field'},
-        Value => $args{'Value'},
-        IsSQL => $args{'IsSQL'}
+        Field      => $args{'Field'},
+        Value      => $args{'Value'},
+        IsSQL      => $args{'IsSQL'},
+        LastUpdate => $args{'LastUpdate'}
     );
         my ($status, $msg) =  $ret->as_array();

@@ -1398,6 +1404,7 @@

         MIMEObj   => undef,
         ActivateScrips => 1,
         CommitScrips => 1,
+        LastUpdate => 1,
         @_
     );

@@ -1438,7 +1445,9 @@

  $RT::Logger-&gt;warning($msg) unless $transaction;
  • $self->_SetLastUpdated;
  • if ($args{'LastUpdate'} == 1) {
  • $self->_SetLastUpdated();
  • } if ( defined $args{'TimeTaken'} and $self->can('_UpdateTimeTaken')) { $self->_UpdateTimeTaken( $args{'TimeTaken'} );