diff --git a/Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs b/Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs index 7b54e343..845008fa 100644 --- a/Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs +++ b/Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs @@ -20,7 +20,14 @@ abstract public class ContentTypeBaseSerializer : SyncBaseSerializer, ISyn internal IContentTypeService _contentTypeService; internal IDataTypeService _dataTypeService; internal IMemberTypeService _memberTypeService; - internal IEntityService _entityService; + internal IEntityService _entityService; + + // all content/media cached lists - they are used when + // creating new properties to make sure we don't YSOD the site. + // + private List _allContentTypes; + private List _allMediaTypes; + public ContentTypeBaseSerializer(string itemType): base(itemType) { @@ -138,8 +145,13 @@ internal void DeserializeStructure(IContentTypeBase item, XElement node) item.AllowedContentTypes = allowedTypes; } - internal void DeserializeProperties(IContentTypeBase item, XElement node) + internal string DeserializeProperties(IContentTypeBase item, XElement node) { + string message = ""; + // clear our type cache, we use it to check for clashes in compistions. + _allMediaTypes = null; + _allContentTypes = null; + List propertiesToRemove = new List(); Dictionary propertiesToMove = new Dictionary(); Dictionary tabsToBlank = new Dictionary(); @@ -191,10 +203,20 @@ internal void DeserializeProperties(IContentTypeBase item, XElement node) if (property == null) { - // create the property - LogHelper.Debug("Creating new Property: {0} {1}", ()=> item.Alias, ()=> alias); - property = new PropertyType(dataTypeDefinition, alias); - newProperty = true; + // for doctypes we need to check the compositions, we cant create a property here + // that exists further down the composition tree. + + if (CanCreateProperty(item, alias)) + { + LogHelper.Debug("Creating new Property: {0} {1}", () => item.Alias, () => alias); + property = new PropertyType(dataTypeDefinition, alias); + newProperty = true; + } + else + { + message = string.Format("Property: {0} was not created because of clash (try running import again)", alias); + } + } if (property != null) @@ -353,6 +375,8 @@ internal void DeserializeProperties(IContentTypeBase item, XElement node) } } + return message; + } internal void DeserializeTabSortOrder(IContentTypeBase item, XElement node) @@ -616,6 +640,42 @@ private IContentTypeBase LookupByAlias(string alias) return item; } + + + /// + /// does a check to see that no doctype/media type below + /// what we are looking at has the property we want to + /// create, if it doesn, we warn and carry on. a double + /// import fixes this + /// + /// + /// + private bool CanCreateProperty(IContentTypeBase item, string alias) + { + bool canCreate = true; + + switch (_itemType) + { + case Constants.Packaging.DocumentTypeNodeName: + if (_allContentTypes == null) + _allContentTypes = _contentTypeService.GetAllContentTypes().ToList(); + + var allProperties = _allContentTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == item.Id)).Select(x => x.PropertyTypes); + if (allProperties.Any(x => x.Any(y => y.Alias == alias))) + canCreate = false; + break; + case "MediaType": + if (_allMediaTypes == null) + _allMediaTypes = _contentTypeService.GetAllMediaTypes().ToList(); + + var allMediaProperties = _allMediaTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == item.Id)).Select(x => x.PropertyTypes); + if (allMediaProperties.Any(x => x.Any(y => y.Alias == alias))) + canCreate = false; + break; + } + return canCreate; + + } #endregion } diff --git a/Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs b/Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs index 2cf469f6..a72bdb37 100644 --- a/Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs +++ b/Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs @@ -112,7 +112,7 @@ internal override SyncAttempt DeserializeCore(XElement node) // _contentTypeService.Save(item); // Update Properties - DeserializeProperties((IContentTypeBase)item, node); + var msg = DeserializeProperties((IContentTypeBase)item, node); // Update Tabs DeserializeTabSortOrder((IContentTypeBase)item, node); @@ -143,7 +143,7 @@ internal override SyncAttempt DeserializeCore(XElement node) // structure twice. // DeserializeStructure((IContentTypeBase)item, node); - return SyncAttempt.Succeed(item.Name, item, ChangeType.Import); + return SyncAttempt.Succeed(item.Name, item, ChangeType.Import, msg); } private int GetContentFolders(XElement info, IContentType item) diff --git a/Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs b/Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs index f3600d0f..62a2552f 100644 --- a/Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs +++ b/Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs @@ -94,7 +94,7 @@ internal override SyncAttempt DeserializeCore(XElement node) item.SetLazyParentId(new Lazy(() => parentId)); } - DeserializeProperties(item, node); + var msg = DeserializeProperties(item, node); DeserializeTabSortOrder(item, node); @@ -103,7 +103,7 @@ internal override SyncAttempt DeserializeCore(XElement node) _contentTypeService.Save(item); - return SyncAttempt.Succeed(item.Name, item, ChangeType.Import); + return SyncAttempt.Succeed(item.Name, item, ChangeType.Import, msg); } private int GetMediaFolders(XElement info, IMediaType item) diff --git a/Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs b/Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs index 54b529c0..3cc7161d 100644 --- a/Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs +++ b/Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs @@ -58,13 +58,13 @@ internal override SyncAttempt DeserializeCore(XElement node) DeserializeBase(item, info); - DeserializeProperties(item, node); + var msg = DeserializeProperties(item, node); DeserializeTabSortOrder(item, node); _memberTypeService.Save(item); - return SyncAttempt.Succeed(item.Name, item, ChangeType.Import); + return SyncAttempt.Succeed(item.Name, item, ChangeType.Import, msg); } internal override SyncAttempt SerializeCore(IMemberType item) diff --git a/umbPackage/uSync.BackOffice/Jumoo.uSync.Core.dll b/umbPackage/uSync.BackOffice/Jumoo.uSync.Core.dll index 9c4ec079..b40f6763 100644 Binary files a/umbPackage/uSync.BackOffice/Jumoo.uSync.Core.dll and b/umbPackage/uSync.BackOffice/Jumoo.uSync.Core.dll differ diff --git a/umbPackage/uSync.Core/Jumoo.uSync.Core.dll b/umbPackage/uSync.Core/Jumoo.uSync.Core.dll index 9c4ec079..b40f6763 100644 Binary files a/umbPackage/uSync.Core/Jumoo.uSync.Core.dll and b/umbPackage/uSync.Core/Jumoo.uSync.Core.dll differ