From f07752078105e7cb63045fcb37cc87a379485731 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 20 Mar 2014 17:35:51 +1100 Subject: [PATCH] Fixes: U4-4154 convert existing property data from XML to JSON during upgrade v6 - 7 to ensure that other data types that have this property editor are upgraded as well. Fixes some of the installer bits so that the steps are not marked as completed if they have problems. --- .../UpdateRelatedLinksData.cs | 94 ++++++++----------- src/Umbraco.Web/Install/InstallException.cs | 14 +++ .../InstallSteps/DatabaseConfigureStep.cs | 2 +- .../InstallSteps/DatabaseInstallStep.cs | 6 +- .../InstallSteps/DatabaseUpgradeStep.cs | 6 +- .../InstallSteps/SetUmbracoVersionStep.cs | 9 +- .../InstallSteps/StarterKitDownloadStep.cs | 4 +- 7 files changed, 58 insertions(+), 77 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs index 5d28cf9119..8778546c3c 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs @@ -26,74 +26,56 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven { if (database != null) { - try + var dtSql = new Sql().Select("nodeId").From().Where(dto => dto.PropertyEditorAlias == Constants.PropertyEditors.RelatedLinksAlias); + var dataTypeIds = database.Fetch(dtSql); + + var propertyData = + database.Fetch( + "WHERE propertyTypeId in (SELECT id from cmsPropertyType where dataTypeID IN (@dataTypeIds))", new { dataTypeIds = dataTypeIds }); + foreach (var data in propertyData) { - var propertyData = - database.Fetch( - "WHERE propertyTypeId in (SELECT id from cmsPropertyType where dataTypeID = 1040)"); - foreach (var data in propertyData) + if (!string.IsNullOrEmpty(data.Text)) { - if (!string.IsNullOrEmpty(data.Text)) + //var cs = ApplicationContext.Current.Services.ContentService; + + //fetch the current data (that's in xml format) + var xml = new XmlDocument(); + xml.LoadXml(data.Text); + + if (xml != null) { - //var cs = ApplicationContext.Current.Services.ContentService; + var links = new List(); - //fetch the current data (that's in xml format) - var xml = new XmlDocument(); - xml.LoadXml(data.Text); - - if (xml != null) + //loop all the stored links + foreach (XmlNode node in xml.DocumentElement.ChildNodes) { - var links = new List(); + var title = node.Attributes["title"].Value; + var type = node.Attributes["type"].Value; + var newwindow = node.Attributes["newwindow"].Value.Equals("1") ? true : false; + var lnk = node.Attributes["link"].Value; - //loop all the stored links - foreach (XmlNode node in xml.DocumentElement.ChildNodes) - { - var title = node.Attributes["title"].Value; - var type = node.Attributes["type"].Value; - var newwindow = node.Attributes["newwindow"].Value.Equals("1") ? true : false; - var lnk = node.Attributes["link"].Value; + //create the links in the format the new prop editor expects it to be + var link = new ExpandoObject() as IDictionary; + link.Add("title", title); + link.Add("caption", title); + link.Add("link", lnk); + link.Add("newWindow", newwindow); + link.Add("type", type.Equals("internal") ? "internal" : "external"); + link.Add("internal", type.Equals("internal") ? lnk : null); - //create the links in the format the new prop editor expects it to be - var link = new ExpandoObject() as IDictionary; - link.Add("title", title); - link.Add("caption", title); - link.Add("link", lnk); - link.Add("newWindow", newwindow); - link.Add("type", type.Equals("internal") ? "internal" : "external"); - link.Add("internal", type.Equals("internal") ? lnk : null); - - link.Add("edit", false); - link.Add("isInternal", type.Equals("internal")); + link.Add("edit", false); + link.Add("isInternal", type.Equals("internal")); - //try - //{ - // if (type.Equals("internal")) - // { - // int nodeId; - // if (int.TryParse(lnk, out nodeId)) - // link.Add("internalName", cs.GetById(nodeId).Name); - // } - //} - //catch (Exception ex) - //{ - // LogHelper.Error("Exception was thrown when trying to update related links property data, fetching internal node id", ex); - //} - - links.Add((ExpandoObject) link); - } - - //store the serialized data - data.Text = JsonConvert.SerializeObject(links); - - database.Update(data); + links.Add((ExpandoObject)link); } + + //store the serialized data + data.Text = JsonConvert.SerializeObject(links); + + database.Update(data); } } } - catch (Exception ex) - { - LogHelper.Error("Exception was thrown when trying to update related links property data", ex); - } } return string.Empty; } diff --git a/src/Umbraco.Web/Install/InstallException.cs b/src/Umbraco.Web/Install/InstallException.cs index 51c9b39938..a9f254e921 100644 --- a/src/Umbraco.Web/Install/InstallException.cs +++ b/src/Umbraco.Web/Install/InstallException.cs @@ -26,5 +26,19 @@ namespace Umbraco.Web.Install View = view; ViewModel = viewModel; } + + public InstallException(string message, object viewModel) + { + _message = message; + View = "error"; + ViewModel = viewModel; + } + + public InstallException(string message) + { + _message = message; + View = "error"; + ViewModel = null; + } } } diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs index 982d9b76ab..f9ba3fd69b 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs @@ -37,7 +37,7 @@ namespace Umbraco.Web.Install.InstallSteps if (dbHelper.CheckConnection(database, _applicationContext) == false) { - throw new InvalidOperationException("Could not connect to the database"); + throw new InstallException("Could not connect to the database"); } ConfigureConnection(database); return null; diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs index ed2b0234ec..fe3725e45d 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs @@ -25,11 +25,7 @@ namespace Umbraco.Web.Install.InstallSteps if (result.Success == false) { - return new InstallSetupResult("error", - new - { - message = "The database failed to install. ERROR: " + result.Message - }); + throw new InstallException("The database failed to install. ERROR: " + result.Message); } if (result.RequiresUpgrade == false) diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs index a596c9cadd..467142a580 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -34,11 +34,7 @@ namespace Umbraco.Web.Install.InstallSteps if (result.Success == false) { - return new InstallSetupResult("error", - new - { - message = "The database failed to upgrade. ERROR: " + result.Message - }); + throw new InstallException("The database failed to upgrade. ERROR: " + result.Message); } DatabaseInstallStep.HandleConnectionStrings(); diff --git a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs index eeb21fb05d..5575c4b172 100644 --- a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs @@ -27,14 +27,7 @@ namespace Umbraco.Web.Install.InstallSteps public override InstallSetupResult Execute(object model) { // Update configurationStatus - try - { - GlobalSettings.ConfigurationStatus = UmbracoVersion.Current.ToString(3); - } - catch (Exception ex) - { - LogHelper.Error("An error occurred updating the config status", ex); - } + GlobalSettings.ConfigurationStatus = UmbracoVersion.Current.ToString(3); // Update ClientDependency version var clientDependencyConfig = new ClientDependencyConfiguration(); diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs index d1233a8c89..5167f6cf66 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs @@ -53,11 +53,11 @@ namespace Umbraco.Web.Install.InstallSteps var repo = global::umbraco.cms.businesslogic.packager.repositories.Repository.getByGuid(RepoGuid); if (repo == null) { - throw new InvalidOperationException("No repository found with id " + RepoGuid); + throw new InstallException("No repository found with id " + RepoGuid); } if (repo.HasConnection() == false) { - throw new InvalidOperationException("Cannot connect to repository"); + throw new InstallException("Cannot connect to repository"); } var installer = new Installer();