Updating MediaRepository to not create versions for Media, and ensuring that properties are properly updated.

This commit is contained in:
Morten Christensen
2012-12-17 14:00:46 -01:00
parent 4d5d556e64
commit 9bf45d6031
3 changed files with 37 additions and 16 deletions

View File

@@ -108,15 +108,5 @@ namespace Umbraco.Core.Models
if (Key == Guid.Empty)
Key = Guid.NewGuid();
}
/// <summary>
/// Method to call when Entity is being updated
/// </summary>
/// <remarks>Modified Date is set and a new Version guid is set</remarks>
internal override void UpdatingEntity()
{
base.UpdatingEntity();
Version = Guid.NewGuid();
}
}
}

View File

@@ -342,6 +342,8 @@ namespace Umbraco.Core.Persistence.Repositories
//Create the PropertyData for this version - cmsPropertyData
var propertyFactory = new PropertyFactory(((Content)entity).ContentType, entity.Version, entity.Id);
var propertyDataDtos = propertyFactory.BuildDto(entity.Properties);
var keyDictionary = new Dictionary<int, int>();
//Add Properties
foreach (var propertyDataDto in propertyDataDtos)
{
@@ -351,7 +353,17 @@ namespace Umbraco.Core.Persistence.Repositories
}
else
{
Database.Insert(propertyDataDto);
int primaryKey = Convert.ToInt32(Database.Insert(propertyDataDto));
keyDictionary.Add(propertyDataDto.PropertyTypeId, primaryKey);
}
}
//Update Properties with its newly set Id
if (keyDictionary.Any())
{
foreach (var property in entity.Properties)
{
property.Id = keyDictionary[property.PropertyTypeId];
}
}

View File

@@ -231,7 +231,7 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistUpdatedItem(IMedia entity)
{
//Updates Modified date and Version Guid
//Updates Modified date
((Models.Media)entity).UpdatingEntity();
var factory = new MediaFactory(NodeObjectTypeId, entity.Id);
@@ -252,17 +252,36 @@ namespace Umbraco.Core.Persistence.Repositories
Database.Update(newContentDto);
}
//Create a new version - cmsContentVersion
//Assumes a new Version guid and Version date (modified date) has been set
Database.Insert(dto);
//Updates the current version - cmsContentVersion
//Assumes a Version guid exists and Version date (modified date) has been set/updated
Database.Update(dto);
//Create the PropertyData for this version - cmsPropertyData
var propertyFactory = new PropertyFactory(entity.ContentType, entity.Version, entity.Id);
var propertyDataDtos = propertyFactory.BuildDto(entity.Properties);
var keyDictionary = new Dictionary<int, int>();
//Add Properties
foreach (var propertyDataDto in propertyDataDtos)
{
Database.Insert(propertyDataDto);
if (propertyDataDto.Id > 0)
{
Database.Update(propertyDataDto);
}
else
{
int primaryKey = Convert.ToInt32(Database.Insert(propertyDataDto));
keyDictionary.Add(propertyDataDto.PropertyTypeId, primaryKey);
}
}
//Update Properties with its newly set Id
if (keyDictionary.Any())
{
foreach (var property in entity.Properties)
{
property.Id = keyDictionary[property.PropertyTypeId];
}
}
((ICanBeDirty)entity).ResetDirtyProperties();