Skip to content

Commit

Permalink
Add handling of failed publish.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nagolucky18 authored and busrasengul committed Mar 1, 2024
1 parent 4f9c793 commit 0cf436f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ public IActionResult PostPublishByIdAndCulture(PublishContent model)
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);
}
Expand Down Expand Up @@ -2322,7 +2322,7 @@ public async Task<IActionResult> PostSort(ContentSortOrder sorted)
}

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);
Expand Down Expand Up @@ -2786,6 +2786,7 @@ private void AddMessageForPublishStatus(IReadOnlyCollection<PublishResult> statu
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:
Expand Down Expand Up @@ -2928,6 +2929,11 @@ private void AddMessageForPublishStatus(IReadOnlyCollection<PublishResult> statu
_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.");
}
Expand Down

0 comments on commit 0cf436f

Please sign in to comment.