diff --git a/build/Build.bat b/build/Build.bat index 525f3cf41b..fa786d3c85 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -16,6 +16,8 @@ echo This file is only here so that the containing folder will be included in th echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\media\dummy.txt echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\scripts\dummy.txt echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\usercontrols\dummy.txt +echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\Views\Partials\dummy.txt +echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\Views\MacroPartials\dummy.txt echo This file is only here so that the containing folder will be included in the NuGet package, it is safe to delete. > .\_BuildOutput\WebApp\xslt\dummy.txt ..\src\.nuget\NuGet.exe pack NuSpecs\UmbracoCms.Core.nuspec -Version %version% diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index b4955f36ad..078a3e1963 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -26,8 +26,9 @@ namespace Umbraco.Core private bool _configured; private string _connectionString; private string _providerName; + private DatabaseSchemaResult _result; - internal DatabaseContext(IDatabaseFactory factory) + internal DatabaseContext(IDatabaseFactory factory) { _factory = factory; } @@ -245,7 +246,7 @@ namespace Umbraco.Core Initialize(providerName); } - else if (ConfigurationManager.AppSettings.ContainsKey(GlobalSettings.UmbracoConnectionName)) + else if (ConfigurationManager.AppSettings.ContainsKey(GlobalSettings.UmbracoConnectionName) && string.IsNullOrEmpty(ConfigurationManager.AppSettings[GlobalSettings.UmbracoConnectionName]) == false) { //A valid connectionstring does not exist, but the legacy appSettings key was found, so we'll reconfigure the conn.string. var legacyConnString = ConfigurationManager.AppSettings[GlobalSettings.UmbracoConnectionName]; @@ -308,10 +309,13 @@ namespace Umbraco.Core if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName))) return new DatabaseSchemaResult(); - var database = new UmbracoDatabase(_connectionString, ProviderName); - var dbSchema = new DatabaseSchemaCreation(database); - var result = dbSchema.ValidateSchema(); - return result; + if (_result == null) + { + var database = new UmbracoDatabase(_connectionString, ProviderName); + var dbSchema = new DatabaseSchemaCreation(database); + _result = dbSchema.ValidateSchema(); + } + return _result; } internal Result CreateDatabaseSchemaAndDataOrUpgrade() @@ -332,11 +336,13 @@ namespace Umbraco.Core var database = new UmbracoDatabase(_connectionString, ProviderName); var schemaResult = ValidateDatabaseSchema(); var installedVersion = schemaResult.DetermineInstalledVersion(); + string message; //If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedVersion.Equals(new Version(0, 0, 0))) { database.CreateDatabaseSchema(); + message = "Installation completed!"; } else { @@ -346,13 +352,28 @@ namespace Umbraco.Core var targetVersion = UmbracoVersion.Current; var runner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); var upgraded = runner.Execute(database, true); + message = "Upgrade completed!"; } - return new Result { Message = "Installation completed!", Success = true, Percentage = "100" }; + return new Result { Message = message, Success = true, Percentage = "100" }; } catch (Exception ex) { - return new Result { Message = ex.Message, Success = false, Percentage = "90" }; + LogHelper.Info("Database configuration failed with the following error and stack trace: " + ex.Message + "\n" + ex.StackTrace); + + if (_result != null) + { + LogHelper.Info("The database schema validation produced the following summary: \n" + _result.GetSummary()); + } + + return new Result + { + Message = + "The database configuration failed with the following message: " + ex.Message + + "\n Please check log file for addtional information (can be found in '/App_Data/Logs/UmbracoTraceLog.txt')", + Success = false, + Percentage = "90" + }; } } diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs index 2c3e245dff..756d97ff13 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs @@ -132,6 +132,11 @@ namespace Umbraco.Core.Persistence.Migrations.Initial result.Errors.Add(new Tuple("Column", column)); } + //MySql doesn't conform to the "normal" naming of constraints, so there is currently no point in doing these checks. + //NOTE: At a later point we do other checks for MySql, but ideally it should be necessary to do special checks for different providers. + if (SyntaxConfig.SqlSyntaxProvider is MySqlSyntaxProvider) + return result; + //Check constraints in configured database against constraints in schema var constraintsInDatabase = SyntaxConfig.SqlSyntaxProvider.GetConstraintsPerColumn(_database).DistinctBy(x => x.Item3).ToList(); var foreignKeysInDatabase = constraintsInDatabase.Where(x => x.Item3.StartsWith("FK_")).Select(x => x.Item3).ToList(); diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaResult.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaResult.cs index 9b0ae69270..144f0f7098 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaResult.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaResult.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using Umbraco.Core.Configuration; using Umbraco.Core.Persistence.DatabaseModelDefinitions; +using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Core.Persistence.Migrations.Initial { @@ -59,7 +61,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial return new Version(4, 7, 0); } - return new Version(4, 10, 0); + return new Version(4, 9, 0); } return new Version(0, 0, 0); @@ -71,7 +73,48 @@ namespace Umbraco.Core.Persistence.Migrations.Initial /// A string containing a human readable string with a summary message public string GetSummary() { - return string.Empty; + var sb = new StringBuilder(); + if (Errors.Any() == false) + { + sb.AppendLine("The database schema validation didn't find any errors."); + return sb.ToString(); + } + + //Table error summary + if (Errors.Any(x => x.Item1.Equals("Table"))) + { + sb.AppendLine("The following tables were found in the database, but are not in the current schema:"); + sb.AppendLine(string.Join(",", Errors.Where(x => x.Item1.Equals("Table")).Select(x => x.Item2))); + sb.AppendLine(" "); + } + //Column error summary + if (Errors.Any(x => x.Item1.Equals("Column"))) + { + sb.AppendLine("The following columns were found in the database, but are not in the current schema:"); + sb.AppendLine(string.Join(",", Errors.Where(x => x.Item1.Equals("Column")).Select(x => x.Item2))); + sb.AppendLine(" "); + } + //Constraint error summary + if (Errors.Any(x => x.Item1.Equals("Constraint"))) + { + sb.AppendLine("The following constraints (Primary Keys, Foreign Keys and Indexes) were found in the database, but are not in the current schema:"); + sb.AppendLine(string.Join(",", Errors.Where(x => x.Item1.Equals("Constraint")).Select(x => x.Item2))); + sb.AppendLine(" "); + } + //Unknown constraint error summary + if (Errors.Any(x => x.Item1.Equals("Unknown"))) + { + sb.AppendLine("The following unknown constraints (Primary Keys, Foreign Keys and Indexes) were found in the database, but are not in the current schema:"); + sb.AppendLine(string.Join(",", Errors.Where(x => x.Item1.Equals("Unknown")).Select(x => x.Item2))); + sb.AppendLine(" "); + } + + if (SyntaxConfig.SqlSyntaxProvider is MySqlSyntaxProvider) + { + sb.AppendLine("Please note that the constraints could not be validated because the current dataprovider is MySql."); + } + + return sb.ToString(); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs index 92f0d617f3..99431e0894 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs @@ -42,23 +42,86 @@ namespace Umbraco.Core.Persistence.SqlSyntax public override IEnumerable GetTablesInSchema(Database db) { - var items = db.Fetch("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"); - return items.Select(x => x.TABLE_NAME).Cast().ToList(); + List list; + try + { + db.OpenSharedConnection(); + var items = + db.Fetch( + "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = @TableSchema", + new {TableSchema = db.Connection.Database}); + list = items.Select(x => x.TABLE_NAME).Cast().ToList(); + } + finally + { + db.CloseSharedConnection(); + } + return list; } public override IEnumerable GetColumnsInSchema(Database db) { - return new List(); + List list; + try + { + db.OpenSharedConnection(); + var items = + db.Fetch( + "SELECT TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @TableSchema", + new {TableSchema = db.Connection.Database}); + list = + items.Select( + item => + new ColumnInfo(item.TABLE_NAME, item.COLUMN_NAME, item.ORDINAL_POSITION, item.COLUMN_DEFAULT, + item.IS_NULLABLE, item.DATA_TYPE)).ToList(); + } + finally + { + db.CloseSharedConnection(); + } + return list; } public override IEnumerable> GetConstraintsPerTable(Database db) { - return new List>(); + List> list; + try + { + //Does not include indexes and constraints are named differently + var items = + db.Fetch( + "SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = @TableSchema", + new {TableSchema = db.Connection.Database}); + list = items.Select(item => new Tuple(item.TABLE_NAME, item.CONSTRAINT_NAME)).ToList(); + } + finally + { + db.CloseSharedConnection(); + } + return list; } public override IEnumerable> GetConstraintsPerColumn(Database db) { - return new List>(); + List> list; + try + { + //Does not include indexes and constraints are named differently + var items = + db.Fetch( + "SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = @TableSchema", + new {TableSchema = db.Connection.Database}); + list = + items.Select( + item => + new Tuple(item.TABLE_NAME, item.COLUMN_NAME, item.CONSTRAINT_NAME)) + .ToList(); + } + finally + { + db.CloseSharedConnection(); + } + return list; } public override bool DoesTableExist(Database db, string tableName) diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs index eda04199bd..7167026d9a 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs @@ -72,7 +72,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax { var items = db.Fetch( - "SELECT TABLE_NAME, CONSTRAINT_NAME FROM SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE"); + "SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE"); return items.Select(item => new Tuple(item.TABLE_NAME, item.CONSTRAINT_NAME)).ToList(); } diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 38bd853e11..89b87663a0 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1228,13 +1228,12 @@ namespace Umbraco.Core.Services _publishingStrategy.PublishingFinalized(content); //We need to check if children and their publish state to ensure that we republish content that was previously published - if (HasChildren(content.Id)) + if (omitCacheRefresh == false && HasChildren(content.Id)) { var children = GetDescendants(content); var shouldBeRepublished = children.Where(child => HasPublishedVersion(child.Id)); - if (omitCacheRefresh == false) - _publishingStrategy.PublishingFinalized(shouldBeRepublished, false); + _publishingStrategy.PublishingFinalized(shouldBeRepublished, false); } Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId, content.Id); diff --git a/src/Umbraco.Tests/App.config b/src/Umbraco.Tests/App.config index fc8a3a6def..20f0ce5aae 100644 --- a/src/Umbraco.Tests/App.config +++ b/src/Umbraco.Tests/App.config @@ -76,6 +76,8 @@ + + diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 66cd2854c4..a729aacabb 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -313,7 +313,9 @@ - + + Designer + diff --git a/src/Umbraco.Web.UI/install/steps/database.ascx b/src/Umbraco.Web.UI/install/steps/database.ascx index d3446f49cb..3234698de5 100644 --- a/src/Umbraco.Web.UI/install/steps/database.ascx +++ b/src/Umbraco.Web.UI/install/steps/database.ascx @@ -269,10 +269,42 @@
-

Installing Umbraco

-

- The Umbraco database is being configured. This process populates your chosen database with a blank Umbraco instance. -

+ +
+

Installing Umbraco

+

+ The Umbraco database is being configured. This process populates your chosen database with a blank Umbraco instance. +

+
+ +
+ +
+

Upgrading Umbraco

+

+ The Umbraco database is being configured. This process upgrades your Umbraco database. +

+
+ +
@@ -310,6 +342,8 @@ if (json.Success) { $(".btn-box").show(); $('.ui-progressbar-value').css("background-image", "url(../umbraco_client/installer/images/pbar.gif)"); + $(".result-status-container").show(); + $(".progress-status-container").hide(); } else { $(".btn-continue").hide(); $(".btn-back").show(); @@ -320,32 +354,4 @@ }); - - - - -

