Adding custom changes to User.pm

Moderator: crythias

Post Reply
duncan9562
Znuny newbie
Posts: 11
Joined: 23 Feb 2016, 14:51
Znuny Version: 5.0.14
Real Name: Duncan Mountford

Adding custom changes to User.pm

Post by duncan9562 »

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
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Post by RStraub »

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 6.0.14 -- MariaDB -- Ubuntu 16 LTS
duncan9562
Znuny newbie
Posts: 11
Joined: 23 Feb 2016, 14:51
Znuny Version: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Post by duncan9562 »

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
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Post by RStraub »

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 6.0.14 -- MariaDB -- Ubuntu 16 LTS
alexus
Znuny wizard
Posts: 380
Joined: 20 Sep 2010, 16:54
Znuny Version: OTRS 6 CE
Real Name: Alexey Yusov
Company: Radiant System Group s.r.o
Location: Prague
Contact:

Re: Adding custom changes to User.pm

Post by alexus »

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

Production: OTRS CE ITSM 6.0.28 on CentOS 7 + Apache 2.4 + MariaDB 10.4.13 + Radiant Customer Portal

Radiant System OTRS Intergrator
RS4OTRS marketplace
Stay tuned on our Facebook
((OTRS)) Community Edition - what next?
nedmaj
Znuny expert
Posts: 167
Joined: 26 Nov 2014, 20:34
Znuny Version: 6.3.4
Real Name: Samuel Casimiro
Company: Câmara dos Deputados
Contact:

Re: Adding custom changes to User.pm

Post by nedmaj »

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

Znuny 6.3.4 | OTRS 5.0.17
OS: Debian 11 | CentOS 6.5
Database: Postgres | Oracle 12.1
Number of agents: 450 | Number of customers: 20000 | Number of CIs: 30000
duncan9562
Znuny newbie
Posts: 11
Joined: 23 Feb 2016, 14:51
Znuny Version: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Post by duncan9562 »

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
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Adding custom changes to User.pm

Post by RStraub »

Glad it helped, you are very welcome :)
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
duncan9562
Znuny newbie
Posts: 11
Joined: 23 Feb 2016, 14:51
Znuny Version: 5.0.14
Real Name: Duncan Mountford

Re: Adding custom changes to User.pm

Post by duncan9562 »

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...
Post Reply