Fixes U4-1863 and U4-1908 by ensuring that content and media are loaded in the same manner through the new api

This commit is contained in:
Morten Christensen
2013-03-13 18:55:25 -01:00
parent 2fdcb9164a
commit 8fba03c05d
4 changed files with 10 additions and 30 deletions

View File

@@ -8,25 +8,17 @@ namespace Umbraco.Core.Persistence.Factories
{
internal class PropertyFactory : IEntityFactory<IEnumerable<Property>, IEnumerable<PropertyDataDto>>
{
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<IContent,PropertyDataDto>
public IEnumerable<Property> BuildEntity(IEnumerable<PropertyDataDto> dtos)
@@ -98,22 +90,5 @@ namespace Umbraco.Core.Persistence.Factories
}
#endregion
public IEnumerable<Property> BuildMediaEntity(IEnumerable<PropertyDataDto> dtos)
{
var properties = new List<Property>();
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;
}
}
}

View File

@@ -347,7 +347,7 @@ namespace Umbraco.Core.Persistence.Repositories
var propertyDataDtos = Database.Fetch<PropertyDataDto, PropertyTypeDto>(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)

View File

@@ -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");

View File

@@ -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<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId",