0

The problem is about OTRS customers. I can't use an external customer backend, so I want to update the customer DB via CSV files. I already wrote a script to add new Customers via otrs.AddCustomerUser.pl.

But how can I mass disable old customers via a script?

Michael
  • 345
  • 6
  • 19

1 Answers1

1

I created a script based in otrs.AddCustomerUser.pl to invalidate customer user:

otrs.DisableCustomerUser.pl:

#!/usr/bin/perl

use strict;
use warnings;

use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . '/Kernel/cpan-lib';
use lib dirname($RealBin) . '/Custom';

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Time;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::CustomerUser;

# create common objects
my %CommonObject;
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject}
    = Kernel::System::Log->new( %CommonObject, LogPrefix => 'OTRS-otrs.DisableCustomerUser.pl' );
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject}   = Kernel::System::DB->new(%CommonObject);
$CommonObject{UserObject} = Kernel::System::CustomerUser->new(%CommonObject);

my %Options;
use Getopt::Std;
getopt( 'c', \%Options );
unless ( $ARGV[0] ) {
    print
        "$FindBin::Script [-c CustomerID] username\n";
    print "\n";
    exit;
}

my %Param;

$Param{Source} = 'CustomerUser';
$Param{UserLogin} = defined $Options{c} ? $Options{c} : $ARGV[0];

my %User = $CommonObject{UserObject}->CustomerUserDataGet( User => $Param{UserLogin});

if ( !%User ) {
    print "No such user '$Param{UserLogin}'!\n";
    exit(1);
}

my $Success = $CommonObject{UserObject}->CustomerUserUpdate(
    Source => 'CustomerUser',
    ID              => $User{UserCustomerID},
    UserCustomerID  => $User{UserCustomerID},
    UserLogin       => $User{UserCustomerID},
    UserFirstname   => $User{UserFirstname},
    UserLastname    => $User{UserLastname},
    UserEmail       => $User{UserEmail},
    ValidID         => 2,
    UserID          => 1,
);

if($Success eq 1){
    print "Set customer user $User{UserCustomerID} to invalid.\n";
}

exit(0);

To invoke:

# otrs.DisableCustomerUser.pl [-c CustomerID] username
Federico Sierra
  • 3,589
  • 1
  • 20
  • 26
  • I tried to change valid_id directly in PostgreSQL database but this didn't work as expected: the front end still showed "valid". Your solution works great! – Michael Nov 04 '14 at 08:08
  • Yes, OTRS cache user data, for that is necessary update this information, CustomerUserUpdate function internally generates a event for flush the cache. – Federico Sierra Nov 04 '14 at 11:36