ForkIntoNewTicket
HomePage > Contributions > ForkIntoNewTicket
ForkIntoNewTicket
Summary
I use this scrip associated with a condition scrip that only catch correspondence/comment to a closed ticket. This scrip create a new ticket based on the correspondence/comment (subject,to,from,data).
It also copy attachments, and add links beetween the two tickets.
The scrip action
In order to install it in RT I advise you to create a $RT/local/lib/RT/Action directory and put the scrip ih this directory.
$cat $RT/local/lib/RT/Action/ForkIntoNewTicket.pm
package RT::Action::ForkIntoNewTicket;
use strict;
use base qw(RT::Action::Generic);
#What does this type of Action doeszxczxc
# {{{ sub Describe
sub Describe {
my $self = shift;
return (ref $self . " Fork into a new ticket, the last correspondence / comment.");
}
# }}}
# {{{ sub Prepare
sub Prepare {
# nothing to prepare
return 1;
}
# }}}
sub Commit {
my $self = shift;
my $ticket = $self->TicketObj;
my $transaction = $self->TransactionObj;
## retrieve original message
my $MIMEObj = MIME::Entity->build(To => $transaction->Attachments->First->GetHeader('To'),
From => $transaction->Attachments->First->GetHeader('From'),
Subject => $transaction->Subject,
Date => $transaction->Attachments->First->GetHeader('Date'),
Encoding => '-SUGGEST',
Data => 'Réponse reçue concernant le ticket résolu #'.$ticket->Id.":\n\n".$transaction->Content
);
RT::I18N::SetMIMEEntityToUTF8($MIMEObj);
## don't forget the attachments
my $transaction_content_obj = $transaction->ContentObj;
my $attachments = $transaction->Attachments;
while (my $attachment = $attachments->Next) {
# don't attach blank file
next unless ($attachment->ContentLength || $attachment->Filename);
# don't attach the message itself...
next if (
$transaction_content_obj
&& $transaction_content_obj->Id == $attachment->Id
&& $transaction_content_obj->ContentType =~ qr{text/plain}i
);
$MIMEObj->attach(
Type => $attachment->ContentType,
Charset => $attachment->OriginalEncoding,
Data => $attachment->OriginalContent,
Filename => Encode::decode_utf8($attachment->Filename),
Encoding => '-SUGGEST'
);
}
# new ticket (cross link is automatic)
my $child_ticket = RT::Ticket->new($RT::SystemUser);
my $user = RT::User->new($RT::SystemUser);
$user->Load($transaction->Creator);
my $mail = $user->EmailAddress;
my ($child_id, $child_TransObj, $errorMsg) =
$child_ticket->Create(
Queue => $ticket->Queue,
Subject => '--> ticket #'.$ticket->Id.':'.$ticket->Subject,
RefersTo => $ticket->Id,
MIMEObj => $MIMEObj,
Requestor => $mail
);
## add a comment to the resolved ticket to inform that we have open a new ticket
$ticket->Comment(
Content => 'Suite à la correspondance précédente, un nouveau ticket a été ouvert : ticket #'.$child_ticket->Id);
unless ($child_id) {
$RT::Logger->debug(">>Error : ". $errorMsg);
return undef
}
}
eval "require RT::Action::ForkIntoNewTicket_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/ForkIntoNewTicket_Vendor.pm});
eval "require RT::Action::ForkIntoNewTicket_Local";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/ForkIntoNewTicket_Local.pm});
1;
installation
Once we have created the scrip action we can inform RT of it. Execute the following script exactly one times. It will not make any output and can be removed afterwards.
$cat createForkIntoNewTicket.pl
#!/home/rt/perl/bin/perl
use strict;
use Unicode::String qw(utf8 latin1);
# Replace this with your RT_LIB_PATH
use lib "/home/rt/rt/lib";
# Replace this with your RT_ETC_PATH
use lib "/home/rt/rt/etc";
use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );
use RT::ScripAction;
##########################################################################
### RT CLI initialization
CleanEnv();
RT::LoadConfig();
RT::Init();
##Drop setgid permissions
RT::DropSetGIDPermissions();
##Get the current user all loaded
our $CurrentUser = GetCurrentUser();
unless( $CurrentUser->Id )
{
print "No RT user found. Please consult your RT administrator.\n";
exit 1;
}
my $sa = new RT::ScripAction($CurrentUser);
$sa->Create(
Name => "Fork la réponse dans un nouveau ticket",
Description => "Fork la réponse dans un nouveau ticket",
ExecModule => 'ForkIntoNewTicket'
);
This script have to be run to use new action in web interface.
$ perl createNotResolvedCondition.pl
NOTE:
In RT3.2 there is no sub named DropSetGIDPermissions() in lib/RT.pm, so I commented that line and it works.
problems
If you meet problem it may be necessary to copy some files into local directory :
$cp $RT/lib/RT/base.pm $RT/local/lib/RT $cp $RT/lib/RT/Action/Generic.pm $RT/local/lib/RT/Action
conclusion
I use it with the scrip condition ReplyToResolved with global scrip On Reply Open disabled
--