Database installed

-
-

- Umbraco - <%=UmbracoVersion.Current.ToString(3)%> - has now been copied to your database. Press Continue to proceed. -

-
-
- -

Database upgraded

-
-

- Your database has been upgraded to version: - <%=UmbracoVersion.Current.ToString(3)%>.
- Press Continue to proceed. -

-
-
- -
-
 
- Continue -
-
+ \ No newline at end of file diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index e1934cd61c..d83c0e0cef 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -66,7 +66,7 @@ - + diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Database.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Database.cs index 0c2b61108f..f5a695e8cf 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Database.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Database.cs @@ -41,7 +41,7 @@ namespace umbraco.presentation.install.steps.Definitions //Even though the ConfigurationStatus is blank we try to determine the version if we can connect to the database var result = ApplicationContext.Current.DatabaseContext.ValidateDatabaseSchema(); var determinedVersion = result.DetermineInstalledVersion(); - if(determinedVersion.Equals(new Version(0, 0, 0))) + if (determinedVersion.Equals(new Version(0, 0, 0))) return false; return UmbracoVersion.Current < determinedVersion; diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Welcome.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Welcome.cs index 868f5c6ab5..944eaf4e89 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Welcome.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/Definitions/Welcome.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using umbraco.cms.businesslogic.installer; +using umbraco.cms.businesslogic.installer; namespace umbraco.presentation.install.steps.Definitions { diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx index d3446f49cb..3234698de5 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx @@ -269,10 +269,42 @@
-

