<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/TicketLockSet.pm - A Module to unlock a 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::TicketLockSet;

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

use utf8;

=head1 NAME

Kernel::System::ProcessManagement::TransitionAction::TicketLockSet - A module to unlock a ticket

=head1 SYNOPSIS

All TicketLockSet 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::TicketLockSet;

    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 $TicketLockSetActionObject = Kernel::System::ProcessManagement::TransitionAction::TicketLockSet-&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};
    }

    $Self-&gt;{LockObject} = Kernel::System::Lock-&gt;new(
        %Param,
        DBObject   =&gt; $Self-&gt;{DBObject},
        MainObject =&gt; $Self-&gt;{MainObject},
        TimeObject =&gt; $Self-&gt;{TimeObject},
    );

    return $Self;
}

=item Run()

    Run Data

    my $TicketLockSetResult = $TicketLockSetActionObject-&gt;Run(
        UserID                   =&gt; 123,
        Ticket                   =&gt; \%Ticket,   # required
        ProcessEntityID          =&gt; 'P123',
        ActivityEntityID         =&gt; 'A123',
        TransitionEntityID       =&gt; 'T123',
        TransitionActionEntityID =&gt; 'TA123',
        Config                   =&gt; {
            Lock  =&gt; 'lock',
            # or
            LockID =&gt; 1,
            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:

    $TicketLockSetResult = 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};
    }

    if ( !$Param{Config}-&gt;{LockID} &amp;&amp; !$Param{Config}-&gt;{Lock} ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage . "No Lock or LockID configured!",
        );
        return;
    }

    my $Success;

    # If Ticket's LockID is already the same as the Value we
    # should set it to, we got nothing to do and return success
    if (
        defined $Param{Config}-&gt;{LoclID}
        &amp;&amp; $Param{Config}-&gt;{LockID} eq $Param{Ticket}-&gt;{LockID}
        )
    {
        return 1;
    }

    # If Ticket's LockID is not the same as the Value we
    # should set it to, set the LockID
    elsif (
        defined $Param{Config}-&gt;{LockID}
        &amp;&amp; $Param{Config}-&gt;{LockID} ne $Param{Ticket}-&gt;{LockID}
        )
    {
        $Success = $Self-&gt;{TicketObject}-&gt;TicketLockSet(
            TicketID =&gt; $Param{Ticket}-&gt;{TicketID},
            LockID   =&gt; $Param{Config}-&gt;{LockID},
            UserID   =&gt; $Param{UserID},
        );

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

    # If Ticket's Lock is already the same as the Value we
    # should set it to, we got nothing to do and return success
    elsif (
        defined $Param{Config}-&gt;{Lock}
        &amp;&amp; $Param{Config}-&gt;{Lock} eq $Param{Ticket}-&gt;{Lock}
        )
    {
        return 1;
    }

    # If Ticket's Lock is not the same as the Value we
    # should set it to, set the Lock
    elsif (
        defined $Param{Config}-&gt;{Lock}
        &amp;&amp; $Param{Config}-&gt;{Lock} ne $Param{Ticket}-&gt;{Lock}
        )
    {
        $Success = $Self-&gt;{TicketObject}-&gt;TicketLockSet(
            TicketID =&gt; $Param{Ticket}-&gt;{TicketID},
            Lock     =&gt; $Param{Config}-&gt;{Lock},
            UserID   =&gt; $Param{UserID},
        );

        if ( !$Success ) {
            $Self-&gt;{LogObject}-&gt;Log(
                Priority =&gt; 'error',
                Message  =&gt; $CommonMessage
                    . 'Ticket Lock '
                    . $Param{Config}-&gt;{Lock}
                    . ' could not be updated for Ticket: '
                    . $Param{Ticket}-&gt;{TicketID} . '!',
            );
        }
    }
    else {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; $CommonMessage
                . "Couldn't update Ticket Lock - can't find valid Lock parameter!",
        );
        return;
    }

    return $Success;
}

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>