Skip to content

Commit 4c6e014

Browse files
authored
Merge pull request #11356 from umbraco/v8/bugfix/fix-incorrect-edited-state-for-failed-publish-11290
[v8] Resolve incorrect ContentSavedState for failed publish
2 parents e36dd86 + f6f5723 commit 4c6e014

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ protected override void PersistNewItem(IContent entity)
520520
protected override void PersistUpdatedItem(IContent entity)
521521
{
522522
var isEntityDirty = entity.IsDirty();
523+
var editedSnapshot = entity.Edited;
523524

524525
// check if we need to make any database changes at all
525526
if ((entity.PublishedState == PublishedState.Published || entity.PublishedState == PublishedState.Unpublished)
@@ -621,6 +622,19 @@ protected override void PersistUpdatedItem(IContent entity)
621622
if (!publishing && entity.PublishName != entity.Name)
622623
edited = true;
623624

625+
// To establish the new value of "edited" we compare all properties publishedValue to editedValue and look
626+
// for differences.
627+
//
628+
// If we SaveAndPublish but the publish fails (e.g. already scheduled for release)
629+
// we have lost the publishedValue on IContent (in memory vs database) so we cannot correctly make that comparison.
630+
//
631+
// This is a slight change to behaviour, historically a publish, followed by change & save, followed by undo change & save
632+
// would change edited back to false.
633+
if (!publishing && editedSnapshot)
634+
{
635+
edited = true;
636+
}
637+
624638
if (entity.ContentType.VariesByCulture())
625639
{
626640
// bump dates to align cultures to version

src/Umbraco.Tests/Services/ContentServiceTests.cs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,65 @@ public void Cannot_Publish_Content_Awaiting_Release()
13751375
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, published.Result);
13761376
}
13771377

1378+
// V9 - Tests.Integration
1379+
[Test]
1380+
public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_True()
1381+
{
1382+
const int rootNodeId = NodeDto.NodeIdSeed + 2;
1383+
1384+
// Arrange
1385+
var contentService = ServiceContext.ContentService;
1386+
var content = contentService.GetById(rootNodeId);
1387+
contentService.SaveAndPublish(content);
1388+
1389+
content.Properties[0].SetValue("Foo", culture: string.Empty);
1390+
content.ContentSchedule.Add(DateTime.Now.AddHours(2), null);
1391+
contentService.Save(content);
1392+
1393+
// Act
1394+
var result = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
1395+
1396+
// Assert
1397+
Assert.Multiple(() =>
1398+
{
1399+
Assert.IsFalse(result.Success);
1400+
Assert.IsTrue(result.Content.Published);
1401+
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, result.Result);
1402+
1403+
// We changed property data
1404+
Assert.IsTrue(result.Content.Edited, "result.Content.Edited");
1405+
});
1406+
}
1407+
1408+
// V9 - Tests.Integration
1409+
[Test]
1410+
public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_False()
1411+
{
1412+
const int rootNodeId = NodeDto.NodeIdSeed + 2;
1413+
1414+
// Arrange
1415+
var contentService = ServiceContext.ContentService;
1416+
var content = contentService.GetById(rootNodeId);
1417+
contentService.SaveAndPublish(content);
1418+
1419+
content.ContentSchedule.Add(DateTime.Now.AddHours(2), null);
1420+
contentService.Save(content);
1421+
1422+
// Act
1423+
var result = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
1424+
1425+
// Assert
1426+
Assert.Multiple(() =>
1427+
{
1428+
Assert.IsFalse(result.Success);
1429+
Assert.IsTrue(result.Content.Published);
1430+
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, result.Result);
1431+
1432+
// We didn't change any property data
1433+
Assert.IsFalse(result.Content.Edited, "result.Content.Edited");
1434+
});
1435+
}
1436+
13781437
[Test]
13791438
public void Cannot_Publish_Culture_Awaiting_Release()
13801439
{
@@ -2176,7 +2235,7 @@ public void Can_Rollback_Version_On_Content()
21762235
contentService.Save(rollback2);
21772236

21782237
Assert.IsTrue(rollback2.Published);
2179-
Assert.IsFalse(rollback2.Edited); // all changes cleared!
2238+
Assert.IsTrue(rollback2.Edited); // Still edited, change of behaviour
21802239

21812240
Assert.AreEqual("Jane Doe", rollback2.GetValue<string>("author"));
21822241
Assert.AreEqual("Text Page 2 ReReUpdated", rollback2.Name);
@@ -2195,7 +2254,7 @@ public void Can_Rollback_Version_On_Content()
21952254
content.CopyFrom(rollto);
21962255
content.Name = rollto.PublishName; // must do it explicitely AND must pick the publish one!
21972256
contentService.Save(content);
2198-
Assert.IsFalse(content.Edited);
2257+
Assert.IsTrue(content.Edited); // Still edited, change of behaviour
21992258
Assert.AreEqual("Text Page 2 ReReUpdated", content.Name);
22002259
Assert.AreEqual("Jane Doe", content.GetValue("author"));
22012260
}

0 commit comments

Comments
 (0)