Skip to content

Commit

Permalink
Issue #255: rename DBConnect() to DBConnectAsRoot()
Browse files Browse the repository at this point in the history
Trying to reduce the confusion
  • Loading branch information
bschmalhofer committed Aug 13, 2020
1 parent 0be28c8 commit ca65815
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions bin/docker/quick_setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ sub Main {
{
# in the Docker use case we can safely assume tha we are dealing with MySQL
my ( $Success, $Message ) = CheckDBRequirements(
DBUser => 'root',
DBPassword => $DBPassword,
DBName => $DBName,
DBName => $DBName, # for checking that the database does not exist yet
);

say $Message if defined $Message;
Expand All @@ -129,10 +128,9 @@ sub Main {
}

{
my ( $Success, $Message ) = DBCreateUser(
DBUser => 'root',
DBPassword => $DBPassword,
my ( $Success, $Message ) = DBCreateUserAndDatabase(
DBName => $DBName,
DBPassword => $DBPassword,
OTOBODBUser => $OTOBODBUser,
OTOBODBPassword => $OTOBODBPassword,
);
Expand All @@ -150,8 +148,6 @@ sub Main {
},
);

my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

# create the XML-Schema, do the initial inserts, add constraints
{
my $Home = $ConfigObject->Get('Home');
Expand Down Expand Up @@ -273,43 +269,47 @@ sub CheckSystemRequirements {
return 1, 'all system requirements are met';
}

sub DBConnect {
sub DBConnectAsRoot {
my %Param = @_;

# check the params
for my $Key ( grep { ! $Param{$_} } qw(DBUser DBPassword ) ) {
for my $Key ( grep { ! $Param{$_} } qw(DBPassword ) ) {
my $SubName = (caller(0))[3];

return 0, "$SubName: the parameter '$Key' is required";
}

my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

# verify that some expected settings are available
KEY:
for my $Key ( qw(Database DatabaseUser DatabasePw DatabaseDSN DatabaseHost) ) {

next KEY if $ConfigObject->Get($Key);

return 0, qq{setting '$Key' is not configured};
}

# verify that the connection to the DB is possible, password was passed on command line
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $DatabaseHost = $ConfigObject->Get('DatabaseHost');
my $DSN = "DBI:mysql:mysql;host=$DatabaseHost;";
my $DSN = "DBI:mysql:database=mysql;host=$DatabaseHost;";

my $DBHandle = DBI->connect($DSN, $Param{DBUser}, $Param{DBPassword});
warn "DSN: '$DSN'";
warn "Password: '$Param{DBPassword}'";
my $DBHandle = DBI->connect($DSN, 'root', $Param{DBPassword});
if ( ! $DBHandle ) {
return 0, $DBI::errstr;
}

return $DBHandle;
return $DBHandle, "connected to '$DSN' as root";
}

sub CheckDBRequirements {
my %Param = @_;

my ( $DBHandle, $Message ) = DBConnect( %Param );
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

# verify that some expected settings are available
KEY:
for my $Key ( qw(Database DatabaseUser DatabasePw DatabaseDSN DatabaseHost) ) {

next KEY if $ConfigObject->Get($Key);

return 0, qq{setting '$Key' is not configured};
}

# try to connect as root to mysql
my ( $DBHandle, $Message ) = DBConnectAsRoot( %Param );

if ( ! $DBHandle ) {
return 0, $Message;
Expand All @@ -333,17 +333,17 @@ sub CheckDBRequirements {
}

# specific for MySQL
sub DBCreateUser {
sub DBCreateUserAndDatabase {
my %Param = @_;

# check the params
for my $Key ( grep { ! $Param{$_} } qw(DBUser DBPassword DBName OTOBODBUser OTOBODBPassword) ) {
for my $Key ( grep { ! $Param{$_} } qw(DBPassword DBName OTOBODBUser OTOBODBPassword) ) {
my $SubName = (caller(0))[3];

return 0, "$SubName: the parameter '$Key' is required";
}

my ( $DBHandle, $Message ) = DBConnect( %Param );
my ( $DBHandle, $Message ) = DBConnectAsRoot( %Param );

if ( ! $DBHandle ) {
return 0, $Message;
Expand Down

0 comments on commit ca65815

Please sign in to comment.