https://rt-wiki.bestpractical.com/index.php?title=UpdatePriority&feed=atom&action=historyUpdatePriority - Revision history2024-03-28T18:45:55ZRevision history for this page on the wikiMediaWiki 1.37.2https://rt-wiki.bestpractical.com/index.php?title=UpdatePriority&diff=4050&oldid=prevAdmin: 2 revisions imported2016-04-06T20:39:37Z<p>2 revisions imported</p>
<p><b>New page</b></p><div> <nowiki>=head1 NAME<br />
<br />
RT::Action::UpdatePriority<br />
<br />
=head1 DESCRIPTION<br />
<br />
UpdatePriority is a ScriptAction that updates the priority of a ticket<br />
to match that of the queue it is in. UpdatePriority is supposed to be<br />
called by an RT escalation tool, such as rt-crontool. It makes it<br />
possible to move a ticket from one queue to another, and have the<br />
ticket's priority updated.<br />
<br />
Here's an example: Suppose you have tree queues. One where the tickets<br />
are due in 7 days, one where they are due in 14 days and one where<br />
they are due in 30 days. If you now wanted to move tickets from one<br />
queue to another, the due date for the tickets would be wrong. You<br />
would then run this ScriptAction to update the priority in the moved<br />
tickets.<br />
<br />
UpdatePriority will change the ticket's priority to satisfy this<br />
equation:<br />
<br />
priority =<br />
(FinalPriority / DefaultDueIn) * (today - Created) + InitialPriority<br />
<br />
=cut<br />
<br />
package RT::Action::UpdatePriority;<br />
require RT::Action::Generic;<br />
<br />
use strict;<br />
<br />
use vars qw(@ISA);<br />
@ISA = qw(RT::Action::Generic);<br />
<br />
# What does this Action do?<br />
sub Describe {<br />
my $self = shift;<br />
return ref $self .<br />
" updates a ticket's priority to match that of the queue it is in";<br />
}<br />
<br />
use constant SECONDS_PER_DAY =&gt; 60 * 60 * 24;<br />
<br />
sub Prepare {<br />
my $self = shift;<br />
my $final_priority = $self-&gt;TicketObj-&gt;QueueObj-&gt;FinalPriority();<br />
my $initial_priority = $self-&gt;TicketObj-&gt;QueueObj-&gt;InitialPriority();<br />
my $created = RT::Date-&gt;new($self-&gt;TicketObj-&gt;CurrentUser());<br />
$created-&gt;Set(Format =&gt; 'sql',<br />
Value =&gt; $self-&gt;TicketObj-&gt;Created());<br />
my $priority = $self-&gt;TicketObj-&gt;Priority();<br />
my $default_due_in = $self-&gt;TicketObj-&gt;QueueObj-&gt;DefaultDueIn();<br />
my $due = $self-&gt;TicketObj-&gt;DueObj();<br />
my $today = RT::Date-&gt;new($self-&gt;TicketObj-&gt;CurrentUser());<br />
$today-&gt;SetToNow();<br />
<br />
return 0 if ($priority &gt; $final_priority);<br />
<br />
# -1 means that the ticket has no due date at all. We leave such<br />
# tickets alone.<br />
return 0 if ($due-&gt;Unix == -1);<br />
<br />
my $diff_in_days = int($today-&gt;Diff($created) / SECONDS_PER_DAY);<br />
<br />
my $new_priority =<br />
int(($final_priority / $default_due_in) * $diff_in_days) +<br />
$initial_priority;<br />
<br />
$new_priority = $final_priority if ($new_priority &gt; $final_priority);<br />
<br />
if ($new_priority != $priority) {<br />
$self-&gt;{prio} = $new_priority;<br />
return 1;<br />
}<br />
return 0;<br />
}<br />
<br />
sub Commit {<br />
my $self = shift;<br />
<br />
my ($val, $msg) = $self-&gt;TicketObj-&gt;SetPriority($self-&gt;{prio});<br />
<br />
unless ($val) {<br />
$RT::Logger-&gt;debug($self . " $msg\n");<br />
}<br />
}<br />
<br />
1;<br />
<br />
</nowiki><br />
<br />
----<br />
<br />
=== updated ===<br />
<br />
Pulled into VIM so I could strip out the tabs and wikify the whole thing. -- [[AndyHarrison]]</div>Admin