Skip to content

Commit 90aebde

Browse files
Paul JohnsonZeegaan
authored andcommitted
Cherry picked fix from v8 and updated test for v9
1 parent 54eeaed commit 90aebde

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ protected override void PersistNewItem(IContent entity)
553553
protected override void PersistUpdatedItem(IContent entity)
554554
{
555555
var isEntityDirty = entity.IsDirty();
556+
var editedSnapshot = entity.Edited;
556557

557558
// check if we need to make any database changes at all
558559
if ((entity.PublishedState == PublishedState.Published || entity.PublishedState == PublishedState.Unpublished)
@@ -659,6 +660,19 @@ protected override void PersistUpdatedItem(IContent entity)
659660
edited = true;
660661
}
661662

663+
// To establish the new value of "edited" we compare all properties publishedValue to editedValue and look
664+
// for differences.
665+
//
666+
// If we SaveAndPublish but the publish fails (e.g. already scheduled for release)
667+
// we have lost the publishedValue on IContent (in memory vs database) so we cannot correctly make that comparison.
668+
//
669+
// This is a slight change to behaviour, historically a publish, followed by change & save, followed by undo change & save
670+
// would change edited back to false.
671+
if (!publishing && editedSnapshot)
672+
{
673+
edited = true;
674+
}
675+
662676
if (entity.ContentType.VariesByCulture())
663677
{
664678
// names also impact 'edited'

src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,107 @@ public void Cannot_Publish_Content_Awaiting_Release()
13481348
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, published.Result);
13491349
}
13501350

1351+
[Test]
1352+
public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_True()
1353+
{
1354+
// Arrange
1355+
IContentService contentService = GetRequiredService<IContentService>();
1356+
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
1357+
1358+
IContentType contentType = new ContentTypeBuilder()
1359+
.WithId(0)
1360+
.AddPropertyType()
1361+
.WithAlias("header")
1362+
.WithValueStorageType(ValueStorageType.Integer)
1363+
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
1364+
.WithName("header")
1365+
.Done()
1366+
.WithContentVariation(ContentVariation.Nothing)
1367+
.Build();
1368+
1369+
contentTypeService.Save(contentType);
1370+
1371+
Content content = new ContentBuilder()
1372+
.WithId(0)
1373+
.WithName("Home")
1374+
.WithContentType(contentType)
1375+
.AddPropertyData()
1376+
.WithKeyValue("header", "Cool header")
1377+
.Done()
1378+
.Build();
1379+
1380+
contentService.SaveAndPublish(content);
1381+
1382+
content.Properties[0].SetValue("Foo", culture: string.Empty);
1383+
content.ContentSchedule.Add(DateTime.Now.AddHours(2), null);
1384+
contentService.Save(content);
1385+
1386+
// Act
1387+
var result = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
1388+
1389+
// Assert
1390+
Assert.Multiple(() =>
1391+
{
1392+
Assert.IsFalse(result.Success);
1393+
Assert.IsTrue(result.Content.Published);
1394+
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, result.Result);
1395+
1396+
// We changed property data
1397+
Assert.IsTrue(result.Content.Edited, "result.Content.Edited");
1398+
});
1399+
}
1400+
1401+
// V9 - Tests.Integration
1402+
[Test]
1403+
public void Failed_Publish_Should_Not_Update_Edited_State_When_Edited_False()
1404+
{
1405+
// Arrange
1406+
IContentService contentService = GetRequiredService<IContentService>();
1407+
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
1408+
1409+
IContentType contentType = new ContentTypeBuilder()
1410+
.WithId(0)
1411+
.AddPropertyType()
1412+
.WithAlias("header")
1413+
.WithValueStorageType(ValueStorageType.Integer)
1414+
.WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
1415+
.WithName("header")
1416+
.Done()
1417+
.WithContentVariation(ContentVariation.Nothing)
1418+
.Build();
1419+
1420+
contentTypeService.Save(contentType);
1421+
1422+
Content content = new ContentBuilder()
1423+
.WithId(0)
1424+
.WithName("Home")
1425+
.WithContentType(contentType)
1426+
.AddPropertyData()
1427+
.WithKeyValue("header", "Cool header")
1428+
.Done()
1429+
.Build();
1430+
1431+
contentService.SaveAndPublish(content);
1432+
1433+
content.ContentSchedule.Add(DateTime.Now.AddHours(2), null);
1434+
contentService.Save(content);
1435+
1436+
// Act
1437+
var result = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
1438+
1439+
// Assert
1440+
Assert.Multiple(() =>
1441+
{
1442+
Assert.IsFalse(result.Success);
1443+
Assert.IsTrue(result.Content.Published);
1444+
Assert.AreEqual(PublishResultType.FailedPublishAwaitingRelease, result.Result);
1445+
1446+
// We didn't change any property data
1447+
Assert.IsFalse(result.Content.Edited, "result.Content.Edited");
1448+
});
1449+
}
1450+
1451+
13511452
[Test]
13521453
public void Cannot_Publish_Culture_Awaiting_Release()
13531454
{
@@ -2151,7 +2252,7 @@ public void Can_Rollback_Version_On_Content()
21512252
ContentService.Save(rollback2);
21522253

21532254
Assert.IsTrue(rollback2.Published);
2154-
Assert.IsFalse(rollback2.Edited); // all changes cleared!
2255+
Assert.IsTrue(rollback2.Edited); // till edited, change of behaviour
21552256

21562257
Assert.AreEqual("Jane Doe", rollback2.GetValue<string>("author"));
21572258
Assert.AreEqual("Text Page 2 ReReUpdated", rollback2.Name);
@@ -2170,7 +2271,7 @@ public void Can_Rollback_Version_On_Content()
21702271
content.CopyFrom(rollto);
21712272
content.Name = rollto.PublishName; // must do it explicitely AND must pick the publish one!
21722273
ContentService.Save(content);
2173-
Assert.IsFalse(content.Edited);
2274+
Assert.IsTrue(content.Edited); //Still edited, change of behaviour
21742275
Assert.AreEqual("Text Page 2 ReReUpdated", content.Name);
21752276
Assert.AreEqual("Jane Doe", content.GetValue("author"));
21762277
}

0 commit comments

Comments
 (0)