<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># --
# Kernel/System/ProcessManagement/TransitionAction/TicketTitleSet.pm - A Module to set the title of a process ticket
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# 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::ProcessManagement::TransitionAction::TicketTitleSet;

use strict;
use warnings;
use Kernel::System::VariableCheck qw(:all);

use utf8;

=head1 NAME

Kernel::System::ProcessManagement::TransitionAction::TicketTitleSet - A Module to set the title of a Ticket

=head1 SYNOPSIS

All TicketTitleSet functions.

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create an object

    use Kernel::Config;
    use Kernel::System::Encode;
    use Kernel::System::Log;
    use Kernel::System::Time;
    use Kernel::System::Main;
    use Kernel::System::DB;
    use Kernel::System::Ticket;
    use Kernel::System::ProcessManagement::TransitionAction::TicketTitleSet;

    my $ConfigObject = Kernel::Config-&gt;new();
    my $EncodeObject = Kernel::System::Encode-&gt;new(
        ConfigObject =&gt; $ConfigObject,
    );
    my $LogObject = Kernel::System::Log-&gt;new(
        ConfigObject =&gt; $ConfigObject,
        EncodeObject =&gt; $EncodeObject,
    );
    my $TimeObject = Kernel::System::Time-&gt;new(
        ConfigObject =&gt; $ConfigObject,
        LogObject    =&gt; $LogObject,
    );
    my $MainObject = Kernel::System::Main-&gt;new(
        ConfigObject =&gt; $ConfigObject,
        EncodeObject =&gt; $EncodeObject,
        LogObject    =&gt; $LogObject,
    );
    my $DBObject = Kernel::System::DB-&gt;new(
        ConfigObject =&gt; $ConfigObject,
        EncodeObject =&gt; $EncodeObject,
        LogObject    =&gt; $LogObject,
        MainObject   =&gt; $MainObject,
    );
    my $TicketObject = Kernel::System::Ticket-&gt;new(
        ConfigObject       =&gt; $ConfigObject,
        LogObject          =&gt; $LogObject,
        DBObject           =&gt; $DBObject,
        MainObject         =&gt; $MainObject,
        TimeObject         =&gt; $TimeObject,
        EncodeObject       =&gt; $EncodeObject,
    );
    my $TicketTitleSetActionObject = Kernel::System::ProcessManagement::TransitionAction::TicketTitleSet-&gt;new(
        ConfigObject       =&gt; $ConfigObject,
        LogObject          =&gt; $LogObject,
        EncodeObject       =&gt; $EncodeObject,
        DBObject           =&gt; $DBObject,
        MainObject         =&gt; $MainObject,
        TimeObject         =&gt; $TimeObject,
        TicketObject       =&gt; $TicketObject,
    );

=cut

sub new {
    my ( $Type, %Param ) = @_;

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

    # get needed objects
    for my $Needed (
        qw(ConfigObject LogObject EncodeObject DBObject MainObject TimeObject TicketObject)
        )
    {
        die "Got no $Needed!" if !$Param{$Needed};

        $Self-&gt;{$Needed} = $Param{$Needed};
    }

    return $Self;
}

=item Run()

    Run Data

    my $TicketTitleSetResult = $TicketTitleSetActionObject-&gt;Run(
        UserID                   =&gt; 123,
        Ticket                   =&gt; \%Ticket,   # required
        ProcessEntityID          =&gt; 'P123',
        ActivityEntityID         =&gt; 'A123',
        TransitionEntityID       =&gt; 'T123',
        TransitionActionEntityID =&gt; 'TA123',
        Config                   =&gt; {
            Title  =&gt; 'Some ticket title',
            UserID =&gt; 123,                      # optional, to override the UserID from the logged user

        }
    );
    Ticket contains the result of TicketGet including DynamicFields
    Config is the Config Hash stored in a Process::TransitionAction's  Config key
    Returns:

    $TicketTitleSetResult = 1; # 0

=cut

sub Run {
    my ( $Self, %Param ) = @_;

    for my $Needed (
        qw(UserID Ticket ProcessEntityID ActivityEntityID TransitionEntityID
        TransitionActionEntityID Config
        )
        )
    {
        if ( !defined $Param{$Needed} ) {
            $Self-&gt;{LogObject}-&gt;Log(
                Priority =&gt; 'error',
                Message  =&gt; "Need $Needed!",
            );
            return;
        }
    }

    # define a common message to output in case of any error
    my $CommonMessage = "Process: $Param{ProcessEntityID} Activity: $Param{ActivityEntityID}"
        . " Transition: $Param{TransitionEntityID}"
        . " TransitionAction: $Param{TransitionActionEntityID} - ";

    # Check if we have Ticket to deal with
    if ( !IsHashRefWithData( $Param{Ticket} ) ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage . "Ticket has no values!",
        );
        return;
    }

    # Check if we have a ConfigHash
    if ( !IsHashRefWithData( $Param{Config} ) ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage . "Config has no values!",
        );
        return;
    }

    # override UserID if specified as a parameter in the TA config
    if ( IsNumber( $Param{Config}-&gt;{UserID} ) ) {
        $Param{UserID} = $Param{Config}-&gt;{UserID};
        delete $Param{Config}-&gt;{UserID};
    }

    # Check for required paramerters in ConfigHash
    if ( !defined $Param{Config}-&gt;{Title} ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage . "No Title configured!",
        );
        return;
    }

    my $Success;
    if (
        $Param{Config}-&gt;{Title} ne $Param{Ticket}-&gt;{Title}
        )
    {
        $Success = $Self-&gt;{TicketObject}-&gt;TicketTitleUpdate(
            Title    =&gt; $Param{Config}-&gt;{Title},
            TicketID =&gt; $Param{Ticket}-&gt;{TicketID},
            UserID   =&gt; $Param{UserID},
        );
    }
    else {

        # data is the same as in ticket nothing to do
        $Success = 1;
    }

    if ( !$Success ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage
                . 'Ticket title could not be updated for Ticket: '
                . $Param{Ticket}-&gt;{TicketID} . '!',
        );
        return;
    }
    return 1;
}

1;

=back

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (L&lt;http://otrs.org/&gt;).

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 L&lt;http://www.gnu.org/licenses/agpl.txt&gt;.

=cut
</pre></body></html>