Installing Umbraco

-

- The Umbraco database is being configured. This process populates your chosen database with a blank Umbraco instance. -

+ +
+

Installing Umbraco

+

+ The Umbraco database is being configured. This process populates your chosen database with a blank Umbraco instance. +

+
+ +
+ +
+

Upgrading Umbraco

+

+ The Umbraco database is being configured. This process upgrades your Umbraco database. +

+
+ +
@@ -310,6 +342,8 @@ if (json.Success) { $(".btn-box").show(); $('.ui-progressbar-value').css("background-image", "url(../umbraco_client/installer/images/pbar.gif)"); + $(".result-status-container").show(); + $(".progress-status-container").hide(); } else { $(".btn-continue").hide(); $(".btn-back").show(); @@ -320,32 +354,4 @@ }); - - - - -

Database installed

-
-

- Umbraco - <%=UmbracoVersion.Current.ToString(3)%> - has now been copied to your database. Press Continue to proceed. -

-
-
- -

Database upgraded

-
-

- Your database has been upgraded to version: - <%=UmbracoVersion.Current.ToString(3)%>.
- Press Continue to proceed. -

-
-
- -
-
 
- Continue -
-
+ \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs index d05f87af9a..a7a564e904 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.cs @@ -71,8 +71,29 @@ namespace umbraco.presentation.install.steps { // Does the user have to enter a connection string? if (settings.Visible && !Page.IsPostBack) - ShowDatabaseSettings(); + { + //If the connection string is already present in web.config we don't need to show the settings page and we jump to installing/upgrading. + if ( + ConfigurationManager.ConnectionStrings[ + Umbraco.Core.Configuration.GlobalSettings.UmbracoConnectionName] == null + || + string.IsNullOrEmpty( + ConfigurationManager.ConnectionStrings[ + Umbraco.Core.Configuration.GlobalSettings.UmbracoConnectionName].ConnectionString)) + { + installProgress.Visible = true; + upgradeProgress.Visible = false; + ShowDatabaseSettings(); + } + else + { + installProgress.Visible = false; + upgradeProgress.Visible = true; + settings.Visible = false; + installing.Visible = true; + } + } } /// diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.designer.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.designer.cs index d54355b647..35cc3f8879 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.designer.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/database.ascx.designer.cs @@ -220,30 +220,21 @@ namespace umbraco.presentation.install.steps { protected global::System.Web.UI.WebControls.PlaceHolder installing; /// - /// confirms control. + /// installProgress control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.Panel confirms; + protected global::System.Web.UI.WebControls.PlaceHolder installProgress; /// - /// installConfirm control. + /// upgradeProgress control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.PlaceHolder installConfirm; - - /// - /// upgradeConfirm control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.PlaceHolder upgradeConfirm; + protected global::System.Web.UI.WebControls.PlaceHolder upgradeProgress; } } diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/welcome.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/welcome.ascx.cs index b69ab00bf3..bb5b765a8c 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/welcome.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/welcome.ascx.cs @@ -1,14 +1,8 @@ -using umbraco; +using System; +using Umbraco.Core; namespace umbraco.presentation.install { - using System; - using System.Data; - using System.Drawing; - using System.Web; - using System.Web.UI.WebControls; - using System.Web.UI.HtmlControls; - /// /// Summary description for welcome. /// @@ -17,24 +11,24 @@ namespace umbraco.presentation.install protected void Page_Load(object sender, System.EventArgs e) { + var result = ApplicationContext.Current.DatabaseContext.ValidateDatabaseSchema(); + var determinedVersion = result.DetermineInstalledVersion(); + // Display the Umbraco upgrade message if Umbraco is already installed - if (String.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus) == false) + if (String.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus) == false || determinedVersion.Equals(new Version(0, 0, 0)) == false) { ph_install.Visible = false; ph_upgrade.Visible = true; } - - // Check for config! - if (GlobalSettings.Configured) - { - Application.Lock(); - Application["umbracoNeedConfiguration"] = null; - Application.UnLock(); - Response.Redirect(Request.QueryString["url"] ?? "/", true); - } - - - + + // Check for config! + if (GlobalSettings.Configured) + { + Application.Lock(); + Application["umbracoNeedConfiguration"] = null; + Application.UnLock(); + Response.Redirect(Request.QueryString["url"] ?? "/", true); + } } protected void gotoNextStep(object sender, EventArgs e) {