Adding custom changes to User.pm

Moderator: crythias

duncan9562
OTRS newbie
Posts: 9
Joined: 23 Feb 2016, 14:51
OTRS Version?: 5.0.14
Real Name: Duncan Mountford

Adding custom changes to User.pm

Postby duncan9562 » 15 Mar 2017, 21:11

Hey guys,

To start, I am running OTRS v5.0.16.

I need to make some changes to User.pm, however have been advised by OTRS support that making changes to any such file will result in them not supporting our installation which is not good news.

We have some custom config in "/opt/otrs/Kernel/Config/Files/" which work well however wasn't set up by myself.

What I am looking to do is add the following...

Code: Select all

    $Self->SetPreferences(
        UserID => $Param{UserTelephone},
        Key    => 'UserTelephone',
        Value  => $Param{UserTelephone}
);

...into the following sections to sync additional information to the Preferences for my agents.

Code: Select all

sub UserAdd {

and

Code: Select all

sub UserUpdate {


Can anyone guide me on how to create a config file as I have absolutely no idea where to start!!

Much appreciated and kind regards,
Duncan.

RStraub
OTRS guru
Posts: 1868
Joined: 13 Mar 2014, 09:16
OTRS Version?: 5.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Postby RStraub » 16 Mar 2017, 12:05

Right, so the *usual* way to customize is:

- Take the file you want to edit
- copy it (containing the same path-structure) to ~otrs/Custom/...
- edit it

If you have large files and only need to edit a specific function, try to overload that:
viewtopic.php?f=64&t=34175

Does this help you ?
Currently using: OTRS 5.0.14 -- MariaDB -- Ubuntu 16 LTS

duncan9562
OTRS newbie
Posts: 9
Joined: 23 Feb 2016, 14:51
OTRS Version?: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Postby duncan9562 » 20 Mar 2017, 17:55

Thanks for the quick reply!

So, I copied /opt/otrs/Kernel/System/User.pm to /opt/otrs/Kernel/Config/Files/CustomUser.pm which is fine.

I have made the changes I need to in /opt/otrs/Kernel/Config/Files/CustomUser.pm, however I get a lot of "Subroutine redefined at xxxxxx" in the apache error log.

Do I need to comment out the old User.pm in /opt/otrs/Kernel/System/, or move it out the way?

Thanks again for your help....

RStraub
OTRS guru
Posts: 1868
Joined: 13 Mar 2014, 09:16
OTRS Version?: 5.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Postby RStraub » 20 Mar 2017, 18:22

You could encapsulate your whole module into a "no-redefine warnings" scope. So from:

Code: Select all

package YourPackageName;

use strict;
use warnings;

[... lots of module code ...]
1;


you could write:

Code: Select all

package YourPackageName;

use strict;
use warnings;

# disable redefine warnings in this scope
{
no warnings 'redefine';

[... lots of module code ...]

# close the "no warnings" scope
}


1;
Currently using: OTRS 5.0.14 -- MariaDB -- Ubuntu 16 LTS

alexus
OTRS superhero
Posts: 236
Joined: 20 Sep 2010, 16:54
OTRS Version?: ITSM 4.0.11
Real Name: Alexey Yusov
Company: Radiant System
Location: Prague
Contact:

Re: Adding custom changes to User.pm

Postby alexus » 20 Mar 2017, 23:01

If you need add some fields to agent only, try this - viewtopic.php?t=19936
Alexey Yusov

Production: OTRS ITSM 5.0.14 on CentOS 7 x64 Linux with MySQL 5.7
Tested: OTRS ITSM 5.0.14
Radiant System OTRS Intergrator
Stay tuned on our Facebook
Get OTRS Professional Services - Consulting, Implementation, Training, Development, Support!

User avatar
nedmaj
OTRS expert
Posts: 74
Joined: 26 Nov 2014, 20:34
OTRS Version?: 4.0.15 and 5.0.15
Real Name: Samuel Casimiro
Company: CD

Re: Adding custom changes to User.pm

Postby nedmaj » 21 Mar 2017, 03:25

duncan9562 wrote:Thanks for the quick reply!

So, I copied /opt/otrs/Kernel/System/User.pm to /opt/otrs/Kernel/Config/Files/CustomUser.pm which is fine.

I have made the changes I need to in /opt/otrs/Kernel/Config/Files/CustomUser.pm, however I get a lot of "Subroutine redefined at xxxxxx" in the apache error log.

Do I need to comment out the old User.pm in /opt/otrs/Kernel/System/, or move it out the way?

Thanks again for your help....


Sorry, but that path and filename are not correct. Try /opt/otrs/Custom/Kernel/System/User.pm instead. Got it?
Samuel

OTRS 4.0.15 and 5.0.15
OTRS::ITSM 4.0.15 and 5.0.15
OS: CentOS 6.5
Database: Oracle 12.1
User database: LDAP (Active Directory)
Auth module: LDAP (Active Directory)
Mail server: Microsoft Exchange
Sendmail module: Sendmail (Postfix)
3rd party packages: Yes
SSL: Yes
Number of agents: 450
Number of customers: 20000
Number of CIs: 30000

duncan9562
OTRS newbie
Posts: 9
Joined: 23 Feb 2016, 14:51
OTRS Version?: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Postby duncan9562 » 22 Mar 2017, 16:54

RStraub wrote:You could encapsulate your whole module into a "no-redefine warnings" scope. So from:

Code: Select all

package YourPackageName;

use strict;
use warnings;

[... lots of module code ...]
1;


you could write:

Code: Select all

package YourPackageName;

use strict;
use warnings;

# disable redefine warnings in this scope
{
no warnings 'redefine';

[... lots of module code ...]

# close the "no warnings" scope
}


1;

RStraub, this worked like an absolute dream. Thank you very much for your help!

RStraub
OTRS guru
Posts: 1868
Joined: 13 Mar 2014, 09:16
OTRS Version?: 5.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Postby RStraub » 22 Mar 2017, 17:09

Glad it helped, you are very welcome :)
Currently using: OTRS 5.0.14 -- MariaDB -- Ubuntu 16 LTS

duncan9562
OTRS newbie
Posts: 9
Joined: 23 Feb 2016, 14:51
OTRS Version?: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Postby duncan9562 » 23 Mar 2017, 12:23

RStraub wrote:Glad it helped, you are very welcome :)


