Skip to content

Commit

Permalink
Fix - Seperate out save from publish on content.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Apr 12, 2024
1 parent 3e332cf commit ed22cea
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions uSync.Core/Serialization/Serializers/ContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ private static ContentSchedule GetContentScheduleFromNode(XElement scheduleNode)
{
var schedules = GetSchedules(node.Element("Info")?.Element("Schedule"));

ContentScheduleCollection scheduleCollection = new ContentScheduleCollection();
foreach(var schedule in schedules)
{
scheduleCollection.Add(schedule);
}

// v14 we always save now, as save and publish doesn't do that anymore...
contentService.Save(item, options.UserId, scheduleCollection);

if (publishedNode.HasElements)
{
// culture based publishing.
Expand Down Expand Up @@ -498,7 +507,6 @@ private static ContentSchedule GetContentScheduleFromNode(XElement scheduleNode)
}
}

this.SaveItem(item, options.UserId);
return Attempt.Succeed("Saved");
}

Expand All @@ -524,7 +532,7 @@ private static List<ContentSchedule> GetSchedules(XElement? schedulesNode)
try
{
logger.LogDebug("Publishing: {item} as User:{user}", item.Name, userId);
var result = contentService.SaveAndPublish(item, userId: userId);
var result = contentService.Publish(item, cultures: [], userId: userId);
if (!result.Success)
{
var messages = result.EventMessages?.FormatMessages(",");
Expand Down Expand Up @@ -559,8 +567,6 @@ private static List<ContentSchedule> GetSchedules(XElement? schedulesNode)

try
{
var hasBeenSaved = false;

var publishedCultures = cultures
.Where(x => x.Value == uSyncContentState.Published)
.Select(x => x.Key)
Expand All @@ -571,7 +577,7 @@ private static List<ContentSchedule> GetSchedules(XElement? schedulesNode)
logger.LogDebug("Publishing {item} as {user} for {cultures}", item.Name, userId,
string.Join(",", publishedCultures));

var result = contentService.SaveAndPublish(item, publishedCultures, userId);
var result = contentService.Publish(item, publishedCultures, userId);

// if this fails, we return the result
if (!result.Success)
Expand All @@ -585,9 +591,6 @@ private static List<ContentSchedule> GetSchedules(XElement? schedulesNode)

return result.ToAttempt();
}

// if its published here it's also saved, so we can skip the save below.
hasBeenSaved = true;
}

var unpublishedCultures = cultures
Expand All @@ -612,17 +615,9 @@ private static List<ContentSchedule> GetSchedules(XElement? schedulesNode)
}
}


if (unpublishMissing)
UnpublishMissingCultures(item, cultures.Select(x => x.Key).ToArray());

// if we get to this point and no save has been called, we should call it.
if (!hasBeenSaved && item.IsDirty())
{
logger.LogDebug("Saving {item} because we didn't publish it", item.Name);
contentService.Save(item);
}

return Attempt.Succeed("Done");
}
catch (ArgumentNullException ex)
Expand Down

0 comments on commit ed22cea

Please sign in to comment.