diff --git a/Database/Database-Initialization.cs b/Database/Database-Initialization.cs index f5cac109..19b06ab8 100644 --- a/Database/Database-Initialization.cs +++ b/Database/Database-Initialization.cs @@ -8,7 +8,7 @@ namespace Swarmops.Database { // These functions are bloody dangerous, mmmkay? - public void ExecuteAdminCommand (string sqlSequence) + public void ExecuteAdminCommand(string sql) { // TODO: Verify that we're in admin mode @@ -16,14 +16,31 @@ namespace Swarmops.Database { connection.Open(); - DbCommand command = GetDbCommand (sqlSequence, connection); + DbCommand command = GetDbCommand(sql, connection); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } - public int ExecuteAdminCommandScalar (string sqlSequence) + public void ExecuteAdminCommands(string[] sqlSequence) + { + // TODO: Verify that we're in admin mode + + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + foreach (string sql in sqlSequence) + { + DbCommand command = GetDbCommand (sql, connection); + command.CommandType = CommandType.Text; + command.ExecuteNonQuery(); + } + } + } + + public int ExecuteAdminCommandScalar(string sqlSequence) { // TODO: Verify that we're in admin mode diff --git a/Logic/Structure/GeographyUpdate.cs b/Logic/Structure/GeographyUpdate.cs index 96aa8c2a..e920df84 100644 --- a/Logic/Structure/GeographyUpdate.cs +++ b/Logic/Structure/GeographyUpdate.cs @@ -159,7 +159,7 @@ namespace Swarmops.Logic.Structure cityIdsUsedLookup[city.CityId] = false; // force non-use of invalid city } - if (cityIdsUsedLookup[city.CityId]) + if ((cityIdsUsedLookup.ContainsKey(city.CityId) && cityIdsUsedLookup[city.CityId]) || country.PostalCodeLength == 0) { int newGeographyId = geographyIdTranslation[city.GeographyId]; diff --git a/Site5/Pages/v5/Init/Default.aspx b/Site5/Pages/v5/Init/Default.aspx index 8a4e0e8d..46620ebc 100644 --- a/Site5/Pages/v5/Init/Default.aspx +++ b/Site5/Pages/v5/Init/Default.aspx @@ -10,6 +10,7 @@ + @@ -139,8 +140,9 @@ // Yes, config is writable. Hide "unwritable" div, show "writable" div, all is nice $('#DivDatabaseUnwritable').css('display', 'none'); - $('#DivDatabaseWritable').css('display', 'inline'); - $('#<%=this.TextCredentialsReadDatabase.ClientID %>').focus(); + $('#DivDatabaseRootConfig').css('display', 'inline'); + setTimeout('$("#TextMysqlServerHost").focus();', 250); + //$('#<%=this.TextCredentialsReadDatabase.ClientID %>').focus(); } else { // Config is NOT writable. Keep the error on-screen and keep re-checking every two seconds. @@ -155,9 +157,17 @@ else if (stepNumber == 2) { isValid = true; // assume true, make false as we go - textBoxes = ["<%=this.TextCredentialsReadDatabase.ClientID %>", "<%=this.TextCredentialsReadServer.ClientID %>", "<%=this.TextCredentialsReadUser.ClientID %>", "<%=this.TextCredentialsReadPassword.ClientID %>", - "<%=this.TextCredentialsWriteDatabase.ClientID %>", "<%=this.TextCredentialsWriteServer.ClientID %>", "<%=this.TextCredentialsWriteUser.ClientID %>", "<%=this.TextCredentialsWritePassword.ClientID %>", - "<%=this.TextCredentialsAdminDatabase.ClientID %>", "<%=this.TextCredentialsAdminServer.ClientID %>", "<%=this.TextCredentialsAdminUser.ClientID %>", "<%=this.TextCredentialsAdminPassword.ClientID %>"]; + textBoxes = []; + + if (autoConfigMode) { + textBoxes = ["TextMysqlServerHost", "TextMysqlRootPassword"]; + } else { + textBoxes = [ + "<%=this.TextCredentialsReadDatabase.ClientID %>", "<%=this.TextCredentialsReadServer.ClientID %>", "<%=this.TextCredentialsReadUser.ClientID %>", "<%=this.TextCredentialsReadPassword.ClientID %>", + "<%=this.TextCredentialsWriteDatabase.ClientID %>", "<%=this.TextCredentialsWriteServer.ClientID %>", "<%=this.TextCredentialsWriteUser.ClientID %>", "<%=this.TextCredentialsWritePassword.ClientID %>", + "<%=this.TextCredentialsAdminDatabase.ClientID %>", "<%=this.TextCredentialsAdminServer.ClientID %>", "<%=this.TextCredentialsAdminUser.ClientID %>", "<%=this.TextCredentialsAdminPassword.ClientID %>" + ]; + } for (loop = 0; loop < textBoxes.length; loop++) { fieldContents = $('#' + textBoxes[loop]).val(); @@ -174,42 +184,73 @@ if (isValid) { DisableNext(); // block Next during synchro call - it may take a while - // also, won't get re-enabled no matter the outcome - $.ajax({ - type: "POST", - url: "/Pages/v5/Init/Default.aspx/FirstCredentialsTest", - data: "{" + - "'readDatabase':'" + $('#<%=this.TextCredentialsReadDatabase.ClientID %>').val() + "',"+ - "'readServer':'" + $('#<%=this.TextCredentialsReadServer.ClientID %>').val() + "',"+ - "'readUser':'" + $('#<%=this.TextCredentialsReadUser.ClientID %>').val() + "',"+ - "'readPassword':'" + $('#<%=this.TextCredentialsReadPassword.ClientID %>').val() + "',"+ - "'writeDatabase':'" + $('#<%=this.TextCredentialsWriteDatabase.ClientID %>').val() + "',"+ - "'writeServer':'" + $('#<%=this.TextCredentialsWriteServer.ClientID %>').val() + "',"+ - "'writeUser':'" + $('#<%=this.TextCredentialsWriteUser.ClientID %>').val() + "',"+ - "'writePassword':'" + $('#<%=this.TextCredentialsWritePassword.ClientID %>').val() + "',"+ - "'adminDatabase':'" + $('#<%=this.TextCredentialsAdminDatabase.ClientID %>').val() + "',"+ - "'adminServer':'" + $('#<%=this.TextCredentialsAdminServer.ClientID %>').val() + "',"+ - "'adminUser':'" + $('#<%=this.TextCredentialsAdminUser.ClientID %>').val() + "',"+ - "'adminPassword':'" + $('#<%=this.TextCredentialsAdminPassword.ClientID %>').val() + "',"+ - "'serverName':'" + hostName + "'," + - "'ipAddress':'" + hostAddress +"'}", - contentType: "application/json; charset=utf-8", - dataType: "json", - async: false, // blocks until function returns - race conditions otherwise - success: function (msg) { - if (msg.d.AllPermissionsOk != true) { + // also, won't get re-enabled no matter the outcome - // We have a permissions problem. Block further progress and display the problem. - updatePermissionsAnalysisDisplay(msg.d); - $('#DivDatabaseWritable').fadeOut(400, 'swing', function() { $('#DivDatabasePermissionProblem').fadeIn(200); }); - setTimeout('recheckDatabasePermissionsAnalysis();', 5000); // 5s until first re-check - isValid = false; - } else { - // re-enable Next only on exit of step 3 + var jsonData = {}; + jsonData.serverName = hostName; + jsonData.ipAddress = hostAddress; + + if (autoConfigMode) { + jsonData.mysqlHostName = $('#TextMysqlServerHost').val(); + jsonData.rootPassword = $('#TextMysqlRootPassword').val(); + + $.ajax({ + type: "POST", + url: "/Pages/v5/Init/Default.aspx/CreateDatabaseFromRoot", + data: $.toJSON(jsonData), + contentType: "application/json; charset=utf-8", + dataType: "json", + async: false, // blocks until function returns - race conditions otherwise + success: function (msg) { + if (msg.d != true) { + + // Credentials problem. + $('#TextMysqlRootPassword, #TextMysqlServerHost').css('background-image', "url('/Images/Icons/iconshock-cross-12px.png')").css('background-position', 'right center').css('background-repeat', 'no-repeat'); + EnableNext(); + isValid = false; + } else { + // re-enable Next only on exit of step 3 + } } - } - }); - } + }); + } + else + { + jsonData.readDatabase = $('#<%=this.TextCredentialsReadDatabase.ClientID %>').val(); + jsonData.readServer = $('#<%=this.TextCredentialsReadServer.ClientID %>').val(); + jsonData.readUser = $('#<%=this.TextCredentialsReadUser.ClientID %>').val(); + jsonData.readPassword = $('#<%=this.TextCredentialsReadPassword.ClientID %>').val(); + jsonData.writeDatabase = $('#<%=this.TextCredentialsWriteDatabase.ClientID %>').val(); + jsonData.writeServer = $('#<%=this.TextCredentialsWriteServer.ClientID %>').val(); + jsonData.writeUser = $('#<%=this.TextCredentialsWriteUser.ClientID %>').val(); + jsonData.writePassword = $('#<%=this.TextCredentialsWritePassword.ClientID %>').val(); + jsonData.adminDatabase = $('#<%=this.TextCredentialsAdminDatabase.ClientID %>').val(); + jsonData.adminServer = $('#<%=this.TextCredentialsAdminServer.ClientID %>').val(); + jsonData.adminUser = $('#<%=this.TextCredentialsAdminUser.ClientID %>').val(); + jsonData.adminPassword = $('#<%=this.TextCredentialsAdminPassword.ClientID %>').val(); + + $.ajax({ + type: "POST", + url: "/Pages/v5/Init/Default.aspx/FirstCredentialsTest", + data: $.toJSON(jsonData), + contentType: "application/json; charset=utf-8", + dataType: "json", + async: false, // blocks until function returns - race conditions otherwise + success: function(msg) { + if (msg.d.AllPermissionsOk != true) { + + // We have a permissions problem. Block further progress and display the problem. + updatePermissionsAnalysisDisplay(msg.d); + $('#DivDatabaseManualConfig').fadeOut(400, 'swing', function() { $('#DivDatabasePermissionProblem').fadeIn(200); }); + setTimeout('recheckDatabasePermissionsAnalysis();', 5000); // 5s until first re-check + isValid = false; + } else { + // re-enable Next only on exit of step 3 + } + } + }); + } + } if (isValid) { @@ -311,7 +352,7 @@ contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { - $('#DivDatabasePermissionProblem').fadeOut(200, 'swing', function () { $('#DivDatabaseWritable').fadeIn(200); EnableNext(); }); + $('#DivDatabasePermissionProblem').fadeOut(200, 'swing', function () { $('#DivDatabaseManualConfig').fadeIn(200); EnableNext(); }); } }); } @@ -328,10 +369,10 @@ success: function (msg) { if (msg.d == true) { - // Yes, config is writable. Hide "unwritable" div, show "writable" div, all is nice + // Yes, config is writable. Hide "unwritable" div, show "config" div, all is nice $('#DivDatabaseUnwritable').css('display', 'none'); - $('#DivDatabaseWritable').fadeIn('slow'); - setTimeout('$("#<%=this.TextCredentialsReadDatabase.ClientID %>").focus();', 250); + $('#DivDatabaseManualConfig').fadeIn('slow'); + setTimeout('$("#TextMysqlServerHost").focus();', 250); EnableNext(); } else { // Config is NOT writable. Keep the error on-screen and keep re-checking every two seconds. @@ -470,8 +511,16 @@ } }); - } + } + function goManualCredentials() { + autoConfigMode = false; + $('#DivDatabaseRootConfig').css('display', 'none'); + $('#DivDatabaseManualConfig').fadeIn('slow'); + setTimeout('$("#<%=this.TextCredentialsReadDatabase.ClientID %>").focus();', 250); + } + + var autoConfigMode = true; @@ -582,8 +631,15 @@ -