Merge Ticket as a note

Moderator: crythias

Locked
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Merge Ticket as a note

Post by ovron »

Hello

Now we have a filter that merge identical tickets.

Code: Select all

# --
# Kernel/System/PostMaster/Filter/MergeIdenticalTickets.pm - sub part of PostMaster.pm
# Copyright (C) 2014 Perl-Services.de, http://perl-services.de
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
	package Kernel::System::PostMaster::Filter::MergeIdenticalTickets;
	
 use strict;
 use warnings;
	
 use List::Util qw(first);
	
 our @ObjectDependencies = qw(
	Kernel::System::Ticket
	Kernel::System::Log
 );
 sub new {
	 my ( $Type, %Param ) = @_;
	 # allocate new hash for object
	 my $Self = {};
	 bless( $Self, $Type );
	 
	 $Self->{Debug} = $Param{Debug} || 0;

	 return $Self;
 }

 
 sub Run {
	 my ( $Self, %Param ) = @_;
	 
	 my $LogObject = $Kernel::OM->Get('Kernel::System::Log');
	
	 # check needed stuff
	 for my $Needed (qw(JobConfig GetParam)) {
		 if ( !$Param{$Needed} ) {
			 $LogObject->Log(
				 Priority => 'error',
				 Message => "Need $Needed!",
			 );
			 return;
		}
	}
	
	 # get config options
	 my %Config;
	 my %Metrics;

	 if ( $Param{JobConfig} && ref $Param{JobConfig} eq 'HASH' ) {
		 %Config = %{ $Param{JobConfig} };
		 %Metrics = %{ $Param{JobConfig}->{Metric} || {} };
 }

	return 1 if !%Config;
	return 1 if !%Metrics;

	my %Mail = %{ $Param{GetParam} };

	
	my %SearchCriteria = ( StateType => 'Open' );
	if ( $Metrics{From} ) {
		$SearchCriteria{From} = $Mail{From}
 }

	if ( $Metrics{Subject} ) {
		$SearchCriteria{Subject} = $Mail{Subject}
 }

	my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
	my @TicketIDs = $TicketObject->TicketSearch(
		%SearchCriteria,
		Result => 'ARRAY',
		UserID => 1,
	);

	return 1 if !@TicketIDs;

	my ($TicketID) = first { $_ ne $Param{TicketID} } reverse @TicketIDs;
	my ($HTMLFile) = first{ $_->{Filename} eq 'file-2' }@{ $Mail{Attachment} || [] };

	if ( $Metrics{HTMLBody} && $HTMLFile ) {
		my $Found = 0;

		POSSIBLETICKET:
		for my $PossibleTicket ( reverse @TicketIDs ) {
			next POSSIBLETICKET if $PossibleTicket eq $Param{TicketID};

			my %Article = $TicketObject->ArticleFirstArticle(
				TicketID => $PossibleTicket,
				UserID => 1,
			);

			my %AttachmentIndex = $TicketObject->ArticleAttachmentIndex(
				ArticleID => $Article{ArticleID},
				UserID => 1,
			);

			my ($FileID) = first { $AttachmentIndex{$_}->{Filename} eq 'file-2' }keys %AttachmentIndex;
			my %File = $TicketObject->ArticleAttachment(
				FileID => $FileID,
				ArticleID => $Article{ArticleID},
				UserID => 1,
			);

			if ( $File{Content} eq $HTMLFile->{Content} ) {
				$Found++;
				$TicketID = $PossibleTicket;
				last POSSIBLETICKET;
			}
	}
	$TicketID = undef if !$Found;
 }
 if ( $TicketID ) {
	$TicketObject->TicketMerge(
		MainTicketID => $TicketID,
		MergeTicketID => $Param{TicketID},
		UserID => 1,
	);
 }
 
 return 1;
}

1;
The problem is that everytime when he merge a ticket he create a new one. It is possible to add a identical ticket as a note?
So that we have 1 ticket with for example 5 notes?

Thanks.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Merge Ticket as a note

Post by crythias »

So, if all tickets say "Help", they all are identical?
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

They check the sender and subject. If they are similar they will merge.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Merge Ticket as a note

Post by reneeb »

This should be possible with a "pre"-filter. Can you open a issue at https://github.com/reneeb/otrs-MergeIdenticalTickets ? I try to implement that until next week...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

Did it.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Merge Ticket as a note

Post by reneeb »

Fixed as of version 4.0.2...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

I tried it now but he merge still like a normal ticket and not as a note..
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Merge Ticket as a note

Post by reneeb »

Please check the SysConfig options. The "old" behaviour is still default, please activate the "pre" module and deactivate the "post" module...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

I checked it. Now i've the settings like you said.
But the "pre" filter still don't work. He create two tickets which have the similar sender, subject and body.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Merge Ticket as a note

Post by reneeb »

Can you post your configuration and the two mails (with replaced mailaddresses)?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

Do you mean like this?

The mails:

--------------------
From: XXX
Sent: Mittwoch, 3. Juni 2015 11:13
To: XXX
Subject: Test1144

Test1144
--------------------

and attached you'll find the sysconf
You do not have the required permissions to view the files attached to this post.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Merge Ticket as a note

Post by reneeb »

Thanks, I'll look at it tomorrow...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

How is the status?
ovron
Znuny newbie
Posts: 19
Joined: 23 Apr 2015, 15:29
Znuny Version: 4.0.7

Re: Merge Ticket as a note

Post by ovron »

??
Locked