Can't locate object method "GetUserData" via package "Kernel

English! place to talk about development, programming and coding
Post Reply
remo
Znuny newbie
Posts: 4
Joined: 22 Feb 2014, 23:35
Znuny Version: 5.0.23

Can't locate object method "GetUserData" via package "Kernel

Post by remo »

Hi folks

We are evaluating the use of otrs for our company and I got the development part... so I'm totaly new to otrs development and it's model.

I'm having some trouble with my modul on the customer frontend. The same module is running fine for the agents but on the customer frontend I'm getting an 500 internal server error back from apache:

Code: Select all

[Sat Feb 22 22:24:20 2014] [error] Can't locate object method "GetUserData" via package "Kernel::System::CustomerUser" at /opt/otrs//Kernel/Output/HTML/NotificationOutofOfficeCheck.pm line 32.\n
I was also trying to load this package directly in the CustomerMonitoring.pm frontend module with

Code: Select all

use Kernel::System::User;
use Kernel::System::CustomerUser;
but I guess the error is even before the load of my CustomerMonitoring frontend module?! Any other already built in modules like ticket and faq are running fine.

OTRS / Server Infos:

Code: Select all

DOCUMENT_ROOT	/opt/otrs/var/httpd/htdocs/
GATEWAY_INTERFACE	CGI/1.1
MOD_PERL	mod_perl/2.0.7
MOD_PERL_API_VERSION	2
PATH	/usr/local/bin:/usr/bin:/bin
SCRIPT_FILENAME	/opt/otrs/bin/cgi-bin/index.pl
SERVER_PORT	80
SERVER_PROTOCOL	HTTP/1.1
SERVER_SIGNATURE	
SERVER_SOFTWARE	Apache

Linux tnlabs-webdev01 2.6.32-5-686 #1 SMP Mon Sep 23 23:00:18 UTC 2013 i686 GNU/Linux

This is perl 5, version 14, subversion 2 (v5.14.2) built for i486-linux-gnu-thread-multi-64int
(with 88 registered patches, see perl -V for more detail)

Server version: Apache/2.2.22 (Debian)
Server built:   Mar  4 2013 21:32:29

This is the CustomerMonitoring frontend module:

Code: Select all

package Kernel::Modules::CustomerMonitoring;

use strict;
use warnings;

use Kernel::System::Monitoring;


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

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

    # check needed objects
    # check all needed objects
    for (qw(ParamObject DBObject QueueObject LayoutObject ConfigObject LogObject SessionObject UserObject UserID)) {
        if ( !$Self->{$_} ) {
            $Self->{LayoutObject}->FatalError( Message => "Got no $_!" );
        }
    }

    # create needed objects
    $Self->{MonitoringObject} = Kernel::System::Monitoring->new(%Param);

    return $Self;
}

sub Run() {
	my ($Self, %Param ) = @_;
	my %Data = ();
	
	$Data{MonitoringFrame} = $Self->{MonitoringObject}->GetMonitoringFrame();
	
	# Build the output
	my $Output 	 = $Self->{LayoutObject}->Header(Title => "Monitoring Informations");
	$Output		.= $Self->{LayoutObject}->NavigationBar();
	$Output		.= $Self->{LayoutObject}->Output(
		Data => \%Data,
		TemplateFile => 'CustomerMonitoringFrame'
	);
	$Output		.= $Self->{LayoutObject}->Footer();
	return $Output;
}

1;
This it the Monitoring.pm core module:

Code: Select all

package Kernel::System::Monitoring;

use strict;
use warnings;

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

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

    return $Self;
}

sub GetMonitoringFrame() {
	my ($Self, %Param ) = @_;
	
	return "<iframe src=\"http://FRAME-URL/ABC/YXZ\" style=\"margin:0; padding:0; border:none; height:100%; width:100%;\"></iframe>";
}

1;

For a customer frontend module, do I need to load or create something other then in the agent frontend?


Thank you very much for your help and time!!

Best regards,
Remo

PS: just let me know if you need any more infos!
Last edited by remo on 24 Feb 2014, 02:12, edited 1 time in total.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Working agent module not running on customer frontend

Post by crythias »

Perhaps it might be good to tell us:
This is supposed to do _____________

perldoc Kernel/System/CustomerUser.pm

Code: Select all

       CustomerUserDataGet()
           get user data (UserLogin, UserFirstname, UserLastname, UserEmail, ...)

               my %User = $CustomerUserObject->CustomerUserDataGet(
                   User => 'franz',
               );
Since you have an error in
/opt/otrs//Kernel/Output/HTML/NotificationOutofOfficeCheck.pm line 32

Why didn't you show that file?

What version of OTRS are you running against?
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
remo
Znuny newbie
Posts: 4
Joined: 22 Feb 2014, 23:35
Znuny Version: 5.0.23

Re: Working agent module not running on customer frontend

Post by remo »

hi crythias

First of all, thanks for your time!

We are running OTRS 3.3.4. This CustomerMonitoring module is about to give our customer the ability to access our monitoring server which is part of our managed security service... so it's including a HTML iframe. I didn't show the NotificationOutofOfficeCheck.pm module because the OTRS installation which we are running has still the original default settings and original code as well and based on this fact I didn't include the code of it... a very important information which I forgot... sorry about that! :)

I think it's not about a bug in /opt/otrs//Kernel/Output/HTML/NotificationOutofOfficeCheck.pm because this file seems to be called from somewhere and it's missing the UserObject objectvar what wasn't created before?! just laud thinking ...

