From 6fd3acf651b7c1e17da1f70a956ca0330c64e48e Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Tue, 2 Dec 2014 11:17:08 -0500 Subject: [PATCH] More work on setup form --- airtime_mvc/build/airtime-setup/load.php | 14 -------- .../build/airtime-setup/setup-config.php | 34 +++++++++++++++++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/build/airtime-setup/load.php b/airtime_mvc/build/airtime-setup/load.php index 29d4b227a..96f21ed66 100644 --- a/airtime_mvc/build/airtime-setup/load.php +++ b/airtime_mvc/build/airtime-setup/load.php @@ -71,18 +71,4 @@ function airtimeCheckDatabaseConfiguration() { */ function airtimeConfigureDatabase() { Propel::init(CONFIG_PATH . 'airtime-conf-production.php'); -} - -function airtimeValidateDatabaseSettings($settings) { - global $airtimeSetup; - if (!$airtimeSetup) { - return false; - } - - $dbUser = $settings["dbUser"]; - $dbPass = $settings["dbPass"]; - $dbName = $settings["dbName"]; - $dbHost = $settings["dbHost"]; - - return true; } \ No newline at end of file diff --git a/airtime_mvc/build/airtime-setup/setup-config.php b/airtime_mvc/build/airtime-setup/setup-config.php index b5b17a040..478a77671 100644 --- a/airtime_mvc/build/airtime-setup/setup-config.php +++ b/airtime_mvc/build/airtime-setup/setup-config.php @@ -1,5 +1,7 @@ @@ -36,8 +38,36 @@ $("#dbSettingsForm").submit(function(e) { e.preventDefault(); var d = $('#dbSettingsForm').serializeArray(); - $.post('setup/functions.php?fn=airtimeValidateDatabaseSettings', d, function(data) { - console.log(data); + // First, check if the db user exists (if not, we're done) + $.post('setup/functions.php?fn=airtimeValidateDatabaseUser', d, function(result) { + if (result == true) { + // We know that the user credentials check out, so check if the database exists + $.post('setup/functions.php?fn=airtimeValidateDatabaseSettings', d, function(result) { + if (result == true) { + // The database already exists, so we can just set up the schema + // TODO change alerts to actually useful things + alert("Setting up airtime schema..."); + } else { + // The database doesn't exist, so check if the user can create databases + $.post('setup/functions.php?fn=airtimeCheckUserCanCreateDb', d, function(result) { + if (result == true) { + // The user can create a database, so ask if they want to create it + if (confirm("Create database '" + $("#dbName").val() + "' on " + $("#dbHost").val() + + " as user " + $("#dbUser").val() + "?")) { + // TODO create the database... + alert("Creating airtime database..."); + } + } else { + // The user can't create databases, so we're done + alert("No database " + $("#dbName").val() + " exists; user " + $("#dbUser").val() + + " does not have permission to create databases on " + $("#dbHost").val()); + } + }, "json"); + } + }, "json"); + } else { + alert("User credentials are invalid!"); + } }, "json"); });