Spoke to soon :p

So, I have made the following changes in the custom User.pm file:-

Code: Select all

=item UserAdd()

to add new users

    my $UserID = $UserObject->UserAdd(
        UserFirstname => 'Huber',
        UserLastname  => 'Manfred',
        UserLogin     => 'mhuber',
        UserPw        => 'some-pass', # not required
        UserEmail     => 'email@example.com',
        UserMobile    => '1234567890', # not required
        UserMyFieldTelephone => '01234567890', # not required
        ValidID       => 1,
        ChangeUserID  => 123,
    );
.....
.....
    # set user telephone
    $Self->SetPreferences(
        UserID => $Param{UserID},
        Key    => 'UserMyFieldTelephone',
        Value  => $Param{UserMyFieldTelephone} || '',
    );
.....
.....
=item UserUpdate()

to update users

    $UserObject->UserUpdate(
        UserID        => 4321,
        UserFirstname => 'Huber',
        UserLastname  => 'Manfred',
        UserLogin     => 'mhuber',
        UserPw        => 'some-pass', # not required
        UserEmail     => 'email@example.com',
        UserMobile    => '1234567890', # not required
        UserMyFieldTelephone => '01234567890', # not required
        ValidID       => 1,
        ChangeUserID  => 123,
    );
.....
.....
    # set user telephone
    $Self->SetPreferences(
        UserID => $Param{UserID},
        Key    => 'UserMyFieldTelephone',
        Value  => $Param{UserMyFieldTelephone} || '',
    );
.....
.....


Also I have added the UserMyFieldTelephone field into UserSyncMap as follows:-

Code: Select all

    $Self->{'AuthSyncModule::LDAP::UserSyncMap'} = {
        # DB -> LDAP
        UserFirstname => 'givenName',
        UserLastname  => 'sn',
        UserEmail     => 'mail',
        UserMobile    => 'mobile',
        UserMyFieldTelephone => 'ipPhone',
    };


I have also created an additional field in Agent Preferences to show the UserMyFieldTelephone field in the Preferences section.

Everything syncs perfectly!!.......however, I am seeing the following come up in the apache error log:-

Code: Select all

[Thu Mar 23 09:30:36 2017] -e: Use of uninitialized value $SyncUser{"UserMyFieldTelephone"} in string eq at /opt/otrs//Kernel/System/Auth/Sync/LDAP.pm line 335.
[Thu Mar 23 09:30:36 2017] -e: Use of uninitialized value in string eq at /opt/otrs//Kernel/System/Auth/Sync/LDAP.pm line 335.
[Thu Mar 23 09:30:36 2017] -e: Use of uninitialized value $SyncUser{"UserMobile"} in string eq at /opt/otrs//Kernel/System/Auth/Sync/LDAP.pm line 335.
[Thu Mar 23 09:30:36 2017] -e: Use of uninitialized value in string eq at /opt/otrs//Kernel/System/Auth/Sync/LDAP.pm line 335.


We have a customer control panel that allows users to submit tickets which does involve quite a heavy integration with OTRS via the API. This error only appears when an API call is made, and if I comment out "UserMyFieldTelephone => 'ipPhone'," under UserSyncMap then the error goes away.

Is there anything I could have missed whilst doing this....?

Thank you in advance for your help...


Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests