Skip to content

Instantly share code, notes, and snippets.

@mbeijen
Created November 8, 2013 11:23
Show Gist options
  • Select an option

  • Save mbeijen/7369675 to your computer and use it in GitHub Desktop.

Select an option

Save mbeijen/7369675 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# --
# bin/otrs.CheckCustomerDataSource.pl - Check customer data sources
# Copyright (C) 2001-2013 OTRS AG, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# 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 Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
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.CheckCustomerDataSource.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 %CustomerBackends = $CommonObject{UserObject}->CustomerSourceList();
for my $Backend ( sort keys %CustomerBackends ) {
my @Errors;
print "BACKEND $Backend: '$CustomerBackends{$Backend}'\n";
print "====================================================\n\n";
my $Config = $CommonObject{ConfigObject}->Get($Backend);
print "---------------------|-----------------|-----------------|----------|------|\n";
print "OTRS Variable | Display Name | Internal | Required | Type |\n";
print "---------------------|-----------------|-----------------|----------|------|\n";
my %Fields;
for my $Mapping ( @{ $Config->{Map} } ) {
my $Required = $Mapping->[4] ? 'Yes' : 'No';
# var, frontend, storage, shown (1=always,2=lite), required, storage-type, http-link, readonly, http-link-target, link class(es)
printf "%-20s | %-15s | %-15s | %6s | %-4s |\n",
$Mapping->[0], $Mapping->[1], $Mapping->[2], $Required, $Mapping->[5];
$Fields{ $Mapping->[2] } = 1;
}
print "---------------------|-----------------|-----------------|----------|------|\n\n";
printf "%35s : %-20s\n", 'Type', $Config->{Module};
# check if fields are existing in mapping
ITEM:
for my $Item (qw(CustomerKey CustomerID CustomerValid)) {
if ( !$Config->{$Item} ) {
push @Errors, "$Item is not defined in configuration";
next ITEM;
}
printf "%35s : %-20s\n", $Item, $Config->{$Item};
if ( !$Fields{ $Config->{$Item} } ) {
push @Errors, "Field '$Config->{$Item}' in config under $Item but not in field map.";
}
}
ARRAYITEM:
for my $Item (
qw(CustomerUserNameFields CustomerUserPostMasterSearchFields CustomerUserSearchFields CustomerUserListFields)
)
{
if ( ref $Config->{$Item} ne 'ARRAY' ) {
push @Errors, "$Item is not defined in configuration";
next ARRAYITEM;
}
printf "%35s : ", $Item;
print join( ", ", @{ $Config->{$Item} } ), "\n";
# test if all fields exist
FIELD:
for my $Field ( @{ $Config->{$Item} } ) {
next FIELD if $Fields{$Field};
push @Errors, "Field '$Field' in config under $Item but not in field map.";
}
}
if (@Errors) {
print "\nWARNING: these errors were found in configuration for data source '$Backend':\n\n";
print join( "\n", @Errors );
print "\n\n\n";
}
else {
print "\nNo errors found in configuration for data source '$Backend'.\n\n\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment