]> git.uio.no Git - usit-rt.git/blame - lib/RT/Action/EscalatePriority.pm
Upgrade to 4.2.2
[usit-rt.git] / lib / RT / Action / EscalatePriority.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
320f0092 5# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
13# This work is made available to you under the terms of Version 2 of
14# the GNU General Public License. A copy of that license should have
15# been provided with this software, but in any event can be snarfed
16# from www.gnu.org.
17#
18# This work is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301 or visit their web page on the internet at
27# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
32# (The following paragraph is not intended to limit the rights granted
33# to you to modify and distribute this software under the terms of
34# the GNU General Public License and is only of importance to you if
35# you choose to contribute your changes and enhancements to the
36# community by submitting them to Best Practical Solutions, LLC.)
37#
38# By intentionally submitting any modifications, corrections or
39# derivatives to this work, or any other work intended for use with
40# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41# you are the copyright holder for those contributions and you grant
42# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43# royalty-free, perpetual, license to use, copy, create derivative
44# works based on those contributions, and sublicense and distribute
45# those contributions and any derivatives thereof.
46#
47# END BPS TAGGED BLOCK }}}
48
49=head1 NAME
50
51 RT::Action::EscalatePriority
52
53=head1 DESCRIPTION
54
55EscalatePriority is a ScripAction which is NOT intended to be called
56per transaction. It's intended to be called by an RT escalation tool.
57One such tool is called rt-crontool and is located in $RTHOME/bin (see
58C<rt-crontool -h> for more details)
59
60EsclatePriority uses the following formula to change a ticket's priority:
61
62 Priority = Priority + (( FinalPriority - Priority ) / ( DueDate-Today))
63
64Unless the duedate is past, in which case priority gets bumped straight
65to final priority.
66
67In this way, priority is either increased or decreased toward the final priority
68as the ticket heads toward its due date.
69
70Alternately, if you don't set a due date, the Priority will be incremented by 1
71until it reaches the Final Priority. If a ticket without a due date has a Priority
72greater than Final Priority, it will be decremented by 1.
73
74=cut
75
76
77package RT::Action::EscalatePriority;
78use base 'RT::Action';
79
80use strict;
403d7b0b 81use warnings;
84fb5b46
MKG
82
83#Do what we need to do and send it out.
84
85#What does this type of Action does
86
87sub Describe {
88 my $self = shift;
89 return (ref $self . " will move a ticket's priority toward its final priority.");
90}
af59614d 91
84fb5b46
MKG
92
93sub Prepare {
94 my $self = shift;
af59614d 95
84fb5b46 96 if ($self->TicketObj->Priority() == $self->TicketObj->FinalPriority()) {
af59614d
MKG
97 # no update necessary.
98 return 0;
84fb5b46 99 }
af59614d 100
84fb5b46
MKG
101 #compute the number of days until the ticket is due
102 my $due = $self->TicketObj->DueObj();
af59614d 103
84fb5b46
MKG
104
105 # If we don't have a due date, adjust the priority by one
106 # until we hit the final priority
107 if ($due->Unix() < 1) {
af59614d
MKG
108 if ( $self->TicketObj->Priority > $self->TicketObj->FinalPriority ){
109 $self->{'prio'} = ($self->TicketObj->Priority - 1);
110 return 1;
111 }
112 elsif ( $self->TicketObj->Priority < $self->TicketObj->FinalPriority ){
113 $self->{'prio'} = ($self->TicketObj->Priority + 1);
114 return 1;
115 }
116 # otherwise the priority is at the final priority. we don't need to
117 # Continue
118 else {
119 return 0;
120 }
84fb5b46
MKG
121 }
122
123 # we've got a due date. now there are other things we should do
af59614d
MKG
124 else {
125 my $diff_in_seconds = $due->Diff(time());
126 my $diff_in_days = int( $diff_in_seconds / 86400);
127
128 #if we haven't hit the due date yet
129 if ($diff_in_days > 0 ) {
130
131 # compute the difference between the current priority and the
132 # final priority
133
134 my $prio_delta =
135 $self->TicketObj->FinalPriority() - $self->TicketObj->Priority;
136
137 my $inc_priority_by = int( $prio_delta / $diff_in_days );
138
139 #set the ticket's priority to that amount
140 $self->{'prio'} = $self->TicketObj->Priority + $inc_priority_by;
141
142 }
143 #if $days is less than 1, set priority to final_priority
144 else {
145 $self->{'prio'} = $self->TicketObj->FinalPriority();
146 }
84fb5b46
MKG
147
148 }
149 return 1;
150}
151
152sub Commit {
153 my $self = shift;
154 my ($val, $msg) = $self->TicketObj->SetPriority($self->{'prio'});
155
156 unless ($val) {
af59614d 157 $RT::Logger->debug($self . " $msg");
84fb5b46
MKG
158 }
159}
160
161RT::Base->_ImportOverlays();
162
1631;