Skip to content

Commit

Permalink
Fixes #548
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Oct 3, 2023
1 parent 2b845ff commit 0df4eeb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 13 additions & 5 deletions uSync.Core/Serialization/Serializers/ContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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)
Expand All @@ -367,12 +370,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");
}

Expand All @@ -387,8 +394,9 @@ protected virtual Attempt<string> 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"));

Expand Down
20 changes: 17 additions & 3 deletions uSync.Core/Serialization/Serializers/ContentSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,17 @@ protected virtual IEnumerable<uSyncChange> 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)
Expand Down Expand Up @@ -679,13 +689,17 @@ protected override Attempt<TObject> 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);

Expand Down

0 comments on commit 0df4eeb

Please sign in to comment.