Add Module

English! place to talk about development, programming and coding
Post Reply
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Add Module

Post by Smiith »

Hello everybody i'm new in OTRS and i wanna some help please !

i want to create another Module "Machine". I read in the manual that i must create 4 files in different folders to create a module:
Kernel/Config/Files => here to create a group in the Sysconfig and to add the NavBar (from what I understood)
Kernel/Modules => here to developpe the code i think (from what I understood)
Kernel/System => here too (from what I understood)
Kernel/Output/HTML/Standard => here to create the interface of the module

In the interface (*.tt) i want to create something like a form, 2 input text "MachineID" and "Machine Model".
and to save those data, i want to create another table in database of the OTRS system but i don't know how, can someone help me please ?
Thanks
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

This is a very very broad question. Where exactly do you need help now? Did you follow the example in the manual to create a module?

Where did you fail ? What did you achieve ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

RStraub wrote:This is a very very broad question. Where exactly do you need help now? Did you follow the example in the manual to create a module?

Where did you fail ? What did you achieve ?
Sorry Mr,
i think first of all that i must create a new table in database of the system to save the data there, i don't know how ?
Thanks for the quick answer ^^
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

i found something ! i think it's in /$HOME_OTRS/scripts/database/otrs-schema.mysql.sql no ?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

I think that's the setup script when you first install OTRS.

For your testing purpose, just login to your DB and execute a create table command:
http://dev.mysql.com/doc/refman/5.1/en/ ... table.html

Later you can add a create table to your .sopm file if you build a packe for your customization.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Add Module

Post by jojo »

Hi,

OTRS is a complex application with more than 200 man years of development. So please tell us first what you want to achieve before starting any coding.

If the data at the end is ticket related, you most likely will not need additional data tables as you can store the information in dynamic fields. If you just want to add the data (ID and Model) to the ticket it can jut be done with configuration.
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

jojo wrote: OTRS is a complex application with more than 200 man years of development. So please tell us first what you want to achieve before starting any coding.
i want to create another module "Machine" to
-Add machines in this module, just like customers or agents
-Search how many ticket has been opened for a specific MachineID
jojo wrote: If the data at the end is ticket related, you most likely will not need additional data tables as you can store the information in dynamic fields. If you just want to add the data (ID and Model) to the ticket it can jut be done with configuration.
yeah i know that and already added 2 dynamic fields in the ticket, thank you