NotificationOutofOfficeCheck.pm:

Code: Select all

# --
# Kernel/Output/HTML/NotificationOutofOfficeCheck.pm
# Copyright (C) 2001-2014 xxx, 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::Output::HTML::NotificationOutofOfficeCheck;

use strict;
use warnings;

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

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

    # get needed objects
    for (qw(ConfigObject LogObject DBObject LayoutObject TimeObject UserObject UserID)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }
    return $Self;
}

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

    my %UserData = $Self->{UserObject}->GetUserData( UserID => $Self->{UserID} );
    return '' if ( !$UserData{OutOfOffice} );

    my $Time = $Self->{TimeObject}->SystemTime();

    my $Start
        = "$UserData{OutOfOfficeStartYear}-$UserData{OutOfOfficeStartMonth}-$UserData{OutOfOfficeStartDay} 00:00:00";

    my $TimeStart = $Self->{TimeObject}->TimeStamp2SystemTime(
        String => $Start,
    );
    my $End
        = "$UserData{OutOfOfficeEndYear}-$UserData{OutOfOfficeEndMonth}-$UserData{OutOfOfficeEndDay} 23:59:59";
    my $TimeEnd = $Self->{TimeObject}->TimeStamp2SystemTime(
        String => $End,
    );
    if ( $TimeStart < $Time && $TimeEnd > $Time ) {
        return $Self->{LayoutObject}->Notify(
            Priority => 'Notice',
            Link     => '$Env{"Baselink"}Action=AgentPreferences',
            Data =>
                '$Text{"You have Out of Office enabled, would you like to disable it?"}',
        );
    }
    else {
        return '';
    }
}

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

Re: Working agent module not running on customer frontend

Post by crythias »

Let me revise my position.

Your title is the problem.
Working agent module not running on customer frontend
It's an agent module. It's designed to run as/for an agent. It doesn't support CustomerUser.
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
remo
Znuny newbie
Posts: 4
Joined: 22 Feb 2014, 23:35
Znuny Version: 5.0.23

Re: Can't locate object method "GetUserData" via package "Ke

Post by remo »

Ok. Do you know where I can find a customer module example like the HelloWorld agent module from the developer manual? Because I don't know where's exactly the difference between an agent and a customer module in focus of the code?

It's easy to say that the module is not running because its designed for agents... but why? What is missing to run correctly on the customer frontend?

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

Re: Can't locate object method "GetUserData" via package "Ke

Post by crythias »

Summary: customer authentication and methods are handled differently from agent/user authentication.

The error message you got is attempting to apply an agent method against a Customer User.

And again, I don't know what you're trying to do on the Customer side (I don't have time to read your code to find out), so I can't/won't tell you how to fix it.

It's trivial to provide a "Hello, World!" module for Customers. Kernel/Modules/Test.pm is rather generic and doesn't specify either CustomerUserObject or UserObject.

I can assume you're trying to tell customers that agents are Out of Office. I'm not entirely certain you need to do this. But if you did, I'd point to a different method:

viewtopic.php?f=60&t=18347

(maybe). It's a bit more complicated, but the gist is, (in my opinion) that unless your office is closed, and *nobody* is going to handle the customer, then there's no real point in telling the customer agent X isn't available. OK, I have personal exceptions to this, but unless you have agent-based-queues, someone's likely to address the Customer's ticket.
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
remo
Znuny newbie
Posts: 4
Joined: 22 Feb 2014, 23:35
Znuny Version: 5.0.23

Re: Can't locate object method "GetUserData" via package "Ke

Post by remo »

I appreciate your help but its sad to me that you didn't take at least 5 mins to review the CustomerMonitoring.pm frontend module code! My module code is completely similar to the HelloWorld agent module from the development manual. The only difference between my code and them from the development manual: I'm returning a html frame instead of the "HelloWorld!" string.

My script (designed to run for customers) was creating an agent frontend instead of a customer frontend (I didn't know that I have to call function "CustomerHeader" instead of "Header"... actually this is very bad documented) and this was causing the NotificationOutOfOffice function call...
In fact: The out of office check is done automatically during the creation of agent frontends to display a warning if such an out of office is configured in the agents settings.

Code: Select all

# Build the output for customer user
my $Output       = $Self->{LayoutObject}->CustomerHeader(Title => "Monitoring Information");
$Output         .= $Self->{LayoutObject}->CustomerNavigationBar();
$Output         .= $Self->{LayoutObject}->Output(
        Data => \%Data,
        TemplateFile => 'CustomerMonitoringFrame'
);
$Output         .= $Self->{LayoutObject}->CustomerFooter();
return $Output;
I'm a bit frustrated... but its working now.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Can't locate object method "GetUserData" via package "Ke

Post by crythias »

remo wrote:You didn't take at least 5 mins to review the CustomerMonitoring.pm frontend module code
Please understand: My workflow on this board is to answer specific questions to achieve specific results.
Whether you gave me a 5 line attachment or War and Peace, I'm not going to read it when I expect to find relevant content in the body of the message.

Look at this from a point of view of if you were given this in exactly the same way you provided this to this forum, what would be the first question you would have asked?
How would you have responded if that question was ignored or told "Just look at the code!"

The fact that you found answers that were completely not part of your original question means we'd be missing important information to answer your question.

I respect you don't understand the model/structure of OTRS, but I'm telling you this so in the future if you have questions you can ask better questions.
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
Post Reply