1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 # CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 # END BPS TAGGED BLOCK }}}
51 RT::Action::EscalatePriority
55 EscalatePriority is a ScripAction which is NOT intended to be called
56 per transaction. It's intended to be called by an RT escalation tool.
57 One such tool is called rt-crontool and is located in $RTHOME/bin (see
58 C<rt-crontool -h> for more details)
60 EsclatePriority uses the following formula to change a ticket's priority:
62 Priority = Priority + (( FinalPriority - Priority ) / ( DueDate-Today))
64 Unless the duedate is past, in which case priority gets bumped straight
67 In this way, priority is either increased or decreased toward the final priority
68 as the ticket heads toward its due date.
70 Alternately, if you don't set a due date, the Priority will be incremented by 1
71 until it reaches the Final Priority. If a ticket without a due date has a Priority
72 greater than Final Priority, it will be decremented by 1.
76 EsclatePriority's behavior can be controlled by two options:
80 =item RecordTransaction
82 If true (the default), the action casuses a transaction on the ticket
83 when it is escalated. If false, the action updates the priority without
84 running scrips or recording a transaction.
86 =item UpdateLastUpdated
88 If true (the default), the action updates the LastUpdated field when the
89 ticket is escalated. You cannot set C<UpdateLastUpdated> to false unless
90 C<RecordTransaction> is also false.
94 To use these with C<rt-crontool>, specify them with C<--action-arg>:
96 --action-arg "RecordTransaction: 0, UpdateLastUpdated: 0"
101 package RT::Action::EscalatePriority;
102 use base 'RT::Action';
107 #Do what we need to do and send it out.
109 #What does this type of Action does
113 return (ref $self . " will move a ticket's priority toward its final priority.");
120 if ($self->TicketObj->Priority() == $self->TicketObj->FinalPriority()) {
121 # no update necessary.
125 #compute the number of days until the ticket is due
126 my $due = $self->TicketObj->DueObj();
129 # If we don't have a due date, adjust the priority by one
130 # until we hit the final priority
131 if (not $due->IsSet) {
132 if ( $self->TicketObj->Priority > $self->TicketObj->FinalPriority ){
133 $self->{'prio'} = ($self->TicketObj->Priority - 1);
136 elsif ( $self->TicketObj->Priority < $self->TicketObj->FinalPriority ){
137 $self->{'prio'} = ($self->TicketObj->Priority + 1);
140 # otherwise the priority is at the final priority. we don't need to
147 # we've got a due date. now there are other things we should do
149 my $arg = $self->Argument || '';
151 if ( $arg =~ /CurrentTime:\s*(\d+)/i ) {
154 my $diff_in_seconds = $due->Diff($now);
155 my $diff_in_days = int( $diff_in_seconds / 86400);
157 #if we haven't hit the due date yet
158 if ($diff_in_days > 0 ) {
160 # compute the difference between the current priority and the
164 $self->TicketObj->FinalPriority() - $self->TicketObj->Priority;
166 my $inc_priority_by = int( $prio_delta / $diff_in_days );
168 #set the ticket's priority to that amount
169 $self->{'prio'} = $self->TicketObj->Priority + $inc_priority_by;
172 #if $days is less than 1, set priority to final_priority
174 $self->{'prio'} = $self->TicketObj->FinalPriority();
183 my $new_value = $self->{'prio'};
184 return 1 unless defined $new_value;
186 my $ticket = $self->TicketObj;
187 return 1 if $ticket->Priority == $new_value;
189 # Overide defaults from argument
190 my($record, $update) = (1, 1);
192 my $arg = $self->Argument || '';
193 if ( $arg =~ /RecordTransaction:\s*(\d+)/i ) {
195 $RT::Logger->debug("Overrode RecordTransaction: $record");
197 if ( $arg =~ /UpdateLastUpdated:\s*(\d+)/i ) {
199 $RT::Logger->debug("Overrode UpdateLastUpdated: $update");
201 # If creating a transaction, we have to update lastupdated
202 $update = 1 if $record;
206 'Escalating priority of ticket #'. $ticket->Id
207 .' from '. $ticket->Priority .' to '. $new_value
208 .' and'. ($record? '': ' do not') .' record a transaction'
209 .' and'. ($update? '': ' do not') .' touch last updated field'
215 ( $val, $msg ) = $ticket->__Set(
220 ( $val, $msg ) = $ticket->_Set(
223 RecordTransaction => 0,
227 ($val, $msg) = $ticket->SetPriority($new_value);
231 $RT::Logger->error( "Couldn't set new priority value: $msg");
237 RT::Base->_ImportOverlays();