Creating hello world module example

Moderator: tto

eandrex
OTRS superhero
Posts: 213
Joined: 04 Nov 2012, 23:58
OTRS Version?: OTRS 4.x
Real Name: Esteban
Company: NORTON DE COLOMBIA

Creating hello world module example

Postby eandrex » 07 Nov 2012, 19:40

Hi, i am a really beginner at this, but however, i have been reading these forums and developer docs for a while.

So today i was reading this guide: http://doc.otrs.org/developer/3.1/en/ht ... dp38876496, created those directories, default xml file, but after it, i get this

After creating the links and executing the Sysconfig, a new module with the name 'HelloWorld' is displayed. When calling it up, an error message is displayed as OTRS cannot find the matching frontend module yet. This is the next thing to be created. To do so, we create the following fil

wait!...what links? and does "executing the sysconfig" mean? why do i have to do at this step, so any help is very appreciated..

im running w7 64 bits, otrs 3.1 mysql.


Thank you in advanced

eandrex
OTRS superhero
Posts: 213
Joined: 04 Nov 2012, 23:58
OTRS Version?: OTRS 4.x
Real Name: Esteban
Company: NORTON DE COLOMBIA

Re: Creating hello world module example

Postby eandrex » 07 Nov 2012, 22:23

ok, i thing i "got" this...reading "chapter 1.getting started"

i see how to link

shell> /src/module-tools/link.pl src/to/your/module /src/to/otrs

and after it, how to run "sysconfig"

shell> cat yourmodule.sopm | bin/xml2sql.pl -t mysql

so let's see what is happening..when im trying to link, i am getting those errors and no way to make it link

first case:

command line: C:\Users\Sanchez\workspace\module-tools\link.pl "C:\Users\Sanchez\workspace\HelloWorldModule" "D:\OTRS\OTRS"
error: http://i49.tinypic.com/293hmk4.png

second case:

command line: C:\Users\Sanchez\workspace\module-tools\link.pl 'C:/Users/Sanchez/workspace/HelloWorldModule' 'D:/OTRS/OTRS'
notice simple quotes and changed \ to /

error: http://i48.tinypic.com/nz3nkp.png

command line: C:\Users\Sanchez\workspace\module-tools\link.pl C:/Users/Sanchez/workspace/HelloWorldModule D:/OTRS/OTRS
without quotes

error: http://i49.tinypic.com/jqm9no.png

:(

i have attached HelloWorlModule... so if anyone can help me..thank you thank you :)

by the way, if i get that work, second step says "cat yourmodule.sopm | bin/xml2sql.pl -t mysql"

do i have to generate "yourmodule.sopm" or it will be generate by itself?, also, is it "cat" a command recognized by windows?

what is "bin/xml2sql.pl" ?, where is that path?

thank you :)
You do not have the required permissions to view the files attached to this post.

reneeb
OTRS guru
Posts: 4338
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: Creating hello world module example

Postby reneeb » 07 Nov 2012, 23:12

OTRS development on a windows system can be quite difficult because some tools do not work on windows. Such a tool is link.pl. Symlinks aren't originally supported on windows, see also http://www.perlmonks.org/?node_id=933175

"cat" is a small tool on *NIX to print the content of a file on the STDOUT (terminal). On Windows you can use "type", see also http://stackoverflow.com/questions/6024 ... dows#60254

You have to create the .sopm yourself! It is the Package spec file, see http://doc.otrs.org/developer/3.0/en/ht ... blish.html

"bin/xml2sql.pl" is a tool that comes with OTRS. But it was renamed with OTRS 3.0 to bin/otrs.xml2sql.pl.
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

eandrex
OTRS superhero
Posts: 213
Joined: 04 Nov 2012, 23:58
OTRS Version?: OTRS 4.x
Real Name: Esteban
Company: NORTON DE COLOMBIA

Re: Creating hello world module example

Postby eandrex » 08 Nov 2012, 00:44

Hi, thank you for your quick reply as usual.

So i guess i will have to switch Ubuntu or something like that =S..i am jumping from an error to another hahaha, so better avoid it..

I just hope on ubuntu it isnt so difficult as on windows is

