Skip to content

Commit

Permalink
User creating with sqlite working
Browse files Browse the repository at this point in the history
  • Loading branch information
jonocodes committed May 18, 2024
1 parent 3330548 commit 6efb14d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# set -e
set -e

APP_DIR=/usr/local/share/cypht
# CYPHT_CONFIG_FILE=${APP_DIR}/hm3.ini
Expand All @@ -11,6 +11,8 @@ APP_DIR=/usr/local/share/cypht

# Modules

# TODO: deal with modules

enable_disable_module() {
local module=${1}
local setting=${2}
Expand Down Expand Up @@ -55,6 +57,7 @@ then
fi

# Attachment Location - create directory
echo "\nCreating director for attachment location: ${ATTACHMENT_DIR}\n"
mkdir -p ${ATTACHMENT_DIR}
chown www-data:www-data ${ATTACHMENT_DIR}

Expand Down
11 changes: 9 additions & 2 deletions scripts/setup_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
$db_pass = getenv('DB_PASS');
$db_driver = getenv('DB_DRIVER') ?: 'mysql';
$db_host = getenv('DB_HOST') ?: '127.0.0.1';
$db_socket = getenv('DB_SOCKET', '/tmp/temp_cypht.sqlite');

$connected = false;
$create_table = "CREATE TABLE IF NOT EXISTS";
Expand All @@ -31,6 +32,12 @@
print("Not connected\n");
try {
$conn = new pdo("{$db_driver}:host={$db_host};dbname={$db_name}", $db_user, $db_pass);

if ($db_driver == 'sqlite') {
// TODO: password protect sqlite?
$conn = new pdo("{$db_driver}:{$db_socket}");
}

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
printf("Database connection successful ...\n");
printf("{$db_driver}:host={$db_host};dbname={$db_name}\n");
Expand All @@ -41,6 +48,7 @@
}
}
print("Connected\n");

if (strcasecmp($session_type,'DB')==0) {
printf("Creating database table hm_user_session ...\n");

Expand Down Expand Up @@ -70,7 +78,6 @@
// TODO: figure out why this is not working for sqlite
$rows = $conn->exec($stmt);
printf($stmt);
printf("\nrows updated: {$rows}\n");
} catch (PDOException $e) {
print($e);
exit (1);
Expand All @@ -92,4 +99,4 @@
$conn->exec($stmt);
}

print("Db setup finished");
print("Db setup finished\n");

0 comments on commit 6efb14d

Please sign in to comment.