Skip to content

Commit

Permalink
Remove legacy DB setup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
williamjallen committed Jun 12, 2024
1 parent d0a2b39 commit 9182c8d
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 2,698 deletions.
54 changes: 4 additions & 50 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,10 @@ public function install(): View
$db_host = $database_config['host'];
$db_port = $database_config['port'];
$db_user = $database_config['username'];
$db_pass = $database_config['password'];
$db_name = $database_config['database'];

if (array_key_exists('unix_socket', $database_config) && $database_config['unix_socket']) {
$db_connection = 'unix_socket';
} else {
$db_connection = 'host';
if ($db_port != '') {
$db_host = $db_host . ';port=' . $db_port;
}
if ($db_port != '') {
$db_host = $db_host . ';port=' . $db_port;
}

$xml .= '<connectiondb_type>' . $db_type . '</connectiondb_type>';
Expand All @@ -376,7 +370,7 @@ public function install(): View

// Step 1: Check if we can connect to the database
try {
$pdo = new PDO("{$db_type}:{$db_connection}={$db_host}", $db_user, $db_pass);
$pdo = DB::getPdo();
$xml .= '<connectiondb>1</connectiondb>';
} catch (Exception) {
$xml .= '<connectiondb>0</connectiondb>';
Expand Down Expand Up @@ -453,7 +447,7 @@ public function install(): View
$sql = $db_type === 'mysql' ? "CREATE DATABASE IF NOT EXISTS `{$db_name}`" : "CREATE DATABASE {$db_name}";

try {
$pdo->exec($sql);
DB::statement($sql);
} catch (Exception $exception) {
if ($db_type !== 'pgsql' || !str_contains($exception->getMessage(), 'already exists')) {
$xml .= '<db_created>0</db_created>';
Expand All @@ -465,46 +459,6 @@ public function install(): View
if ($db_created) {
Artisan::call('migrate --force');

// If we are with PostGreSQL we need to add some extra functions
if ($db_type == 'pgsql') {
$sqlfile = base_path('/app/cdash/sql/pgsql/cdash.ext.sql');

// Create the language. PgSQL has no way to know if the language already
// exists
@pdo_query('CREATE LANGUAGE plpgsql');

$file_content = file($sqlfile);
$query = '';
foreach ($file_content as $sql_line) {
$tsl = trim($sql_line);
if ($sql_line !== '' && !str_starts_with($tsl, '--')) {
$query .= $sql_line;
$possemicolon = strrpos($query, ';');
if ($possemicolon !== false && substr_count($query, '\'', 0, $possemicolon) % 2 == 0) {
// We need to remove only the last semicolon
$pos = strrpos($query, ';');
if ($pos !== false) {
$query = substr($query, 0, $pos) . substr($query, $pos + 1);
}
$result = pdo_query($query);
if (!$result) {
$xml .= '<db_created>0</db_created>';
abort(500, pdo_error());
}
$query = '';
}
}
}

// Check the version of PostgreSQL
$result_version = pdo_query('SELECT version()');
$version_array = pdo_fetch_array($result_version);
if (str_contains(strtolower($version_array[0]), 'postgresql 9.')) {
// For PgSQL 9.0 we need to set the bytea_output to 'escape' (it was changed to hexa)
@pdo_query("ALTER DATABASE {$db_name} SET bytea_output TO 'escape'");
}
}

$user = new \CDash\Model\User();
$user->Email = $admin_email;
$user->Password = password_hash($admin_password, PASSWORD_DEFAULT);
Expand Down
18 changes: 0 additions & 18 deletions app/cdash/sql/convert.sh

This file was deleted.

109 changes: 0 additions & 109 deletions app/cdash/sql/convert_alter_table.pl

This file was deleted.

Loading

0 comments on commit 9182c8d

Please sign in to comment.