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 per
31 transaction. It's intended to be called by an RT escalation daemon.
32 (The daemon is called escalator).
34 EsclatePriority uses the following formula to change a ticket's priority:
36 Priority = Priority + (( FinalPriority - Priority ) / ( DueDate-Today))
38 Unless the duedate is past, in which case priority gets bumped straight
41 In this way, priority is either increased or decreased toward the final priority
42 as the ticket heads toward its due date.
48 package RT::Action::EscalatePriority;
49 require RT::Action::Generic;
53 @ISA=qw(RT::Action::Generic);
55 #Do what we need to do and send it out.
57 #What does this type of Action does
62 return (ref $self . " will move a ticket's priority toward its final priority.");
71 if ($self->TicketObj->Priority() == $self->TicketObj->FinalPriority()) {
72 # no update necessary.
76 #compute the number of days until the ticket is due
77 my $due = $self->TicketObj->DueObj();
80 # If we don't have a due date, adjust the priority by one
81 # until we hit the final priority
82 if ($due->Unix() < 1) {
83 if ( $self->TicketObj->Priority > $self->TicketObj->FinalPriority ){
84 $self->{'prio'} = ($self->TicketObj->Priority - 1);
87 elsif ( $self->TicketObj->Priority < $self->TicketObj->FinalPriority ){
88 $self->{'prio'} = ($self->TicketObj->Priority + 1);
91 # otherwise the priority is at the final priority. we don't need to
98 # we've got a due date. now there are other things we should do
100 my $diff_in_seconds = $due->Diff(time());
101 my $diff_in_days = int( $diff_in_seconds / 86400);
103 #if we haven't hit the due date yet
104 if ($diff_in_days > 0 ) {
106 # compute the difference between the current priority and the
110 $self->TicketObj->FinalPriority() - $self->TicketObj->Priority;
112 my $inc_priority_by = int( $prio_delta / $diff_in_days );
114 #set the ticket's priority to that amount
115 $self->{'prio'} = $self->TicketObj->Priority + $inc_priority_by;
118 #if $days is less than 1, set priority to final_priority
120 $self->{'prio'} = $self->TicketObj->FinalPriority();
130 my ($val, $msg) = $self->TicketObj->SetPriority($self->{'prio'});
133 $RT::Logger->debug($self . " $msg\n");
137 eval "require RT::Action::EscalatePriority_Vendor";
138 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriority_Vendor.pm});
139 eval "require RT::Action::EscalatePriority_Local";
140 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriority_Local.pm});