From 740dfcc5312168c61e1cfc19abb9493dce8c1011 Mon Sep 17 00:00:00 2001 From: nikolajlauridsen Date: Wed, 6 Oct 2021 12:26:18 +0200 Subject: [PATCH] Verify that published culture has domain --- .../Controllers/ContentController.cs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 63af3f4bc5..553bfd828c 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -1413,10 +1413,10 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers wasCancelled = publishStatus.Result == PublishResultType.FailedPublishCancelledByEvent; successfulCultures = culturesToPublish; - // Verify that there's appropriate cultures configured for the root nude + // Verify that there's appropriate cultures configured for the root node if (publishStatus.Success && contentItem.ParentId == -1) { - VerifyRootNodeDomainsForCultures(contentItem, publishStatus); + VerifyDomainsForCultures(contentItem.PersistedContent, publishStatus); } return publishStatus; } @@ -1431,18 +1431,17 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } } - private void VerifyRootNodeDomainsForCultures(ContentItemSave contentItemSave, PublishResult publishResult) + private void VerifyDomainsForCultures(IContent publishedContent, PublishResult publishResult) { - IContent persistedContent = contentItemSave.PersistedContent; - var publishedCultures = persistedContent.PublishedCultures.ToList(); + var publishedCultures = publishedContent.PublishedCultures.ToList(); // If only a single culture is published we shouldn't have any routing issues - if (publishedCultures.Count() < 2) + if (publishedCultures.Count < 2) { return; } // If more than a single culture is published we need to verify that there's a domain registered for each published culture - IEnumerable assignedDomains = _domainService.GetAssignedDomains(persistedContent.Id, true); + var assignedDomains = _domainService.GetAssignedDomains(publishedContent.Id, true).ToList(); // No domains at all, add a warning, and making it scary, to add domains. if (assignedDomains.Any() is false) @@ -1452,10 +1451,26 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers "Domains are not configured for multilingual site, please contact an administrator, see log for more information", EventMessageType.Error)); - _logger.LogWarning("The root node {RootNodeName} is published with multiple cultures, but no domains are configured, this will cause routing and caching issues, please register domains for: {Cultures}", - persistedContent.Name, string.Join(", ", publishedCultures)); + _logger.LogWarning("The root node {RootNodeName} was published with multiple cultures, but no domains are configured, this will cause routing and caching issues, please register domains for: {Cultures}", + publishedContent.Name, string.Join(", ", publishedCultures)); return; } + + // If there is some domains, verify that there's a domain for each of the published cultures + foreach (var culture in publishedCultures) + { + if (assignedDomains.Any(x => x.LanguageIsoCode.Equals(culture, StringComparison.OrdinalIgnoreCase)) is false) + { + publishResult.EventMessages.Add(new EventMessage( + "Multilingual site", + $"There is no domain configured for {culture}, please contact an administrator, see log for more information", + EventMessageType.Error + )); + + _logger.LogWarning("The root node {RootNodeName} was published in culture {Culture}, but there's no domain configured for it, this will cause routing and caching issues, please register a domain for it", + publishedContent.Name, culture); + } + } } ///