Adds publish status for mixed unpublish/publish action in the same operation

This commit is contained in:
Shannon
2018-11-08 12:49:37 +11:00
parent d4bf5f7ab9
commit c4bce9ecb5
3 changed files with 59 additions and 9 deletions

View File

@@ -1002,11 +1002,8 @@ namespace Umbraco.Core.Services.Implement
publishResult = StrategyCanPublish(scope, content, userId, /*checkPath:*/ true, culturesPublishing, culturesUnpublishing, evtMsgs);
if (publishResult.Success)
{
// note: StrategyPublish flips the PublishedState to Publishing!
publishResult = StrategyPublish(scope, content, userId, culturesPublishing, culturesUnpublishing, evtMsgs);
}
else
{
@@ -2382,7 +2379,9 @@ namespace Umbraco.Core.Services.Implement
}
}
//TODO: If we are both publishing and unpublishing cultures, then there should be a status for that (mixed?)
//If we are both publishing and unpublishing cultures, then return a mixed status
if (variesByCulture && culturesPublishing.Count > 0 && culturesUnpublishing.Count > 0)
return new PublishResult(PublishResultType.SuccessMixedCulture, evtMsgs, content);
return new PublishResult(evtMsgs, content);
}
@@ -2409,15 +2408,23 @@ namespace Umbraco.Core.Services.Implement
//if this is a variant then we need to log which cultures have been published/unpublished and return an appropriate result
if (content.ContentType.VariesByCulture())
{
if (content.Published && culturesUnpublishing.Count == 0 && culturesPublishing.Count == 0)
return new PublishResult(PublishResultType.FailedPublishNothingToPublish, evtMsgs, content);
if (culturesUnpublishing.Count > 0)
{
Logger.Info<ContentService>("Document {ContentName} (id={ContentId}) cultures: {Cultures} have been unpublished.",
content.Name, content.Id, string.Join(",", culturesUnpublishing));
return new PublishResult(PublishResultType.SuccessUnpublishCulture, evtMsgs, content);
}
Logger.Info<ContentService>("Document {ContentName} (id={ContentId}) cultures: {Cultures} have been published.",
if (culturesPublishing.Count > 0)
Logger.Info<ContentService>("Document {ContentName} (id={ContentId}) cultures: {Cultures} have been published.",
content.Name, content.Id, string.Join(",", culturesPublishing));
if (culturesUnpublishing.Count > 0 && culturesPublishing.Count > 0)
return new PublishResult(PublishResultType.SuccessMixedCulture, evtMsgs, content);
if (culturesUnpublishing.Count > 0 && culturesPublishing.Count == 0)
return new PublishResult(PublishResultType.SuccessUnpublishCulture, evtMsgs, content);
return new PublishResult(PublishResultType.SuccessPublishCulture, evtMsgs, content);
}

View File

@@ -48,7 +48,15 @@
#endregion
//TODO: WE need something like SuccessPublishCultureMixed, FailedPublishCultureMixed - for when a culture is published and another is unpublished at the same time
#region Success - Mixed
/// <summary>
/// A variant content item has a culture published and another culture unpublished in the same operation
/// </summary>
SuccessMixedCulture = 7,
#endregion
#region Failed - Publish

View File

@@ -1554,6 +1554,41 @@ namespace Umbraco.Tests.Services
Assert.IsFalse(content.Published);
}
[Test]
public void Can_Publish_And_Unpublish_Cultures_In_Single_Operation()
{
var langFr = new Language("fr");
var langDa = new Language("da");
ServiceContext.LocalizationService.Save(langFr);
ServiceContext.LocalizationService.Save(langDa);
var ct = MockedContentTypes.CreateBasicContentType();
ct.Variations = ContentVariation.Culture;
ServiceContext.ContentTypeService.Save(ct);
IContent content = MockedContent.CreateBasicContent(ct);
content.SetCultureName("name-fr", langFr.IsoCode);
content.SetCultureName("name-da", langDa.IsoCode);
content.PublishCulture(langFr.IsoCode);
var result = ServiceContext.ContentService.SavePublishing(content);
Assert.IsTrue(result.Success);
content = ServiceContext.ContentService.GetById(content.Id);
Assert.IsTrue(content.IsCulturePublished(langFr.IsoCode));
Assert.IsFalse(content.IsCulturePublished(langDa.IsoCode));
content.UnpublishCulture(langFr.IsoCode);
content.PublishCulture(langDa.IsoCode);
result = ServiceContext.ContentService.SavePublishing(content);
Assert.IsTrue(result.Success);
Assert.AreEqual(PublishResultType.SuccessMixedCulture, result.Result);
content = ServiceContext.ContentService.GetById(content.Id);
Assert.IsFalse(content.IsCulturePublished(langFr.IsoCode));
Assert.IsTrue(content.IsCulturePublished(langDa.IsoCode));
}
// documents: an enumeration of documents, in tree order
// map: applies (if needed) PublishValue, returns a value indicating whether to proceed with the branch
private IEnumerable<IContent> MapPublishValues(IEnumerable<IContent> documents, Func<IContent, bool> map)