Skip to content

Commit

Permalink
Merge pull request #638 from RotherOSS/issue-#630-check_dbd_modules
Browse files Browse the repository at this point in the history
Issue #630 check dbd modules
  • Loading branch information
bschmalhofer committed Nov 12, 2020
2 parents ed2e97b + d33bb8a commit 7f7141d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
10 changes: 7 additions & 3 deletions Kernel/System/Main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -108,6 +111,7 @@ sub Require {
return;
}

# indicate that the module could be loaded
return 1;
}

Expand Down
66 changes: 61 additions & 5 deletions Kernel/System/MigrateFromOTRS/CloneDB/Driver/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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<DBD::*> 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<Message>, I<Comment>, and I<Successful>.
Expand All @@ -93,7 +111,7 @@ The returned value is a hash ref with the fields I<Message>, I<Comment>, and I<S
=cut

sub SanityChecks {
my $Self = shift;
my $Self = shift;
my %Param = @_;

my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
Expand All @@ -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();
Expand Down

0 comments on commit 7f7141d

Please sign in to comment.