Redefine errors in module

Moderator: crythias

Locked
JWS
Znuny newbie
Posts: 2
Joined: 12 Nov 2011, 14:44
Znuny Version: 3.0.11

Redefine errors in module

Post by JWS »

Hello,

I'm trying to create a custom module based on this guide.
I added the XML file, the .pm file in the described directories, and the configuration line in Config.pm. However, I only get a blank screen when triggered.

The /var/log/httpd/error_log log says (module's called AddToShiftreport):

Code: Select all

AddToShiftreport.pm: Subroutine new redefined at /opt/otrs//Kernel/System/Ticket/Event/AddToShiftreport.pm line 20.
AddToShiftreport.pm: Subroutine Run redefined at /opt/otrs//Kernel/System/Ticket/Event/AddToShiftreport.pm line 43.
If I don't load the module, everything works fine. So it definitely triggers it, but somehow exits when loaded.

Config.pm module load:
(in the Load{} 'Start of your own config options!!!' section)

Code: Select all

$Self->{'Ticket::EventModulePost'}->{'137-AddToShiftreport'} = {
       'Event' => '(TicketLockUpdate)',
       'Module' => 'Kernel::System::Ticket::Event::AddToShiftreport',
};
I searched this forum, Google, but couldn't really find anything helpful.
I'm running OTRS 3.0.11

What am I doing wrong?
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Redefine errors in module

Post by crythias »

If the subroutine is redefined, it means (or would seem to indicate) that you have two sub new and two sub Run. Is that accurate?
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
JWS
Znuny newbie
Posts: 2
Joined: 12 Nov 2011, 14:44
Znuny Version: 3.0.11

Re: Redefine errors in module

Post by JWS »

Thanks for the swift reply.

I thought that as well, but it seems it's coming from somewhere else, because I'm using the default one from the guide (which has only one of each).

AddToShiftreport.pm:

Code: Select all

# --
# Kernel/System/Ticket/Event/EventModulePostTemplate.pm - event module
# Copyright (C) 2001-2010 xxx, http://otrs.org/
# --
# $Id: EventModulePostTemplate.pm,v 1.1 2010/05/10 17:56:20 sb Exp $
# --
# 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::Ticket::Event::AddToShiftreport;

use strict;
use warnings;

use vars qw($VERSION);
$VERSION = qw($Revision: 1.1 $) [1];

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

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

    # get needed objects
    for (
        qw(
        ConfigObject CustomerGroupObject CustomerUserObject DBObject EncodeObject GroupObject
        HTMLUtilsObject LinkObject LockObject LogObject LoopProtectionObject MainObject
        PriorityObject QueueObject SendmailObject ServiceObject SLAObject StateObject
        TicketObject TimeObject TypeObject UserObject ValidObject
        )
        )
    {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    return $Self;
}

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

    # check needed stuff
    for (qw(TicketID Event Config)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }

    return 1 if $Param{Event} ne 'TicketCreate';

    my %Ticket = $Self->{TicketObject}->TicketGet(
        TicketID => $Param{TicketID},
        UserID   => 1,
    );
    return 1 if !%Ticket;
    #return 1 if $Ticket{State} eq 'Open';

    # do some stuff
    $Self->{TicketObject}->HistoryAdd(
        TicketID     => $Param{TicketID},
        CreateUserID => 22,
        HistoryType  => 'Misc',
        Name         => 'New ticket with state other than Open!',
    );

    return 1;
}

1;
I didn't edit anything other than the package name and the CreateUserID, because I couldn't even get past these errors.

Could this be a conflict with another module? Though this is confusing, because every default module has these subroutines, which would mean you can only load one.
Locked