diff options
Diffstat (limited to 'rt/lib/RT/Action')
| -rw-r--r-- | rt/lib/RT/Action/Accumulate.pm | 44 | ||||
| -rw-r--r-- | rt/lib/RT/Action/CreateTickets.pm | 19 | ||||
| -rw-r--r-- | rt/lib/RT/Action/EscalatePriority.pm | 7 | ||||
| -rwxr-xr-x | rt/lib/RT/Action/EscalateQueue.pm | 141 | ||||
| -rw-r--r-- | rt/lib/RT/Action/SetPriority_Local.pm | 47 |
5 files changed, 257 insertions, 1 deletions
diff --git a/rt/lib/RT/Action/Accumulate.pm b/rt/lib/RT/Action/Accumulate.pm new file mode 100644 index 000000000..c4ca667ea --- /dev/null +++ b/rt/lib/RT/Action/Accumulate.pm @@ -0,0 +1,44 @@ +package RT::Action::Accumulate; +use base 'RT::Action'; + +use strict; + +=head1 NAME + +RT::Action::Accumulate - Accumulate a running total in a ticket custom field. + +This action requires a transaction and ticket custom field with the same name. +When a transaction is submitted with a numeric value in that field, the field +value for the ticket will be incremented by that amount. Use this to create +custom fields that behave like the "TimeWorked" field. + +Best used with an "On Update" condition that triggers on any transaction. The +ticket custom field update itself does not a create a transaction. + +The argument to this action is the name of the custom field. They must have +the same name, and should be single-valued fields. + +=cut + +sub Prepare { + my $self = shift; + my $cfname = $self->Argument or return 0; + $self->{'inc_by'} = $self->TransactionObj->FirstCustomFieldValue($cfname); + return ( $self->{'inc_by'} =~ /^(\d+)$/ ); +} + +sub Commit { + my $self = shift; + my $cfname = $self->Argument; + my $newval = $self->{'inc_by'} + + ($self->TicketObj->FirstCustomFieldValue($cfname) || 0); + my ($val) = $self->TicketObj->AddCustomFieldValue( + Field => 'Support time', + Value => $newval, + RecordTransaction => 0, + ); + return $val; +} + +1; + diff --git a/rt/lib/RT/Action/CreateTickets.pm b/rt/lib/RT/Action/CreateTickets.pm index 7b8a13699..5a1693569 100644 --- a/rt/lib/RT/Action/CreateTickets.pm +++ b/rt/lib/RT/Action/CreateTickets.pm @@ -763,6 +763,7 @@ sub ParseLines { FinalPriority => $args{'finalpriority'} || 0, SquelchMailTo => $args{'squelchmailto'}, Type => $args{'type'}, + $self->Rules ); if ( $args{content} ) { @@ -1239,6 +1240,24 @@ sub PostProcess { } +sub Options { + my $self = shift; + my $queues = RT::Queues->new($self->CurrentUser); + $queues->UnLimit; + my @names; + while (my $queue = $queues->Next) { + push @names, $queue->Id, $queue->Name; + } + return ( + { + 'name' => 'Queue', + 'label' => 'In queue', + 'type' => 'select', + 'options' => \@names + } + ) +} + RT::Base->_ImportOverlays(); 1; diff --git a/rt/lib/RT/Action/EscalatePriority.pm b/rt/lib/RT/Action/EscalatePriority.pm index 5f8f879e2..e15e50c84 100644 --- a/rt/lib/RT/Action/EscalatePriority.pm +++ b/rt/lib/RT/Action/EscalatePriority.pm @@ -121,7 +121,12 @@ sub Prepare { # we've got a due date. now there are other things we should do else { - my $diff_in_seconds = $due->Diff(time()); + my $arg = $self->Argument || ''; + my $now = time(); + if ( $arg =~ /CurrentTime:\s*(\d+)/i ) { + $now = $1; + } + my $diff_in_seconds = $due->Diff($now); my $diff_in_days = int( $diff_in_seconds / 86400); #if we haven't hit the due date yet diff --git a/rt/lib/RT/Action/EscalateQueue.pm b/rt/lib/RT/Action/EscalateQueue.pm new file mode 100755 index 000000000..adafbdfb7 --- /dev/null +++ b/rt/lib/RT/Action/EscalateQueue.pm @@ -0,0 +1,141 @@ +=head1 NAME + +RT::Action::EscalateQueue - move a ticket to a different queue when it reaches its final priority + +=head1 DESCRIPTION + +EscalateQueue is a ScripAction that will move a ticket to a new +queue when its priority equals its final priority. It is designed +to be used with LinearEscalate or another action that increments +ticket priority on some schedule. Like those actions, it is intended +to be called from an escalation tool. + +=head1 CONFIGURATION + +FinalPriority is a ticket property, defaulting to the queue property. + +EscalateQueue is a queue custom field using RT::CustomFieldValues::Queue +as its data source (that is, it refers to another queue). Tickets at +FinalPriority will be moved to that queue. + +From a shell you can use the following command: + + 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@freeside.bizE<gt> + +Based on in part LinearEscalate by Kevin Riggle E<lt>kevinr@bestpractical.comE<gt> +and Ruslan Zakirov E<lt>ruz@bestpractical.comE<gt> . + +=cut diff --git a/rt/lib/RT/Action/SetPriority_Local.pm b/rt/lib/RT/Action/SetPriority_Local.pm new file mode 100644 index 000000000..efaadc961 --- /dev/null +++ b/rt/lib/RT/Action/SetPriority_Local.pm @@ -0,0 +1,47 @@ +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; |
