<commit_before># --
# Kernel/System/PostMaster/FollowUp.pm - the sub part of PostMaster.pm
# Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
# --
# $Id: FollowUp.pm,v 1.47 2006-11-02 13:02:04 tr Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::PostMaster::FollowUp;

use strict;
use Kernel::System::User;

use vars qw($VERSION);
$VERSION = '$Revision: 1.47 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);

    foreach (keys %Param) {
        $Self->{$_} = $Param{$_};
    }

    $Self->{Debug} = $Param{Debug} || 0;

    # check needed Objects
    foreach (qw(DBObject ConfigObject TicketObject LogObject ParseObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    $Self->{UserObject} = Kernel::System::User->new(%Param);

    return $Self;
}

sub Run {
    my $Self = shift;
    my %Param = @_;

    # check needed stuff
    foreach (qw(TicketID InmailUserID GetParam Tn AutoResponseType)) {
        if (!$Param{$_}) {
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
            return;
        }
    }
    my %GetParam = %{$Param{GetParam}};
    # get ticket data
    my %Ticket = $Self->{TicketObject}->TicketGet(TicketID => $Param{TicketID});

    my $Comment = $Param{Comment} || '';
    my $Lock = $Param{Lock} || '';
    my $AutoResponseType = $Param{AutoResponseType} || '';

    # Check if owner of ticket is still valid
    my %UserInfo = $Self->{UserObject}->GetUserData(
        UserID => $Ticket{OwnerID},
    );
    # check data
    if ($UserInfo{ValidID} eq 1) {
        # set lock (if ticket should be locked on follow up)
        if ($Lock && $Ticket{StateType} =~ /^close/i) {
            $Self->{TicketObject}->LockSet(
                TicketID => $Param{TicketID},
                Lock => 'lock',
                UserID => => $Param{InmailUserID},
            );
            if ($Self->{Debug} > 0) {
                print "Lock: lock\n";
                $Self->{LogObject}->Log(
                    Priority => 'notice',
                    Message => "Ticket [$Param{Tn}] still locked",
                );
            }
        }
    }
    else {
        # Unlock ticket, because current user is set to invalid
        $Self->{TicketObject}->LockSet(
            TicketID => $Param{TicketID},
            Lock => 'unlock',
            UserID => => $Param{InmailUserID},
        );
        $Self->{LogObject}->Log(
            Priority => 'notice',
            Message => "Ticket [$Param{Tn}] unlocked, current owner is invalid!",
        );
    }
    # set state
    my $State = $Self->{ConfigObject}->Get('PostmasterFollowUpState') || 'open';
    if ($GetParam{'X-OTRS-FollowUp-State'}) {
        $State = $GetParam{'X-OTRS-FollowUp-State'};
    }

    if ($Ticket{StateType} !~ /^new/ || $GetParam{'X-OTRS-FollowUp-State'}) {
        $Self->{TicketObject}->StateSet(
            State => $GetParam{'X-OTRS-FollowUp-State'} || $State,
            TicketID => $Param{TicketID},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "State: $State\n";
        }
    }
    # set priority
    if ($GetParam{'X-OTRS-FollowUp-Priority'}) {
        $Self->{TicketObject}->PrioritySet(
            TicketID => $Param{TicketID},
            Priority => $GetParam{'X-OTRS-FollowUp-Priority'},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "PriorityUpdate: $GetParam{'X-OTRS-FollowUp-Priority'}\n";
        }
    }
    # set queue
    if ($GetParam{'X-OTRS-FollowUp-Queue'}) {
        $Self->{TicketObject}->MoveTicket(
            Queue => $GetParam{'X-OTRS-FollowUp-Queue'},
            TicketID => $Param{TicketID},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "QueueUpdate: $GetParam{'X-OTRS-FollowUp-Queue'}\n";
        }
    }
    # set free ticket text
    my @Values = ('X-OTRS-FollowUp-TicketKey', 'X-OTRS-FollowUp-TicketValue');
    my $CounterTmp = 0;
    while ($CounterTmp <= 8) {
        $CounterTmp++;
        if ($GetParam{"$Values[0]$CounterTmp"}) {
            $Self->{TicketObject}->TicketFreeTextSet(
                TicketID => $Param{TicketID},
                Key => $GetParam{"$Values[0]$CounterTmp"},
                Value => $GetParam{"$Values[1]$CounterTmp"},
                Counter => $CounterTmp,
                UserID => $Param{InmailUserID},
            );
            if ($Self->{Debug} > 0) {
                print "TicketKey$CounterTmp: ".$GetParam{"$Values[0]$CounterTmp"}."\n";
                print "TicketValue$CounterTmp: ".$GetParam{"$Values[1]$CounterTmp"}."\n";<commit_msg>Fixed bug #1523 - Update of FreetextValues 9-16 not working<commit_after># --
# Kernel/System/PostMaster/FollowUp.pm - the sub part of PostMaster.pm
# Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
# --
# $Id: FollowUp.pm,v 1.48 2006-12-08 09:30:08 cs Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::PostMaster::FollowUp;

use strict;
use Kernel::System::User;

use vars qw($VERSION);
$VERSION = '$Revision: 1.48 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);

    foreach (keys %Param) {
        $Self->{$_} = $Param{$_};
    }

    $Self->{Debug} = $Param{Debug} || 0;

    # check needed Objects
    foreach (qw(DBObject ConfigObject TicketObject LogObject ParseObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    $Self->{UserObject} = Kernel::System::User->new(%Param);

    return $Self;
}

sub Run {
    my $Self = shift;
    my %Param = @_;

    # check needed stuff
    foreach (qw(TicketID InmailUserID GetParam Tn AutoResponseType)) {
        if (!$Param{$_}) {
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
            return;
        }
    }
    my %GetParam = %{$Param{GetParam}};
    # get ticket data
    my %Ticket = $Self->{TicketObject}->TicketGet(TicketID => $Param{TicketID});

    my $Comment = $Param{Comment} || '';
    my $Lock = $Param{Lock} || '';
    my $AutoResponseType = $Param{AutoResponseType} || '';

    # Check if owner of ticket is still valid
    my %UserInfo = $Self->{UserObject}->GetUserData(
        UserID => $Ticket{OwnerID},
    );
    # check data
    if ($UserInfo{ValidID} eq 1) {
        # set lock (if ticket should be locked on follow up)
        if ($Lock && $Ticket{StateType} =~ /^close/i) {
            $Self->{TicketObject}->LockSet(
                TicketID => $Param{TicketID},
                Lock => 'lock',
                UserID => => $Param{InmailUserID},
            );
            if ($Self->{Debug} > 0) {
                print "Lock: lock\n";
                $Self->{LogObject}->Log(
                    Priority => 'notice',
                    Message => "Ticket [$Param{Tn}] still locked",
                );
            }
        }
    }
    else {
        # Unlock ticket, because current user is set to invalid
        $Self->{TicketObject}->LockSet(
            TicketID => $Param{TicketID},
            Lock => 'unlock',
            UserID => => $Param{InmailUserID},
        );
        $Self->{LogObject}->Log(
            Priority => 'notice',
            Message => "Ticket [$Param{Tn}] unlocked, current owner is invalid!",
        );
    }
    # set state
    my $State = $Self->{ConfigObject}->Get('PostmasterFollowUpState') || 'open';
    if ($GetParam{'X-OTRS-FollowUp-State'}) {
        $State = $GetParam{'X-OTRS-FollowUp-State'};
    }

    if ($Ticket{StateType} !~ /^new/ || $GetParam{'X-OTRS-FollowUp-State'}) {
        $Self->{TicketObject}->StateSet(
            State => $GetParam{'X-OTRS-FollowUp-State'} || $State,
            TicketID => $Param{TicketID},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "State: $State\n";
        }
    }
    # set priority
    if ($GetParam{'X-OTRS-FollowUp-Priority'}) {
        $Self->{TicketObject}->PrioritySet(
            TicketID => $Param{TicketID},
            Priority => $GetParam{'X-OTRS-FollowUp-Priority'},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "PriorityUpdate: $GetParam{'X-OTRS-FollowUp-Priority'}\n";
        }
    }
    # set queue
    if ($GetParam{'X-OTRS-FollowUp-Queue'}) {
        $Self->{TicketObject}->MoveTicket(
            Queue => $GetParam{'X-OTRS-FollowUp-Queue'},
            TicketID => $Param{TicketID},
            UserID => $Param{InmailUserID},
        );
        if ($Self->{Debug} > 0) {
            print "QueueUpdate: $GetParam{'X-OTRS-FollowUp-Queue'}\n";
        }
    }
    # set free ticket text
    my @Values = ('X-OTRS-FollowUp-TicketKey', 'X-OTRS-FollowUp-TicketValue');
    my $CounterTmp = 0;
    while ($CounterTmp <= 16) {
        $CounterTmp++;
        if ($GetParam{"$Values[0]$CounterTmp"}) {
            $Self->{TicketObject}->TicketFreeTextSet(
                TicketID => $Param{TicketID},
                Key => $GetParam{"$Values[0]$CounterTmp"},
                Value => $GetParam{"$Values[1]$CounterTmp"},
                Counter => $CounterTmp,
                UserID => $Param{InmailUserID},
            );
            if ($Self->{Debug} > 0) {
                print "TicketKey$CounterTmp: ".$GetParam{"$Values[0]$CounterTmp"}."\n";
                print "TicketValue$CounterTmp: ".$GetParam{"$Values[1]$CounterTmp"}."\n";
{'fraction_non_alphanumeric': 0.17473306057279714, 'fraction_numerical': 0.00938030136712903, 'mean_word_length': 2.133833646028768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540122', 'n_tokens_mistral': 3422, 'n_tokens_neox': 3244, 'n_words': 661}