zum importieren von Kunden benutze ich das Script "synccustomeruser_csv2otrs.pl" welches wie folgt aussieht:
Code: Select all
#!/usr/bin/perl -w
# --
# synccustomer_csv2otrs.pl - sync csv user list or otrs
# Copyright (C) 2001-2008 xxx, http://otrs.org/
# --
# $Id: synccustomer_csv2otrs.pl,v 1.10 2008/06/09 14:52:11 tr Exp $
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# --
# config options / csv file - column 0-...
my %Fields = ();
$Fields{login} = 0;
$Fields{email} = 0;
$Fields{customer_id} = 2;
$Fields{pw} = 3;
$Fields{salutation} = 4;
$Fields{firstname} = 5;
$Fields{lastname} = 6;
$Fields{phone} = 7;
$Fields{fax} = 8;
$Fields{street} = 9;
$Fields{zip} = 10;
$Fields{city} = 11;
$Fields{comment} = 12;
$Fields{loginnew} = 0;
$Fields{gueltig} = 14;
# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . "/Kernel/cpan-lib";
use strict;
use warnings;
use Getopt::Std;
use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::Time;
use Kernel::System::DB;
#use Kernel::System::User;
use Kernel::System::CustomerUser;
# common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'test.pl',
%CommonObject
);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
#$CommonObject{UserObject} = Kernel::System::User->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{CustomerUserObject} = Kernel::System::CustomerUser->new(%CommonObject);
# get options
my %Opts = ();
getopt( 's', \%Opts );
my $End = "\n";
if ( !$Opts{s} ) {
die "Need -s <CSV_FILE>\n";
}
my $Lang = $CommonObject{ConfigObject}->Get('DefaultLanguage') || 'de';
# read csv file
open (IN, "< $Opts{'s'}") || die "Can't read $Opts{'s'}: $!";
while( <IN>) {
my $LineStrg = $_;
$LineStrg =~ s/\"//g;
my @Line = split(/;/, $LineStrg);
# check if user extsis
#my %UserData = $CommonObject{UserObject}->GetUserData( User => $Line[ $Fields{UserLogin} ] );
my %CustomerUserData = $CommonObject{CustomerUserObject}->CustomerUserDataGet(User => $Line[$Fields{login}]);
# if there is no pw in the csv list, gererate one
if( !$Line[$Fields{pw}]) {
$Line[$Fields{pw}] = $CommonObject{CustomerUserObject}->GenerateRandomPassword();
}
# update user
if( %CustomerUserData) {
print "Updating customer user '$Line[$Fields{login}]' with password '$Line[$Fields{pw}]'\n";
$CommonObject{CustomerUserObject}->CustomerUserUpdate(
Source => $Line[$Fields{customer_id}] || '', # CustomerUser source config
ID => $Line[$Fields{login}], # current user login
UserLogin => $Line[$Fields{loginnew}], # new user login
UserFirstname => $Line[$Fields{firstname}],
UserLastname => $Line[$Fields{lastname}],
UserPhone => $Line[$Fields{phone}] || '',
UserFax => $Line[$Fields{fax}] || '',
UserStreet => $Line[$Fields{street}] || '',
UserZIP => $Line[$Fields{zip}] || '',
UserCity => $Line[$Fields{city}] || '',
UserPassword => $Line[$Fields{pw}], # not required
UserEmail => $Line[$Fields{email}],
UserCustomerID => $Line[$Fields{customer_id}] || '',
UserSalutation => $Line[$Fields{salutation}] || '',
UserComment => $Line[$Fields{comment}] || '',
ValidID => $Line[$Fields{gueltig}],
UserID => 123,
);
}
# add user
else {
print "Add customer_user '$Line[$Fields{login}]' ($Line[$Fields{firstname}],$Line[$Fields{lastname}]) with password '$Line[$Fields{pw}]'\n";
$CustomerUserData{UserID} = $CommonObject{CustomerUserObject}->CustomerUserAdd(
UserSalutation => $Line[$Fields{salutation}] || '',
UserFirstname => $Line[$Fields{firstname}],
UserLastname => $Line[$Fields{lastname}],
UserPhone => $Line[$Fields{phone}] || '',
UserFax => $Line[$Fields{fax}] || '',
UserStreet => $Line[$Fields{street}] || '',
UserZIP => $Line[$Fields{zip}] || '',
UserCity => $Line[$Fields{city}] || '',
UserLogin => $Line[$Fields{loginnew}],
UserPassword => $Line[$Fields{pw}],
UserEmail => $Line[$Fields{email}],
CustomerID => $Line[$Fields{customer_id}] || '',
UserCustomerID => $Line[$Fields{customer_id}] || '',
UserComment => $Line[$Fields{comment}] || '',
ValidID => $Line[$Fields{gueltig}],
UserID => 1,
);
}
}
close( IN);
Die Daten werden auch in die Datenbank geschrieben und kann sie auch in OTRS sehen. Allerdings bekomme ich die PLZ nicht angezeigt in den Kundeninfos. Da ich aber Google Maps aktiviert habe kann ich mir die Adresse anzeigen lassen und dort erscheint aber die PLZ korrekt. Also ist sie in der Datenbank hinterlegt nur wird sie mir nicht angezeigt. Auch in der Anzeige vom Kunden bekomme ich keine PLZ angezeigt. Wenn ich allerdings die PLZ von Hand ausfülle und ich die Kundendaten dann aktualisiere erscheint die PLZ und wird dann auch später in den Kundendetails beim schreiben eines Tickets angezeigt.info@domain.com;info@domain.com;12345678;12345;Herr;Vorname;Nachname;0000-000000Telefon;0000-000000Fax;Straße 10;PLZ;Ort;Kommentar;info@domain.com;1
Kennt jemand dieses Problem und kann mir einen Tip geben?
Gruß
Christian