This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::CustomerUser::Event::DynamicFieldObjectNameUpdate;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::DynamicField',
);
sub new {
my ( $Type, %Param ) = @_;
# Allocate new hash for object.
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw( Data Event Config UserID )) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!"
);
return;
}
}
for my $Needed (qw( UserLogin NewData OldData )) {
if ( !$Param{Data}->{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed in Data!"
);
return;
}
}
# If the user login has been changed, update dynamic field object name for given name and type.
if ( lc $Param{Data}->{OldData}->{UserLogin} ne lc $Param{Data}->{NewData}->{UserLogin} ) {
my $Success = $Kernel::OM->Get('Kernel::System::DynamicField')->ObjectMappingNameChange(
OldObjectName => $Param{Data}->{OldData}->{UserLogin},
NewObjectName => $Param{Data}->{NewData}->{UserLogin},
ObjectType => 'CustomerUser',
);
if ( !$Success ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message =>
"Unable to change dynamic field object mapping name from $Param{Data}->{OldData}->{UserLogin} to $Param{Data}->{NewData}->{UserLogin} for type CustomerUser!",
);
return;
}
}
return 1;
}
1;

View File

@@ -0,0 +1,66 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::CustomerUser::Event::SearchProfileUpdate;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::SearchProfile',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw( Data Event Config UserID )) {
if ( !$Param{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
for (qw( UserLogin NewData OldData )) {
if ( !$Param{Data}->{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_ in Data!"
);
return;
}
}
# only update CustomerUser search profiles if fields have really changed
if ( lc $Param{Data}->{OldData}->{UserLogin} ne lc $Param{Data}->{NewData}->{UserLogin} ) {
# update searchprofiles
$Kernel::OM->Get('Kernel::System::SearchProfile')->SearchProfileUpdateUserLogin(
Base => 'CustomerTicketSearch',
UserLogin => $Param{Data}->{OldData}->{UserLogin},
NewUserLogin => $Param{Data}->{NewData}->{UserLogin},
);
}
return 1;
}
1;

View File

@@ -0,0 +1,87 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::CustomerUser::Event::ServiceMemberUpdate;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::Service',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw( Data Event Config UserID )) {
if ( !$Param{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
for (qw( UserLogin NewData OldData )) {
if ( !$Param{Data}->{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_ in Data!"
);
return;
}
}
# only update CustomerUser <> Service if fields have really changed
if ( $Param{Data}->{OldData}->{UserLogin} ne $Param{Data}->{NewData}->{UserLogin} ) {
# get service object
my $ServiceObject = $Kernel::OM->Get('Kernel::System::Service');
my @Services = $ServiceObject->CustomerUserServiceMemberList(
CustomerUserLogin => $Param{Data}->{OldData}->{UserLogin},
Result => 'ARRAY',
DefaultServices => 0,
);
for my $ServiceID (@Services) {
# first remove old customer id as service member
$ServiceObject->CustomerUserServiceMemberAdd(
CustomerUserLogin => $Param{Data}->{OldData}->{UserLogin},
ServiceID => $ServiceID,
Active => 0,
UserID => 1,
);
# add new customer id as service member
$ServiceObject->CustomerUserServiceMemberAdd(
CustomerUserLogin => $Param{Data}->{NewData}->{UserLogin},
ServiceID => $ServiceID,
Active => 1,
UserID => 1,
);
}
}
return 1;
}
1;

View File

@@ -0,0 +1,86 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::CustomerUser::Event::TicketUpdate;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::Ticket',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw( Data Event Config UserID )) {
if ( !$Param{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
for (qw( UserLogin NewData OldData )) {
if ( !$Param{Data}->{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_ in Data!"
);
return;
}
}
# only update if fields have really changed
if (
$Param{Data}->{OldData}->{UserCustomerID} ne $Param{Data}->{NewData}->{UserCustomerID}
|| $Param{Data}->{OldData}->{UserLogin} ne $Param{Data}->{NewData}->{UserLogin}
)
{
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# perform search
my @Tickets = $TicketObject->TicketSearch(
Result => 'ARRAY',
Limit => 100_000,
CustomerUserLoginRaw => $Param{Data}->{OldData}->{UserLogin},
CustomerIDRaw => $Param{Data}->{OldData}->{UserCustomerID},
ArchiveFlags => [ 'y', 'n' ],
UserID => 1,
);
# update the customer ID and login of tickets
for my $TicketID (@Tickets) {
$TicketObject->TicketCustomerSet(
No => $Param{Data}->{NewData}->{UserCustomerID},
User => $Param{Data}->{NewData}->{UserLogin},
TicketID => $TicketID,
UserID => $Param{UserID},
);
}
}
return 1;
}
1;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,215 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::CustomerUser::Preferences::DB;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Cache',
'Kernel::System::DB',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
$Self->{CacheType} = 'CustomerUserPreferencesDB';
$Self->{CacheTTL} = 60 * 60 * 24 * 20;
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# preferences table data
$Self->{PreferencesTable} = $ConfigObject->Get('CustomerPreferences')->{Params}->{Table}
|| 'customer_preferences';
$Self->{PreferencesTableKey} = $ConfigObject->Get('CustomerPreferences')->{Params}->{TableKey}
|| 'preferences_key';
$Self->{PreferencesTableValue} = $ConfigObject->Get('CustomerPreferences')->{Params}->{TableValue}
|| 'preferences_value';
$Self->{PreferencesTableUserID} = $ConfigObject->Get('CustomerPreferences')->{Params}->{TableUserID}
|| 'user_id';
# set lower if database is case sensitive
$Self->{Lower} = '';
if ( $Kernel::OM->Get('Kernel::System::DB')->GetDatabaseFunction('CaseSensitive') ) {
$Self->{Lower} = 'LOWER';
}
# create cache prefix
$Self->{CachePrefix} = 'CustomerUserPreferencesDB'
. $Self->{PreferencesTable}
. $Self->{PreferencesTableKey}
. $Self->{PreferencesTableValue}
. $Self->{PreferencesTableUserID};
return $Self;
}
sub SetPreferences {
my ( $Self, %Param ) = @_;
return if !$Param{UserID};
return if !$Param{Key};
my $Value = defined $Param{Value} ? $Param{Value} : '';
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
# delete old data
return if !$DBObject->Do(
SQL => "
DELETE FROM $Self->{PreferencesTable}
WHERE $Self->{PreferencesTableUserID} = ?
AND $Self->{PreferencesTableKey} = ?",
Bind => [ \$Param{UserID}, \$Param{Key} ],
);
# insert new data
return if !$DBObject->Do(
SQL => "
INSERT INTO $Self->{PreferencesTable}
($Self->{PreferencesTableUserID}, $Self->{PreferencesTableKey}, $Self->{PreferencesTableValue})
VALUES (?, ?, ?)",
Bind => [ \$Param{UserID}, \$Param{Key}, \$Value ],
);
# delete cache
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
Type => $Self->{CacheType},
Key => $Self->{CachePrefix} . $Param{UserID},
);
return 1;
}
# =item RenamePreferences()
#
# rename the old userid with the new userid in the preferences
#
# returns 1 if success or undef otherwise
#
# my $Success = $PreferencesObject->RenamePreferences(
# NewUserID => 2,
# OldUserID => 1,
# );
#
# =cut
sub RenamePreferences {
my ( $Self, %Param ) = @_;
return if !$Param{NewUserID};
return if !$Param{OldUserID};
# update the preferences
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
SQL => "
UPDATE $Self->{PreferencesTable}
SET $Self->{PreferencesTableUserID} = ?
WHERE $Self->{PreferencesTableUserID} = ?",
Bind => [ \$Param{NewUserID}, \$Param{OldUserID}, ],
);
# delete cache
$Kernel::OM->Get('Kernel::System::Cache')->Delete(
Type => $Self->{CacheType},
Key => $Self->{CachePrefix} . $Param{OldUserID},
);
return 1;
}
sub GetPreferences {
my ( $Self, %Param ) = @_;
return if !$Param{UserID};
# read cache
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
Type => $Self->{CacheType},
Key => $Self->{CachePrefix} . $Param{UserID},
);
return %{$Cache} if $Cache;
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
# get preferences
return if !$DBObject->Prepare(
SQL => "
SELECT $Self->{PreferencesTableKey}, $Self->{PreferencesTableValue}
FROM $Self->{PreferencesTable}
WHERE $Self->{PreferencesTableUserID} = ?",
Bind => [ \$Param{UserID} ],
);
# fetch the result
my %Data;
while ( my @Row = $DBObject->FetchrowArray() ) {
$Data{ $Row[0] } = $Row[1];
}
# set cache
$Kernel::OM->Get('Kernel::System::Cache')->Set(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => $Self->{CachePrefix} . $Param{UserID},
Value => \%Data,
);
return %Data;
}
sub SearchPreferences {
my ( $Self, %Param ) = @_;
my $Key = $Param{Key} || '';
my $Value = $Param{Value} || '';
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
my $Lower = '';
if ( $DBObject->GetDatabaseFunction('CaseSensitive') ) {
$Lower = 'LOWER';
}
my $SQL = "
SELECT $Self->{PreferencesTableUserID}, $Self->{PreferencesTableValue}
FROM $Self->{PreferencesTable}
WHERE $Self->{PreferencesTableKey} = ?";
my @Bind = ( \$Key );
if ($Value) {
$SQL .= " AND $Lower($Self->{PreferencesTableValue}) LIKE $Lower(?)";
push @Bind, \$Value;
}
# get preferences
return if !$DBObject->Prepare(
SQL => $SQL,
Bind => \@Bind,
);
# fetch the result
my %UserID;
while ( my @Row = $DBObject->FetchrowArray() ) {
$UserID{ $Row[0] } = $Row[1];
}
return %UserID;
}
1;