Add handling of failed publish.
When publishing, if the selected page does not yet have a page created, handle the FailedPublishNothingToPublish error so that the user is not presented with an exception. A warning is shown to the user that some languages failed to publish due to nothing to publish and to check that a page has been created for selected languages. Additionally fixed a validation issue where publish would always succeed if all languages were selected. Issue: 15352
This commit is contained in:
committed by
Busra Sengul
parent
4f9c793d00
commit
0cf436fa5c
@@ -2061,7 +2061,7 @@ public class ContentController : ContentControllerBase
|
||||
var languageCount = _allLangs.Value.Count();
|
||||
|
||||
// If there is no culture specified or the cultures specified are equal to the total amount of languages, publish the content in all cultures.
|
||||
if (model.Cultures == null || !model.Cultures.Any() || model.Cultures.Length == languageCount)
|
||||
if (model.Cultures == null || !model.Cultures.Any())
|
||||
{
|
||||
return PostPublishById(model.Id);
|
||||
}
|
||||
@@ -2322,7 +2322,7 @@ public class ContentController : ContentControllerBase
|
||||
}
|
||||
|
||||
var languageCount = _allLangs.Value.Count();
|
||||
if (model.Cultures?.Length == 0 || model.Cultures?.Length == languageCount)
|
||||
if (model.Cultures?.Length == 0)
|
||||
{
|
||||
//this means that the entire content item will be unpublished
|
||||
PublishResult unpublishResult = _contentService.Unpublish(foundContent, userId: _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? -1);
|
||||
@@ -2786,6 +2786,7 @@ public class ContentController : ContentControllerBase
|
||||
case PublishResultType.FailedPublishIsTrashed:
|
||||
case PublishResultType.FailedPublishContentInvalid:
|
||||
case PublishResultType.FailedPublishMandatoryCultureMissing:
|
||||
case PublishResultType.FailedPublishNothingToPublish:
|
||||
//the rest that we are looking for each belong in their own group
|
||||
return x.Result;
|
||||
default:
|
||||
@@ -2928,6 +2929,11 @@ public class ContentController : ContentControllerBase
|
||||
_localizedTextService.Localize(null, "publish"),
|
||||
"publish/contentPublishedFailedByCulture");
|
||||
break;
|
||||
case PublishResultType.FailedPublishNothingToPublish:
|
||||
display.AddWarningNotification(
|
||||
_localizedTextService.Localize(null, "publish"),
|
||||
$"Nothing to publish for some languages. Ensure selected languages have a page created.");
|
||||
break;
|
||||
default:
|
||||
throw new IndexOutOfRangeException($"PublishedResultType \"{status.Key}\" was not expected.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user