diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs new file mode 100644 index 0000000000..abc312ab5d --- /dev/null +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Models.Rdbms; + +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixTwoZero +{ + [Migration("6.2.0", 2, GlobalSettings.UmbracoMigrationName)] + public class UpdateToNewMemberPropertyAliases : MigrationBase + { + public override void Up() + { + Execute.Code(Update); + } + + internal static string Update(Database database) + { + if (database != null) + { + var aliasMap = new Dictionary + { + {"umbracoPasswordRetrievalQuestionPropertyTypeAlias", Constants.Conventions.Member.PasswordQuestion}, + {"umbracoPasswordRetrievalAnswerPropertyTypeAlias", Constants.Conventions.Member.PasswordAnswer}, + {"umbracoCommentPropertyTypeAlias", Constants.Conventions.Member.Comments}, + {"umbracoApprovePropertyTypeAlias", Constants.Conventions.Member.IsApproved}, + {"umbracoLockPropertyTypeAlias", Constants.Conventions.Member.IsLockedOut}, + {"umbracoLastLoginPropertyTypeAlias", Constants.Conventions.Member.LastLoginDate}, + {"umbracoMemberLastPasswordChange", Constants.Conventions.Member.LastPasswordChangeDate}, + {"umbracoMemberLastLockout", Constants.Conventions.Member.LastLockoutDate}, + {"umbracoFailedPasswordAttemptsPropertyTypeAlias", Constants.Conventions.Member.FailedPasswordAttempts} + }; + + const string propertyTypeUpdateSql = @"UPDATE cmsPropertyType +SET Alias = @newAlias +WHERE Alias = @oldAlias AND contentTypeId IN ( +SELECT DISTINCT cmsContentType.nodeId FROM cmsPropertyType +INNER JOIN cmsContentType ON cmsPropertyType.contentTypeId = cmsContentType.nodeId +INNER JOIN umbracoNode ON cmsContentType.nodeId = umbracoNode.id +WHERE umbracoNode.nodeObjectType = @objectType)"; + + const string xmlSelectSql = @"SELECT cmsContentXml.* FROM cmsContentXml +INNER JOIN umbracoNode ON cmsContentXml.nodeId = umbracoNode.id +WHERE umbracoNode.nodeObjectType = @objectType"; + + using (var trans = database.GetTransaction()) + { + try + { + + //Upate all of the property type aliases + foreach (var map in aliasMap) + { + database.Execute(propertyTypeUpdateSql, new { newAlias = map.Value, oldAlias = map.Key, objectType = Constants.ObjectTypes.MemberType }); + } + + //Update all of the XML + var items = database.Fetch(xmlSelectSql, new { objectType = Constants.ObjectTypes.Member }); + foreach (var item in items) + { + foreach (var map in aliasMap) + { + item.Xml = item.Xml.Replace("<" + map.Key + ">", "<" + map.Value + ">"); + item.Xml = item.Xml.Replace("", ""); + } + database.Update(item); + } + + trans.Complete(); + } + catch (Exception ex) + { + LogHelper.Error("Exception was thrown when trying to upgrade old member aliases to the new ones", ex); + throw; + } + } + + + } + return string.Empty; + } + + public override void Down() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6c1701b424..4928431771 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -358,6 +358,7 @@ + diff --git a/src/Umbraco.Web/Controllers/UmbLoginController.cs b/src/Umbraco.Web/Controllers/UmbLoginController.cs index 63a69032ee..3ae00f6970 100644 --- a/src/Umbraco.Web/Controllers/UmbLoginController.cs +++ b/src/Umbraco.Web/Controllers/UmbLoginController.cs @@ -32,9 +32,9 @@ namespace Umbraco.Web.Controllers } //redirect to current page by default - TempData.Add("LoginSuccess", true); - //return RedirectToCurrentUmbracoPage(); - return RedirectToCurrentUmbracoUrl(); + TempData["LoginSuccess"] = true; + return RedirectToCurrentUmbracoPage(); + //return RedirectToCurrentUmbracoUrl(); } } } diff --git a/src/Umbraco.Web/Controllers/UmbLoginStatusController.cs b/src/Umbraco.Web/Controllers/UmbLoginStatusController.cs index fb71c6ef14..457ed77767 100644 --- a/src/Umbraco.Web/Controllers/UmbLoginStatusController.cs +++ b/src/Umbraco.Web/Controllers/UmbLoginStatusController.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.Controllers } //redirect to current page by default - TempData.Add("LogoutSuccess", true); + TempData["LogoutSuccess"] = true; return RedirectToCurrentUmbracoPage(); } } diff --git a/src/Umbraco.Web/Controllers/UmbProfileController.cs b/src/Umbraco.Web/Controllers/UmbProfileController.cs index 701e34ea23..8e38bd5282 100644 --- a/src/Umbraco.Web/Controllers/UmbProfileController.cs +++ b/src/Umbraco.Web/Controllers/UmbProfileController.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.Controllers } //redirect to current page by default - TempData.Add("ProfileUpdateSuccess", true); + TempData["ProfileUpdateSuccess"] = true; return RedirectToCurrentUmbracoPage(); } } diff --git a/src/Umbraco.Web/Controllers/UmbRegisterController.cs b/src/Umbraco.Web/Controllers/UmbRegisterController.cs index d876df7f6e..7a8817031b 100644 --- a/src/Umbraco.Web/Controllers/UmbRegisterController.cs +++ b/src/Umbraco.Web/Controllers/UmbRegisterController.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.Controllers return Redirect(model.RedirectUrl); } //redirect to current page by default - TempData.Add("FormSuccess", true); + TempData["FormSuccess"] = true; return RedirectToCurrentUmbracoPage(); case MembershipCreateStatus.InvalidUserName: ModelState.AddModelError((model.UsernameIsEmail || model.Username == null) diff --git a/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs b/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs index 6fb3610411..e205966f78 100644 --- a/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs +++ b/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs @@ -8,43 +8,6 @@ using Umbraco.Web.Routing; namespace Umbraco.Web.Mvc { /// - /// Redirects to the current URL rendering an Umbraco page - /// - /// - /// this is useful if you need to redirect - /// to the current page but the current page is actually a rewritten URL normally done with something like - /// Server.Transfer. - /// - public class RedirectToUmbracoUrlResult : ActionResult - { - private readonly UmbracoContext _umbracoContext; - - /// - /// Creates a new RedirectToUmbracoResult - /// - /// - public RedirectToUmbracoUrlResult(UmbracoContext umbracoContext) - { - _umbracoContext = umbracoContext; - } - - public override void ExecuteResult(ControllerContext context) - { - if (context == null) throw new ArgumentNullException("context"); - - if (context.IsChildAction) - { - throw new InvalidOperationException("Cannot redirect from a Child Action"); - } - - var destinationUrl = _umbracoContext.OriginalRequestUrl.PathAndQuery; - context.Controller.TempData.Keep(); - - context.HttpContext.Response.Redirect(destinationUrl, endResponse: false); - } - } - - /// /// Redirects to an Umbraco page by Id or Entity /// public class RedirectToUmbracoPageResult : ActionResult diff --git a/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs b/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs new file mode 100644 index 0000000000..fc472c0255 --- /dev/null +++ b/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs @@ -0,0 +1,42 @@ +using System; +using System.Web.Mvc; + +namespace Umbraco.Web.Mvc +{ + /// + /// Redirects to the current URL rendering an Umbraco page + /// + /// + /// this is useful if you need to redirect + /// to the current page but the current page is actually a rewritten URL normally done with something like + /// Server.Transfer. + /// + public class RedirectToUmbracoUrlResult : ActionResult + { + private readonly UmbracoContext _umbracoContext; + + /// + /// Creates a new RedirectToUmbracoResult + /// + /// + public RedirectToUmbracoUrlResult(UmbracoContext umbracoContext) + { + _umbracoContext = umbracoContext; + } + + public override void ExecuteResult(ControllerContext context) + { + if (context == null) throw new ArgumentNullException("context"); + + if (context.IsChildAction) + { + throw new InvalidOperationException("Cannot redirect from a Child Action"); + } + + var destinationUrl = _umbracoContext.OriginalRequestUrl.PathAndQuery; + context.Controller.TempData.Keep(); + + context.HttpContext.Response.Redirect(destinationUrl, endResponse: false); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 872b87ef80..333dc6f598 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -342,6 +342,7 @@ +