diff --git a/uSync.Core/Serialization/Serializers/ContentSerializer.cs b/uSync.Core/Serialization/Serializers/ContentSerializer.cs index 7f44d2a2..6ace158c 100644 --- a/uSync.Core/Serialization/Serializers/ContentSerializer.cs +++ b/uSync.Core/Serialization/Serializers/ContentSerializer.cs @@ -402,6 +402,9 @@ protected override uSyncChange HandleTrashedState(IContent item, bool trashed) // if the item is trashed, then the change of it's parent // should restore it (as long as we do a move!) + // if this item is new but in the bin, we can't move it to the bin. + + contentService.Move(item, item.ParentId); // clean out any relations for this item (some versions of Umbraco don't do this on a Move) @@ -412,12 +415,16 @@ protected override uSyncChange HandleTrashedState(IContent item, bool trashed) } else if (trashed && !item.Trashed) { + // not already in the recycle bin? + if (item.ParentId > Constants.System.RecycleBinContent) + { + // clean any relations that may be there (stops an error) + CleanRelations(item, "relateParentDocumentOnDelete"); - // clean any relations that may be there (stops an error) - CleanRelations(item, "relateParentDocumentOnDelete"); + // move to the recycle bin + contentService.MoveToRecycleBin(item); + } - // move to the recycle bin - contentService.MoveToRecycleBin(item); return uSyncChange.Update("Moved to Bin", item.Name, "", "Recycle Bin"); } @@ -432,8 +439,9 @@ protected virtual Attempt DoSaveOrPublish(IContent item, XElement node, return Attempt.Succeed("No Changes"); } + var trashed = item.Trashed || (node.Element("Info")?.Element("Trashed").ValueOrDefault(false) ?? false); var publishedNode = node.Element("Info")?.Element("Published"); - if (!item.Trashed && publishedNode != null) + if (!trashed && publishedNode != null) { var schedules = GetSchedules(node.Element("Info")?.Element("Schedule")); diff --git a/uSync.Core/Serialization/Serializers/ContentSerializerBase.cs b/uSync.Core/Serialization/Serializers/ContentSerializerBase.cs index 0300a0d9..c6c30615 100644 --- a/uSync.Core/Serialization/Serializers/ContentSerializerBase.cs +++ b/uSync.Core/Serialization/Serializers/ContentSerializerBase.cs @@ -394,7 +394,17 @@ protected virtual IEnumerable DeserializeBase(TObject item, XElemen item.Level = nodeLevel; } } - + else // trashed. + { + // we need to set the parent to something, + // or the move will fail. + if (item.ParentId == -1) + { + item.ParentId = item is IContent + ? Constants.System.RecycleBinContent + : Constants.System.RecycleBinMedia; + } + } var key = node.GetKey(); if (key != Guid.Empty && item.Key != key) @@ -679,13 +689,17 @@ protected override Attempt FindOrCreate(XElement node) var alias = node.GetAlias(); - var parentKey = node.Attribute(uSyncConstants.Xml.Parent).ValueOrDefault(Guid.Empty); + var parentKey = node.Element(uSyncConstants.Xml.Info) + ?.Element(uSyncConstants.Xml.Parent) + ?.Attribute(uSyncConstants.Xml.Key) + .ValueOrDefault(Guid.Empty) ?? Guid.Empty; + if (parentKey != Guid.Empty) { item = FindItem(alias, parentKey); if (item != null) return Attempt.Succeed(item); } - + // create var parent = default(TObject);