1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 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::LinearEscalate - will move a ticket's priority toward its final priority.
53 =head1 This vs. RT::Action::EscalatePriority
55 This action doesn't change priority if due date is not set.
57 This action honor the Starts date.
59 This action can apply changes silently.
61 This action can replace EscalatePriority completly. If you want to tickets
62 that have been created without Due date then you can add scrip that sets
63 default due date. For example a week then priorities of your tickets will
64 escalate linearly during the week from intial value towards final.
66 =head1 This vs. LinearEscalate from the CPAN
68 This action is an integration of the module from the CPAN into RT's core
69 that's happened in RT 3.8. If you're upgrading from 3.6 and have been using
70 module from the CPAN with old version of RT then you should uninstall it
73 However, this action doesn't support control over config. Read </CONFIGURATION>
74 to find out ways to deal with it.
78 LinearEscalate is a ScripAction that will move a ticket's priority
79 from its initial priority to its final priority linearly as
80 the ticket approaches its due date.
82 It's intended to be called by an RT escalation tool. One such tool is called
83 rt-crontool and is located in $RTHOME/bin (see C<rt-crontool -h> for more details).
87 Once the ScripAction is installed, the following script in "cron"
88 will get tickets to where they need to be:
90 rt-crontool --search RT::Search::FromSQL --search-arg \
91 "(Status='new' OR Status='open' OR Status = 'stalled')" \
92 --action RT::Action::LinearEscalate
94 The Starts date is associated with intial ticket's priority or
95 the Created field if the former is not set. End of interval is
96 the Due date. Tickets without due date B<are not updated>.
100 Initial and Final priorities are controlled by queue's options
101 and can be defined using the web UI via Admin tab. This
102 action should handle correctly situations when initial priority
103 is greater than final.
105 LinearEscalate's behavior can be controlled by two options:
109 =item RecordTransaction - defaults to false and if option is true then
110 causes the tool to create a transaction on the ticket when it is escalated.
112 =item UpdateLastUpdated - which defaults to true and updates the LastUpdated
113 field when the ticket is escalated, otherwise don't touch anything.
117 You cannot set "UpdateLastUpdated" to false unless "RecordTransaction"
118 is also false. Well, you can, but we'll just ignore you.
120 You can set this options using either in F<RT_SiteConfig.pm>, as action
121 argument in call to the rt-crontool or in DB if you want to use the action
124 From a shell you can use the following command:
126 rt-crontool --search RT::Search::FromSQL --search-arg \
127 "(Status='new' OR Status='open' OR Status = 'stalled')" \
128 --action RT::Action::LinearEscalate \
129 --action-arg "RecordTransaction: 1"
131 This ScripAction uses RT's internal _Set or __Set calls to set ticket
132 priority without running scrips or recording a transaction on each
133 update, if it's been said to.
137 package RT::Action::LinearEscalate;
141 use base qw(RT::Action);
143 #Do what we need to do and send it out.
145 #What does this type of Action does
149 my $class = ref($self) || $self;
150 return "$class will move a ticket's priority toward its final priority.";
156 my $ticket = $self->TicketObj;
158 unless ( $ticket->DueObj->IsSet ) {
159 $RT::Logger->debug('Due is not set. Not escalating.');
163 my $priority_range = ($ticket->FinalPriority ||0) - ($ticket->InitialPriority ||0);
164 unless ( $priority_range ) {
165 $RT::Logger->debug('Final and Initial priorities are equal. Not escalating.');
169 if ( $ticket->Priority >= $ticket->FinalPriority && $priority_range > 0 ) {
170 $RT::Logger->debug('Current priority is greater than final. Not escalating.');
173 elsif ( $ticket->Priority <= $ticket->FinalPriority && $priority_range < 0 ) {
174 $RT::Logger->debug('Current priority is lower than final. Not escalating.');
178 # TODO: compute the number of business days until the ticket is due
180 # now we know we have a due date. for every day that passes,
181 # increment priority according to the formula
183 my $starts = $ticket->StartsObj->IsSet ? $ticket->StartsObj->Unix : $ticket->CreatedObj->Unix;
186 # do nothing if we didn't reach starts or created date
187 if ( $starts > $now ) {
188 $RT::Logger->debug('Starts(Created) is in future. Not escalating.');
192 my $due = $ticket->DueObj->Unix;
193 $due = $starts + 1 if $due <= $starts; # +1 to avoid div by zero
195 my $percent_complete = ($now-$starts)/($due - $starts);
197 my $new_priority = int($percent_complete * $priority_range) + ($ticket->InitialPriority || 0);
198 $new_priority = $ticket->FinalPriority if $new_priority > $ticket->FinalPriority;
199 $self->{'new_priority'} = $new_priority;
207 my $new_value = $self->{'new_priority'};
208 return 1 unless defined $new_value;
210 my $ticket = $self->TicketObj;
211 # if the priority hasn't changed do nothing
212 return 1 if $ticket->Priority == $new_value;
214 # override defaults from argument
215 my ($record, $update) = (0, 1);
217 my $arg = $self->Argument || '';
218 if ( $arg =~ /RecordTransaction:\s*(\d+)/i ) {
220 $RT::Logger->debug("Overrode RecordTransaction: $record");
222 if ( $arg =~ /UpdateLastUpdated:\s*(\d+)/i ) {
224 $RT::Logger->debug("Overrode UpdateLastUpdated: $update");
226 $update = 1 if $record;
230 'Linearly escalating priority of ticket #'. $ticket->Id
231 .' from '. $ticket->Priority .' to '. $new_value
232 .' and'. ($record? '': ' do not') .' record a transaction'
233 .' and'. ($update? '': ' do not') .' touch last updated field'
239 ( $val, $msg ) = $ticket->__Set(
245 ( $val, $msg ) = $ticket->_Set(
248 RecordTransaction => 0,
253 ( $val, $msg ) = $ticket->SetPriority( $new_value );
257 $RT::Logger->error( "Couldn't set new priority value: $msg" );
263 RT::Base->_ImportOverlays();
269 Kevin Riggle E<lt>kevinr@bestpractical.comE<gt>
271 Ruslan Zakirov E<lt>ruz@bestpractical.comE<gt>