3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 # (Except where explictly superceded by other copyright notices)
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
26 RT::Action::EscalatePriority
30 EscalatePriority is a ScripAction which is NOT intended to be called
31 per transaction. It's intended to be called by an RT escalation tool.
32 One such tool is called rt-crontool and is located in $RTHOME/bin (see
33 C<rt-crontool -h> for more details)
35 EsclatePriority uses the following formula to change a ticket's priority:
37 Priority = Priority + (( FinalPriority - Priority ) / ( DueDate-Today))
39 Unless the duedate is past, in which case priority gets bumped straight
42 In this way, priority is either increased or decreased toward the final priority
43 as the ticket heads toward its due date.
49 package RT::Action::EscalatePriority;
50 require RT::Action::Generic;
54 @ISA=qw(RT::Action::Generic);
56 #Do what we need to do and send it out.
58 #What does this type of Action does
63 return (ref $self . " will move a ticket's priority toward its final priority.");
72 if ($self->TicketObj->Priority() == $self->TicketObj->FinalPriority()) {
73 # no update necessary.
77 #compute the number of days until the ticket is due
78 my $due = $self->TicketObj->DueObj();
81 # If we don't have a due date, adjust the priority by one
82 # until we hit the final priority
83 if ($due->Unix() < 1) {
84 if ( $self->TicketObj->Priority > $self->TicketObj->FinalPriority ){
85 $self->{'prio'} = ($self->TicketObj->Priority - 1);
88 elsif ( $self->TicketObj->Priority < $self->TicketObj->FinalPriority ){
89 $self->{'prio'} = ($self->TicketObj->Priority + 1);
92 # otherwise the priority is at the final priority. we don't need to
99 # we've got a due date. now there are other things we should do
101 my $diff_in_seconds = $due->Diff(time());
102 my $diff_in_days = int( $diff_in_seconds / 86400);
104 #if we haven't hit the due date yet
105 if ($diff_in_days > 0 ) {
107 # compute the difference between the current priority and the
111 $self->TicketObj->FinalPriority() - $self->TicketObj->Priority;
113 my $inc_priority_by = int( $prio_delta / $diff_in_days );
115 #set the ticket's priority to that amount
116 $self->{'prio'} = $self->TicketObj->Priority + $inc_priority_by;
119 #if $days is less than 1, set priority to final_priority
121 $self->{'prio'} = $self->TicketObj->FinalPriority();
131 my ($val, $msg) = $self->TicketObj->SetPriority($self->{'prio'});
134 $RT::Logger->debug($self . " $msg\n");
138 eval "require RT::Action::EscalatePriority_Vendor";
139 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriority_Vendor.pm});
140 eval "require RT::Action::EscalatePriority_Local";
141 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriority_Local.pm});