Right now im downloading ubuntu 12.04 32 bits lts
after it i will have to install and configure Apache, mysql(i have read perl is already included), and finally install OTRS (http://wiki.otterhub.org/index.php?titl ... %2810.4%29)

if i make an otrs module(hope so), it will run on windows too?

any suggestion for someone who starts from zero(otrs+perl)?

reneeb
OTRS guru
Posts: 4338
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: Creating hello world module example

Postby reneeb » 08 Nov 2012, 12:06

As long as you do not use operating system specific stuff, your OTRS package runs anywhere OTRS itself runs. It's very unlikely that you use operating system specific stuff ;-) So start hacking and ask questions when need some help...
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

eandrex
OTRS superhero
Posts: 213
Joined: 04 Nov 2012, 23:58
OTRS Version?: OTRS 4.x
Real Name: Esteban
Company: NORTON DE COLOMBIA

Re: Creating hello world module example

Postby eandrex » 09 Nov 2012, 17:22

Hi, reneeb.! Just thank you ;)

Finally i made it hahahah, thats what i needed to start :P

Image

now, if you dont mind, could you explain me something about the code?

at Kernel/Modules/AgentHelloWorld.pm we got

Code: Select all

# --
# Kernel/Modules/AgentHelloWorld.pm - frontend modul
# Copyright (C) (year) (name of author) (email of author)
# --
# $Id: writing-otrs-application.xml,v 1.3 2012/05/07 07:46:47 mh 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::Modules::AgentHelloWorld;

use strict;
use warnings;

use Kernel::System::HelloWorld;

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

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

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

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

    return $Self;
}

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

    $Data{HelloWorldText} = $Self->{HelloWorldObject}->GetHelloWorldText();

    # build output
    my $Output = $Self->{LayoutObject}->Header(Title => "HelloWorld");
    $Output   .= $Self->{LayoutObject}->NavigationBar();
    $Output   .= $Self->{LayoutObject}->Output(
        Data => \%Data,
        TemplateFile => 'AgentHelloWorld',
    );
    $Output   .= $Self->{LayoutObject}->Footer();
    return $Output;
}

1;


are sub "new" and "run" obligatories for every module?

i am very newbie with otrs code and perl,

why in every sub, there is this line

"my ( $Self, %Param ) = @_;" what does it do? it is from otrs API?

if you can explain me as many things as you can(or provide me links to read) to make me understand how otrs works, i would be very grateful


EDIT: additional question

why in the xml file in the middle of tags <subgroup></subgroup> is this line

Code: Select all

Frontend::Agent::ModuleRegistration

i guess if it was

Code: Select all

Frontend::Customer::ModuleRegistration

the hello world module would be show up to all customers...what i want to know is where can i read possibles values that i can write in there

thankk you

reneeb
OTRS guru
Posts: 4338
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: Creating hello world module example

Postby reneeb » 10 Nov 2012, 11:26

So to your questions:

*) Yes, subroutines named "new" and "Run" are mandatory for frontend modules (Kernel::Modules::*)

*) "my ( $Self, %Param ) = @_;"

In @_ are all the parameters that are passed to the subroutine:

$Object->Run( 1, 2, 3, 4);

Now in @_ are the $Object and the numbers 1,2,3, and 4. With the line you mentioned the parameters passed to the subroutine are assigned to variables. As OTRS is programmed in some kind of object orientation, the first parameter of the subroutine is the object itself. It's standard in Perl programming to name it "self".

Please read http://perldoc.perl.org/perlobj.html

*) The subgroup is just for grouping SysConfig options. You can put in there whatever you want. It's standard for OTRS to name the subgroup for agent frontend modules "Frontend::Agent::ModuleRegistration". You can see the subgroup names when you open SysConfig and select e.g. Framework (which is the "Group"). Then the next page is opened where you can select "Core::Sendmail", "Core::Log", ... - that's the subgroup.

If you want to create a customer frontend module, you have to name it "CustomerFrontend::Module###..." see Kernel/Config/Files/Ticket.xml for examples...
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de


Return to “Patches / Modules”

Who is online

Users browsing this forum: No registered users and 2 guests