I have created a different ticketgenerator, to make the ticketnumbers take the form of $Year-$Count.
For example, this creates a ticket like 2016-0030, and it works fine.
However, when a customer replies to an existing ticket a new ticket is generated, while it should append that e-mail to the original ticket.
This is my TicketGenerator.pm
Code: Select all
package Kernel::System::Ticket::Number::TicketGenerator;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Time',
);
sub TicketCreateNumber {
my ( $Self, $JumpCounter ) = @_;
if ( !$JumpCounter ) {
$JumpCounter = 0;
}
# get needed objects
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
my $TimeObject = $Kernel::OM->Get('Kernel::System::Time');
# get needed config options
my $CounterLog = $ConfigObject->Get('Ticket::CounterLog');
my $SystemID = $ConfigObject->Get('SystemID');
# get current time
my ( $Sec, $Min, $Hour, $Day, $Month, $Year ) = $TimeObject->SystemTime2Date(
SystemTime => $TimeObject->SystemTime(),
);
# read count
my $Count = 0;
my $LastModify = '';
if ( -f $CounterLog ) {
my $ContentSCALARRef = $MainObject->FileRead(
Location => $CounterLog,
);
if ( $ContentSCALARRef && ${$ContentSCALARRef} ) {
($Count) = split( /;/, ${$ContentSCALARRef} );
# just debug
if ( $Self->{Debug} > 0 ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message => "Read counter from $CounterLog: $Count",
);
}
}
}
# check if we need to reset the counter, happens yearly
if ( !$LastModify || $LastModify ne "$Year" ) {
$Count = 0;
}
# count auto increment ($Count++)
$Count++;
$Count = $Count + $JumpCounter;
# write new count
my $Write = $MainObject->FileWrite(
Location => $CounterLog,
Content => \$Count,
);
if ($Write) {
if ( $Self->{Debug} > 0 ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message => "Write counter: $Count",
);
}
}
my $MinSize = $ConfigObject->Get('Ticket::NumberGenerator::MinCounterSize')
|| 4;
$Count = sprintf "%.*u", $MinSize, $Count;
# create new ticket number
my $Tn = $Year . "-" . $Count;
# Check ticket number. If exists generate new one!
if ( $Self->TicketCheckNumber( Tn => $Tn ) ) {
$Self->{LoopProtectionCounter}++;
if ( $Self->{LoopProtectionCounter} >= 16000 ) {
# loop protection
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "CounterLoopProtection is now $Self->{LoopProtectionCounter}!"
. " Stopped TicketCreateNumber()!",
);
return;
}
# create new ticket number again
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'notice',
Message => "Tn ($Tn) exists! Creating a new one.",
);
$Tn = $Self->TicketCreateNumber( $Self->{LoopProtectionCounter} );
}
return $Tn;
}
sub GetTNByString {
my ( $Self, $String ) = @_;
if ( !$String ) {
return;
}
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# get needed config options
my $CheckSystemID = $ConfigObject->Get('Ticket::NumberGenerator::CheckSystemID');
my $SystemID = '';
if ($CheckSystemID) {
$SystemID = $ConfigObject->Get('SystemID');
}
my $TicketHook = $ConfigObject->Get('Ticket::Hook');
my $TicketHookDivider = $ConfigObject->Get('Ticket::HookDivider');
# check current setting
if ( $String =~ /\Q$TicketHook$TicketHookDivider\E(\d{1,4}-\d{1,40})/i ) {
return $1;
}
# check default setting
if ( $String =~ /\Q$TicketHook\E:\s{0,2}($SystemID\d{1,4}-\d{1,40})/i ) {
return $1;
}
return;
}
1;
I have been using the on-line regular expression 'calculators', but I can not get the subject to match without using a global modifier. However, it is easy to send an e-mail with something that matches the used regex.
I have replied to an e-mail sent by the otrs system, which has a ticketnumber in the subject. I've sent e-mails with these subjects:
Re: [Ticket#2016-0005]
[Ticket#2016-0005]
Ticket#2016-0005
2016-0005
[2016-0005]
Re: [2016-0005]
Neither works, so this would make me think something is amiss in the settings.
Ticket -> Core::PostMaster
PostMaster::PostFilterModule###000-FollowUpArticleTypeCheck
PostMaster::CheckFollowUpModule###0100-Subject
PostMaster::CheckFollowUpModule###0200-References
are all enabled, and not modified from the default
Ticket -> Core::Ticket
Ticket::NumberGenerator::CheckSystemID -> No
E-mail is sent and fetched with IMAPS and SMTPS.
I hope somebody can point me in the right direction, cause I'm out of options to check.
I also don't know how to get this stuff logged, the debug log only dumps all parameter settings, and I'm not aware of any logfile where I can see what it's doing and if something matches at all.