Merge pull request #10811 from umbraco/v9/bugfix/null-check-redirect-tracking
Needs a null check so it doesn't explode when saving content during a migration.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
@@ -29,6 +30,7 @@ namespace Umbraco.Cms.Core.Routing
|
||||
INotificationHandler<ContentMovingNotification>,
|
||||
INotificationHandler<ContentMovedNotification>
|
||||
{
|
||||
private readonly ILogger<RedirectTrackingHandler> _logger;
|
||||
private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly IRedirectUrlService _redirectUrlService;
|
||||
@@ -36,8 +38,14 @@ namespace Umbraco.Cms.Core.Routing
|
||||
|
||||
private const string NotificationStateKey = "Umbraco.Cms.Core.Routing.RedirectTrackingHandler";
|
||||
|
||||
public RedirectTrackingHandler(IOptionsMonitor<WebRoutingSettings> webRoutingSettings, IPublishedSnapshotAccessor publishedSnapshotAccessor, IRedirectUrlService redirectUrlService, IVariationContextAccessor variationContextAccessor)
|
||||
public RedirectTrackingHandler(
|
||||
ILogger<RedirectTrackingHandler> logger,
|
||||
IOptionsMonitor<WebRoutingSettings> webRoutingSettings,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
||||
IRedirectUrlService redirectUrlService,
|
||||
IVariationContextAccessor variationContextAccessor)
|
||||
{
|
||||
_logger = logger;
|
||||
_webRoutingSettings = webRoutingSettings;
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor;
|
||||
_redirectUrlService = redirectUrlService;
|
||||
@@ -112,7 +120,13 @@ namespace Umbraco.Cms.Core.Routing
|
||||
|
||||
private void CreateRedirects(OldRoutesDictionary oldRoutes)
|
||||
{
|
||||
var contentCache = _publishedSnapshotAccessor.PublishedSnapshot.Content;
|
||||
var contentCache = _publishedSnapshotAccessor.PublishedSnapshot?.Content;
|
||||
|
||||
if (contentCache == null)
|
||||
{
|
||||
_logger.LogWarning("Could not track redirects because there is no current published snapshot available.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var oldRoute in oldRoutes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user