From af37f5c138a3373b69b16738545b70b429c17c62 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Fri, 29 Aug 2014 23:07:54 +0200 Subject: [PATCH] Define prefix after config-file has been loaded (#38 #214 #196) --- php/api.php | 3 +++ php/define.php | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/php/api.php b/php/api.php index 704efc5..1ca6c5e 100755 --- a/php/api.php +++ b/php/api.php @@ -39,6 +39,9 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) { } + # Define the table prefix + defineTablePrefix($dbTablePrefix); + # Connect to database $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName); diff --git a/php/define.php b/php/define.php index 1d285ab..d1768f6 100644 --- a/php/define.php +++ b/php/define.php @@ -26,15 +26,23 @@ define('LYCHEE_CONFIG_FILE', LYCHEE_DATA . 'config.php'); define('LYCHEE_URL_UPLOADS_THUMB', 'uploads/thumb/'); define('LYCHEE_URL_UPLOADS_BIG', 'uploads/big/'); -# Parse table prefix -# Old users do not have the table prefix stored in their config-file -if (!isset($dbTablePrefix)) $dbTablePrefix = ''; -else $dbTablePrefix .= '_'; +function defineTablePrefix($dbTablePrefix) { -# Define tables -define('LYCHEE_TABLE_ALBUMS', $dbTablePrefix . 'lychee_albums'); -define('LYCHEE_TABLE_LOG', $dbTablePrefix . 'lychee_log'); -define('LYCHEE_TABLE_PHOTOS', $dbTablePrefix . 'lychee_photos'); -define('LYCHEE_TABLE_SETTINGS', $dbTablePrefix . 'lychee_settings'); + # This part is wrapped into a function, because it needs to be called + # after the config-file has been loaded. Other defines are also available + # before the config-file has been loaded. + + # Parse table prefix + # Old users do not have the table prefix stored in their config-file + if (!isset($dbTablePrefix)) $dbTablePrefix = ''; + else $dbTablePrefix .= '_'; + + # Define tables + define('LYCHEE_TABLE_ALBUMS', $dbTablePrefix . 'lychee_albums'); + define('LYCHEE_TABLE_LOG', $dbTablePrefix . 'lychee_log'); + define('LYCHEE_TABLE_PHOTOS', $dbTablePrefix . 'lychee_photos'); + define('LYCHEE_TABLE_SETTINGS', $dbTablePrefix . 'lychee_settings'); + +} ?> \ No newline at end of file