From ba9aa49b91165e03951c3d3e632e511df0ebb923 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 7 May 2019 19:44:41 +0200 Subject: [PATCH] Fix user for v7 migration --- src/Umbraco.Core/Models/Membership/User.cs | 1 - src/Umbraco.Core/Persistence/Factories/UserFactory.cs | 7 +++++++ .../Repositories/Implement/UserRepository.cs | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 2fb293c349..3d071b0a18 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -54,7 +54,6 @@ namespace Umbraco.Core.Models.Membership _isLockedOut = false; _startContentIds = new int[] { }; _startMediaIds = new int[] { }; - } /// diff --git a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs index dae70d502f..c64eb14bb7 100644 --- a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs @@ -36,6 +36,13 @@ namespace Umbraco.Core.Persistence.Factories user.InvitedDate = dto.InvitedDate; user.TourData = dto.TourData; + // we should never get user with ID zero from database, except + // when upgrading from v7 - mark that user so that we do not + // save it back to database (as that would create a *new* user) + // see also: UserRepository.PersistNewItem + if (dto.Id == 0) + user.AdditionalData["IS_V7_ZERO"] = true; + // reset dirty initial properties (U4-1946) user.ResetDirtyProperties(false); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs index 9027e9269c..91a20c5bdd 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs @@ -434,6 +434,17 @@ ORDER BY colName"; protected override void PersistNewItem(IUser entity) { + // the use may have no identity, ie ID is zero, and be v7 super + // user - then it has been marked - and we must not persist it + // as new, as we do not want to create a new user - instead, persist + // it as updated + // see also: UserFactory.BuildEntity + if (((User) entity).AdditionalData.ContainsKey("IS_V7_ZERO")) + { + PersistUpdatedItem(entity); + return; + } + ((User) entity).AddingEntity(); // ensure security stamp if missing