diff --git a/Kernel/System/Main.pm b/Kernel/System/Main.pm index 6c285196a1..f0acebf81f 100644 --- a/Kernel/System/Main.pm +++ b/Kernel/System/Main.pm @@ -78,19 +78,22 @@ require/load a module =cut sub Require { - my ( $Self, $Module, %Param ) = @_; + my $Self = shift; + my ( $Module, %Param ) = @_; + # check required params if ( !$Module ) { $Kernel::OM->Get('Kernel::System::Log')->Log( Priority => 'error', Message => 'Need module!', ); + return; } eval { - my $FileName = $Module =~ s{::}{/}smxgr; - require $FileName . '.pm'; + my $FileName = "$Module.pm" =~ s{::}{/}smxgr; + require $FileName; }; # Handle errors. @@ -108,6 +111,7 @@ sub Require { return; } + # indicate that the module could be loaded return 1; } diff --git a/Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm b/Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm index 75d9d74c1e..a2896deb83 100644 --- a/Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm +++ b/Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm @@ -79,8 +79,26 @@ sub new { =head2 SanityChecks -A single sanity check. -Check whether the relevant tables exist in the source database. +check several sanity conditions of the source database. + +=over 4 + +=item check whether the passed database object is supported + +=item check whether the required M module can be loaded + +=item check whether a connection is possible + +=item check whether there are tables + +=item check whether row count of the tables can be determined, empty tables are OK + +=back + + my $SanityCheck = $CloneDBBackendObject->SanityChecks( + OTRSDBObject => $SourceDBObject, + Message => $Message, + ); The returned value is a hash ref with the fields I, I, and I. @@ -93,7 +111,7 @@ The returned value is a hash ref with the fields I, I, and IGet('Kernel::Language'); @@ -120,8 +138,46 @@ sub SanityChecks { # get setup my %TableIsSkipped = $Kernel::OM->Get('Kernel::System::MigrateFromOTRS::Base')->DBSkipTables()->%*; - # get OTOBO DB object - my $TargetDBObject = $Kernel::OM->Get('Kernel::System::DB'); + # check whether the source database type is supported and whether the DBD module can be loaded + my %DBDModule = ( + mysql => 'DBD::mysql', + postgresql => 'DBD::Pg', + oracle => 'DBD::Oracle', + ); + + my $DBType = $SourceDBObject->GetDatabaseFunction( 'Type' ) // ''; + my $Module = $DBDModule{$DBType}; + if ( ! $Module ) { + my $Comment = "The source database type $DBType is not supported"; + + $Kernel::OM->Get('Kernel::System::Log')->Log( + Priority => 'error', + Message => "$Param{Message} $Comment", + ); + + return { + Message => $Param{Message}, + Comment => $Comment, + Successful => 0, + }; + } + + my $MainObject = $Kernel::OM->Get('Kernel::System::Main'); + my $ModuleIsInstalled = $MainObject->Require( $Module ); + if ( ! $ModuleIsInstalled ) { + my $Comment = "The module $Module is not installed."; + + $Kernel::OM->Get('Kernel::System::Log')->Log( + Priority => 'error', + Message => "$Param{Message} $Comment", + ); + + return { + Message => $Param{Message}, + Comment => $Comment, + Successful => 0, + }; + } # check connection my $DbHandle = $SourceDBObject->Connect();