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 Feb 29, 2024
1 parent eff25b5 commit 8653e1e
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())

Check notice on line 2064 in src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

✅ No longer an issue: Complex Conditional

PostPublishByIdAndCulture no longer has a complex conditional. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.

Check notice on line 2064 in src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

✅ No longer an issue: Complex Method

PostPublishByIdAndCulture is no longer above the threshold for cyclomatic complexity. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
{
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)

Check notice on line 2325 in src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

✅ Getting better: Complex Method

PostUnpublish decreases in cyclomatic complexity from 13 to 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
{
//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;

Check warning on line 2936 in src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

❌ Getting worse: Complex Method

AddMessageForPublishStatus increases in cyclomatic complexity from 36 to 38, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
default:
throw new IndexOutOfRangeException($"PublishedResultType \"{status.Key}\" was not expected.");
}
Expand Down

0 comments on commit 8653e1e

Please sign in to comment.