From 25f91cc0da7fd0eb8313e72ecb9d7d964469b0f1 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 24 Jan 2013 13:49:41 -0100 Subject: [PATCH] Fixes U4-1534 so documents containing the tag datatype is properly copied. Copying a document with a Tags datatype on it would only work if a new TagRelationship is created. --- src/Umbraco.Core/Models/Content.cs | 6 +++++ src/Umbraco.Core/Models/EntityBase/Entity.cs | 2 +- src/Umbraco.Core/Services/ContentService.cs | 23 +++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 61cb495679..218d8be580 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -312,6 +312,12 @@ namespace Umbraco.Core.Models clone.Version = Guid.NewGuid(); clone.ResetIdentity(); + foreach (var property in clone.Properties) + { + property.ResetIdentity(); + property.Version = clone.Version; + } + return clone; } diff --git a/src/Umbraco.Core/Models/EntityBase/Entity.cs b/src/Umbraco.Core/Models/EntityBase/Entity.cs index 18ceff06ad..6c081ea0b4 100644 --- a/src/Umbraco.Core/Models/EntityBase/Entity.cs +++ b/src/Umbraco.Core/Models/EntityBase/Entity.cs @@ -85,7 +85,7 @@ namespace Umbraco.Core.Models.EntityBase } } - protected void ResetIdentity() + internal virtual void ResetIdentity() { _hasIdentity = false; _id = default(int); diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index fb8a3168ed..67e0982019 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -791,9 +791,8 @@ namespace Umbraco.Core.Services var copy = ((Content)content).Clone(); copy.ParentId = parentId; - // A copy should never be set to published - // automatically even if the original was - this.UnPublish(copy, userId); + // A copy should never be set to published automatically even if the original was. + copy.ChangePublishedState(PublishedState.Unpublished); if (Copying.IsRaisedEventCancelled(new CopyEventArgs(content, copy, parentId), this)) return null; @@ -806,14 +805,15 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(copy); uow.Commit(); - var uploadFieldId = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c"); - if (content.Properties.Any(x => x.PropertyType.DataTypeId == uploadFieldId)) + //Special case for the Upload DataType + var uploadDataTypeId = new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c"); + if (content.Properties.Any(x => x.PropertyType.DataTypeId == uploadDataTypeId)) { bool isUpdated = false; var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); //Loop through properties to check if the content contains media that should be deleted - foreach (var property in content.Properties.Where(x => x.PropertyType.DataTypeId == uploadFieldId + foreach (var property in content.Properties.Where(x => x.PropertyType.DataTypeId == uploadDataTypeId && string.IsNullOrEmpty(x.Value.ToString()) == false)) { if (fs.FileExists(IOHelper.MapPath(property.Value.ToString()))) @@ -841,6 +841,17 @@ namespace Umbraco.Core.Services uow.Commit(); } } + + //Special case for the Tags DataType + var tagsDataTypeId = new Guid("4023e540-92f5-11dd-ad8b-0800200c9a66"); + if (content.Properties.Any(x => x.PropertyType.DataTypeId == tagsDataTypeId)) + { + var tags = uow.Database.Fetch("WHERE nodeId = @Id", new {Id = content.Id}); + foreach (var tag in tags) + { + uow.Database.Insert(new TagRelationshipDto {NodeId = copy.Id, TagId = tag.TagId}); + } + } } //NOTE This 'Relation' part should eventually be delegated to a RelationService