So i must add a "Create Table Machine etc... " in the /scripts/database/*.sql like i said ? and which file please ? thanks
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

RStraub wrote:I think that's the setup script when you first install OTRS.

For your testing purpose, just login to your DB and execute a create table command:
http://dev.mysql.com/doc/refman/5.1/en/ ... table.html

Later you can add a create table to your .sopm file if you build a packe for your customization.
don't you think that's in the $HOME_OTRS/scripts/database/*.sql files ? because i found all the tables of the system created there.
otherwhise can you give me more details about your solution please ?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

No, I don't think that's the correct file. I highly doubt there's even a script to add a table.

What I meant is executing this:

Code: Select all

mysql -u YourUserName -D YourDBName -p
CREATE TABLE IF NOT EXISTS Machine (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(50) NOT NULL,
PRIMARY KEY (id)
)
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

RStraub wrote:No, I don't think that's the correct file. I highly doubt there's even a script to add a table.

What I meant is executing this:

Code: Select all

mysql -u YourUserName -D YourDBName -p
CREATE TABLE IF NOT EXISTS Machine (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(50) NOT NULL,
PRIMARY KEY (id)
)
thank you very much ! done !
can you help me now with the *.pm files to create the module please ?
i want to add machines, this is what i did in the Kernel/Modules/AddMachines.pm file

Code: Select all

package Kernel::Modules::AddMachines; 

use strict; 
use warnings; 

use Kernel::System::AddMachines; 

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

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

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

    # create additional objects 
    $Self->{MachinesObject}   = Kernel::System::AddMachines->new(%Param); 

    return $Self; 
} 

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

    # permission check 
    if ( !$Self->{AccessRw} ) { 
        return $Self->{LayoutObject}->NoPermission( 
            Message    => 'You need rw permission!', 
            WithHeader => 'yes', 
        ); 
    } 

    # get parameters 
    my %GetParam; 
    for my $ParamName (qw(MachineID Modele)) { 
        $GetParam{$ParamName} = $Self->{ParamObject}->GetParam( Param => $ParamName ); 
    } 

    # set default machine id 
    $GetParam{MachineID} ||= 0; 

    # ------------------------------------------------------------ # 
    # add 
    # ------------------------------------------------------------ # 
    if ( $Self->{Subaction} eq 'Add' ) { 

        # header 
        my $Output = $Self->{LayoutObject}->Header(); 
        $Output .= $Self->{LayoutObject}->NavigationBar(); 

        # HTML output 
        $Self->_Edit( 
            Action => 'Add', 
            %GetParam, 
        ); 
        $Output .= $Self->{LayoutObject}->Output( 
            TemplateFile => 'AddMachines', 
            Data         => \%Param, 
        ); 

        # footer 
        $Output .= $Self->{LayoutObject}->Footer(); 

        return $Output; 
    } 

    # ------------------------------------------------------------ # 
    # add action 
    # ------------------------------------------------------------ # 
    elsif ( $Self->{Subaction} eq 'AddAction' ) { 

        # challenge token check for write action 
        $Self->{LayoutObject}->ChallengeTokenCheck(); 

        # header 
        my $Output = $Self->{LayoutObject}->Header(); 
        $Output .= $Self->{LayoutObject}->NavigationBar(); 

        # check required parameters 
        my %Error; 
        for my $ParamName (qw(MachineID Modele)) { 

            # if required field is not given 
            if ( !$GetParam{$ParamName} ) { 

                # add server error string for machine modele field 
                if ( $ParamName eq 'Modele' ) { 
                    $Error{NameServerErrorMessage} = 'A machine should have a model!'; 
                } 
            } 
        } 

        # send server error if any required parameters are missing 
        if (%Error) { 

            # HTML output 
            $Self->_Edit( 
                Action => 'Add', 
                %GetParam, 
                %Error, 
            ); 
            $Output .= $Self->{LayoutObject}->Output( 
                TemplateFile => 'AddMachines', 
                Data         => \%Param, 
            ); 

            # footer 
            $Output .= $Self->{LayoutObject}->Footer(); 

            return $Output; 
        } 

        # add new machine
        my $MachineID = $Self->{MachinesObject}->MachinesAdd( 
            %GetParam, 
            UserID => $Self->{UserID}, 
        ); 

        # check error 
        if ( !$MachineID ) { 
            return $Self->{LayoutObject}->ErrorScreen(); 
        } 

        # show notification 
        $Output .= $Self->{LayoutObject}->Notify( Info => 'Machine added!' ); 

        # show overview 
        $Self->_Overview(); 
        $Output .= $Self->{LayoutObject}->Output( 
            TemplateFile => 'AddMachines', 
            Data         => \%Param, 
        ); 

        # footer 
        $Output .= $Self->{LayoutObject}->Footer(); 

        return $Output; 
    } 
} 
1;
is this correct ?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

I'm willing to support but not to quality check your code :)
Thus:

What is working - and what isn't ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Add Module

Post by jojo »

Also, see my questions above. What is the scope of your module?
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

RStraub wrote:I'm willing to support but not to quality check your code :)
you're right :D
RStraub wrote:What is working - and what isn't ?
i don't know what's wrong, Is there any compiler or a tool to debug if something's wrong ? synthax etc...
When i click in the NavBar "Add Machine"
add machine.png
Here's what i get
error.png
You do not have the required permissions to view the files attached to this post.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

Watch the apache log while you try to access that page. It will tell you what's wrong.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

jojo wrote:Also, see my questions above. What is the scope of your module?
i want to create another module "Machine" to
-Add machines in this module, just like customers or agents
-Search how many ticket has been opened for a specific MachineID
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

RStraub wrote:Watch the apache log while you try to access that page. It will tell you what's wrong.
/var/log/apache2/error.log here ?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Add Module

Post by RStraub »

Yes. I'd recommend doing a:

Code: Select all

tail -f /var/log/apache2/error.log
and while you tail it, access the page.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Add Module

Post by jojo »

A dynamic field will also give you the needed report...
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
Smiith
Znuny newbie
Posts: 19
Joined: 22 Jul 2015, 10:49
Znuny Version: OTRS 4
Real Name: Muhammad Hassanine Haddad
Company: CIMEF

Re: Add Module

Post by Smiith »

jojo wrote:A dynamic field will also give you the needed report...
really ? can you tell me how please ?
Post Reply