From 8fba03c05d3aca5f56b45e34bf501e87b6ecef7b Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Wed, 13 Mar 2013 18:55:25 -0100 Subject: [PATCH] Fixes U4-1863 and U4-1908 by ensuring that content and media are loaded in the same manner through the new api --- .../Persistence/Factories/PropertyFactory.cs | 29 ++----------------- .../Repositories/MediaRepository.cs | 2 +- .../umbraco/editContent.aspx.cs | 2 +- .../umbraco/editMedia.aspx.cs | 7 ++++- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index 9efa544768..623e770525 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -8,25 +8,17 @@ namespace Umbraco.Core.Persistence.Factories { internal class PropertyFactory : IEntityFactory, IEnumerable> { - private readonly IContentType _contentType; - private readonly IMediaType _mediaType; + private readonly IContentTypeComposition _contentType; private readonly Guid _version; private readonly int _id; - public PropertyFactory(IContentType contentType, Guid version, int id) + public PropertyFactory(IContentTypeComposition contentType, Guid version, int id) { _contentType = contentType; _version = version; _id = id; } - public PropertyFactory(IMediaType mediaType, Guid version, int id) - { - _mediaType = mediaType; - _version = version; - _id = id; - } - #region Implementation of IEntityFactory public IEnumerable BuildEntity(IEnumerable dtos) @@ -98,22 +90,5 @@ namespace Umbraco.Core.Persistence.Factories } #endregion - - public IEnumerable BuildMediaEntity(IEnumerable dtos) - { - var properties = new List(); - foreach (var dto in dtos) - { - if (_mediaType.CompositionPropertyTypes.Any(x => x.Id == dto.PropertyTypeId)) - { - var propertyType = _mediaType.CompositionPropertyTypes.First(x => x.Id == dto.PropertyTypeId); - var property = propertyType.CreatePropertyFromRawValue(dto.GetValue, dto.VersionId.Value, dto.Id); - - property.ResetDirtyProperties(); - properties.Add(property); - } - } - return properties; - } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs index 3e2152e37c..08cc4fb2b3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MediaRepository.cs @@ -347,7 +347,7 @@ namespace Umbraco.Core.Persistence.Repositories var propertyDataDtos = Database.Fetch(sql); var propertyFactory = new PropertyFactory(contentType, versionId, id); - var properties = propertyFactory.BuildMediaEntity(propertyDataDtos); + var properties = propertyFactory.BuildEntity(propertyDataDtos); var newProperties = properties.Where(x => x.HasIdentity == false); foreach (var property in newProperties) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index e136cd05a3..7371da9160 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -45,7 +45,7 @@ namespace umbraco.cms.presentation //validate! int id; - if (!int.TryParse(Request.QueryString["id"], out id)) + if (int.TryParse(Request.QueryString["id"], out id) == false) { //if this is invalid show an error this.DisplayFatalError("Invalid query string"); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs index 0cf950be91..2c770738e2 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs @@ -2,6 +2,7 @@ using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; +using Umbraco.Core; using umbraco.cms.businesslogic.datatype.controls; using System.Collections.Generic; using System.Linq; @@ -40,7 +41,11 @@ namespace umbraco.cms.presentation InitializeComponent(); base.OnInit(e); - _media = new cms.businesslogic.media.Media(int.Parse(Request.QueryString["id"])); + int id = int.Parse(Request.QueryString["id"]); + + //Loading Media via new public service to ensure that the Properties are loaded correct + var media = ApplicationContext.Current.Services.MediaService.GetById(id); + _media = new cms.businesslogic.media.Media(media); // Save media on first load bool exists = SqlHelper.ExecuteScalar("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId",