mirror of
https://github.com/octoleo/docker-joomla.git
synced 2024-11-17 09:15:09 +00:00
Adds pgsql compatibility #42
This commit is contained in:
parent
f03a7cf528
commit
84876534d1
@ -120,7 +120,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
|
||||
fi
|
||||
|
||||
# Ensure the MySQL Database is created
|
||||
php /makedb.php "$JOOMLA_DB_HOST" "$JOOMLA_DB_USER" "$JOOMLA_DB_PASSWORD" "$JOOMLA_DB_NAME"
|
||||
php /makedb.php "$JOOMLA_DB_HOST" "$JOOMLA_DB_USER" "$JOOMLA_DB_PASSWORD" "$JOOMLA_DB_NAME" "${JOOMLA_DB_TYPE:-mysqli}"
|
||||
|
||||
echo >&2 "========================================================================"
|
||||
echo >&2
|
||||
|
101
makedb.php
101
makedb.php
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Args: 0 => makedb.php, 1 => "$JOOMLA_DB_HOST", 2 => "$JOOMLA_DB_USER", 3 => "$JOOMLA_DB_PASSWORD", 4 => "$JOOMLA_DB_NAME"
|
||||
// Args: 0 => makedb.php, 1 => "$JOOMLA_DB_HOST", 2 => "$JOOMLA_DB_USER", 3 => "$JOOMLA_DB_PASSWORD", 4 => "$JOOMLA_DB_NAME", 5 => "$JOOMLA_DB_TYPE"
|
||||
$stderr = fopen('php://stderr', 'w');
|
||||
fwrite($stderr, "\nEnsuring Joomla database is present\n");
|
||||
|
||||
@ -10,40 +10,93 @@ if (strpos($argv[1], ':') !== false)
|
||||
else
|
||||
{
|
||||
$host = $argv[1];
|
||||
$port = 3306;
|
||||
$port = null;
|
||||
}
|
||||
|
||||
$maxTries = 10;
|
||||
$user = $argv[2];
|
||||
$password = $argv[3];
|
||||
$db = $argv[4];
|
||||
$dbType = strtolower($argv[5]);
|
||||
|
||||
// set original default behaviour for PHP 8.1 and higher
|
||||
// see https://www.php.net/manual/en/mysqli-driver.report-mode.php
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
do
|
||||
if ($dbType === 'mysqli')
|
||||
{
|
||||
$mysql = new mysqli($host, $argv[2], $argv[3], '', (int) $port);
|
||||
$port = $port ? (int)$port : 3306;
|
||||
$maxTries = 10;
|
||||
|
||||
if ($mysql->connect_error)
|
||||
{
|
||||
fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
|
||||
--$maxTries;
|
||||
// set original default behaviour for PHP 8.1 and higher
|
||||
// see https://www.php.net/manual/en/mysqli-driver.report-mode.php
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
do {
|
||||
$mysql = new mysqli($host, $user, $password, '', $port);
|
||||
|
||||
if ($maxTries <= 0)
|
||||
if ($mysql->connect_error)
|
||||
{
|
||||
fwrite($stderr, "\nMySQL Connection Error: ({$mysql->connect_errno}) {$mysql->connect_error}\n");
|
||||
--$maxTries;
|
||||
|
||||
if ($maxTries <= 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
} while ($mysql->connect_error);
|
||||
|
||||
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($db) . '`'))
|
||||
{
|
||||
fwrite($stderr, "\nMySQL 'CREATE DATABASE' Error: " . $mysql->error . "\n");
|
||||
$mysql->close();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite($stderr, "\nMySQL Database Created\n");
|
||||
|
||||
$mysql->close();
|
||||
}
|
||||
elseif ($dbType === 'pgsql')
|
||||
{
|
||||
$port = $port ? (int)$port : 5432;
|
||||
$maxTries = 10;
|
||||
|
||||
do {
|
||||
$connection = "host={$host} port={$port} user={$user} password={$password}";
|
||||
$dbconn = @pg_connect($connection);
|
||||
|
||||
if (!$dbconn)
|
||||
{
|
||||
fwrite($stderr, "\nPostgreSQL Connection Error\n");
|
||||
--$maxTries;
|
||||
|
||||
if ($maxTries <= 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
} while (!$dbconn);
|
||||
|
||||
$query = "SELECT 1 FROM pg_database WHERE datname = '$db'";
|
||||
$result = pg_query($dbconn, $query);
|
||||
|
||||
if (pg_num_rows($result) == 0)
|
||||
{
|
||||
$createDbQuery = "CREATE DATABASE \"$db\"";
|
||||
if (!pg_query($dbconn, $createDbQuery))
|
||||
{
|
||||
fwrite($stderr, "\nPostgreSQL 'CREATE DATABASE' Error\n");
|
||||
pg_close($dbconn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
while ($mysql->connect_error);
|
||||
|
||||
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '`'))
|
||||
fwrite($stderr, "\nPostgreSQL Database Created\n");
|
||||
|
||||
pg_close($dbconn);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($stderr, "\nMySQL 'CREATE DATABASE' Error: " . $mysql->error . "\n");
|
||||
$mysql->close();
|
||||
fwrite($stderr, "\nInvalid database type. Please provide 'pgsql' or 'mysqli'.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite($stderr, "\nMySQL Database Created\n");
|
||||
|
||||
$mysql->close();
|
||||
|
Loading…
Reference in New Issue
Block a user