No subject
Wed Aug 4 16:14:33 PDT 2010
rt-crontool --search RT::Search::FromSQL --search-arg \
"(Status='new' OR Status='open' OR Status = 'stalled')" \
--action RT::Action::EscalateQueue
No action argument is needed. Each ticket will be escalated based on the
EscalateQueue property of its current queue.
=cut
package RT::Action::EscalateQueue;
use strict;
use warnings;
use base qw(RT::Action);
our $VERSION = '0.01';
#What does this type of Action does
sub Describe {
my $self = shift;
my $class = ref($self) || $self;
return "$class will move a ticket to its escalation queue when it reaches its final priority."
}
#This Prepare only returns 1 if the ticket will be escalated.
sub Prepare {
my $self = shift;
my $ticket = $self->TicketObj;
my $queue = $ticket->QueueObj;
my $new_queue = $queue->FirstCustomFieldValue('EscalateQueue');
my $ticketid = 'Ticket #'.$ticket->Id; #for debug messages
if ( $ticket->InitialPriority == $ticket->FinalPriority ) {
$RT::Logger->debug("$ticketid has no priority range. Not escalating.");
return 0;
}
if ( $ticket->Priority == $ticket->FinalPriority ) {
if (!$new_queue) {
$RT::Logger->debug("$ticketid has no escalation queue. Not escalating.");
return 0;
}
if ($new_queue eq $queue->Name) {
$RT::Logger->debug("$ticketid would be escalated to its current queue.");
return 0;
}
$self->{'new_queue'} = $new_queue;
return 1;
}
return 0;
}
# whereas Commit returns 1 if it succeeds at whatever it's doing
sub Commit {
my $self = shift;
return 1 if !exists($self->{'new_queue'});
my $ticket = $self->TicketObj;
my $ticketid = 'Ticket #'.$ticket->Id;
my $new_queue = RT::Queue->new($ticket->CurrentUser);
$new_queue->Load($self->{'new_queue'});
if ( ! $new_queue ) {
$RT::Logger->debug("Escalation queue ".$self->{'new_queue'}." not found.");
return 0;
}
$RT::Logger->debug("Escalating $ticket from ".$ticket->QueueObj->Name .
' to '. $new_queue->Name . ', FinalPriority '.$new_queue->FinalPriority);
my ( $val, $msg ) = $ticket->SetQueue($self->{'new_queue'});
if (! $val) {
$RT::Logger->error( "Couldn't set queue: $msg" );
return (0, $msg);
}
# Set properties of the ticket according to its new queue, so that
# escalation Does What You Expect. Don't record transactions for this;
# the queue change should be enough.
( $val, $msg ) = $ticket->_Set(
Field => 'FinalPriority',
Value => $new_queue->FinalPriority,
RecordTransaction => 0,
);
if (! $val) {
$RT::Logger->error( "Couldn't set new final priority: $msg" );
return (0, $msg);
}
my $Due = new RT::Date( $ticket->CurrentUser );
if ( my $due_in = $new_queue->DefaultDueIn ) {
$Due->SetToNow;
$Due->AddDays( $due_in );
}
( $val, $msg ) = $ticket->_Set(
Field => 'Due',
Value => $Due->ISO,
RecordTransaction => 0,
);
if (! $val) {
$RT::Logger->error( "Couldn't set new due date: $msg" );
return (0, $msg);
}
return 1;
}
1;
=head1 AUTHOR
Mark Wells E<lt>mark at freeside.bizE<gt>
Based on in part LinearEscalate by Kevin Riggle E<lt>kevinr at bestpractical.comE<gt>
and Ruslan Zakirov E<lt>ruz at bestpractical.comE<gt> .
=cut
--- NEW FILE: SetPriority_Local.pm ---
package RT::Action::SetPriority;
use strict;
no warnings 'redefine';
# Extension to allow relative priority changes:
# if Argument is "R" followed by a value, it's
# relative to current priority.
sub Commit {
my $self = shift;
my ($rel, $val);
my $arg = $self->Argument;
if ( $arg ) {
($rel, $val) = ( $arg =~ /^(r?)(-?\d+)$/i );
if (!length($val)) {
warn "Bad argument to SetPriority: '$arg'\n";
return 0;
}
}
else {
my %Rules = $self->Rules;
$rel = length($Rules{'inc'}) ? 1 : 0;
$val = $Rules{'inc'} || $Rules{'set'};
if ($val !~ /^[+-]?\d+$/) {
warn "Bad argument to SetPriority: '$val'\n";
return 0;
}
}
$val += $self->TicketObj->Priority if $rel;
$self->TicketObj->SetPriority($val);
}
sub Options {
(
{
'name' => 'set',
'label' => 'Set to value',
'type' => 'text',
},
{
'name' => 'inc',
'label' => 'Increment by',
'type' => 'text',
},
)
}
1;
More information about the freeside-commits
mailing list