From 3d8f81025b4affc003d07c4c0ad270f0912163fe Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 2 Jun 2022 20:53:16 +0200 Subject: [PATCH] Fixed NRT issues --- .../Persistence/NPocoSqlExtensions.cs | 2 +- .../Implement/TrackedReferencesRepository.cs | 11 ++++++++--- .../Routing/RedirectTrackingHandler.cs | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs b/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs index ca2f51d99b..291a8de53f 100644 --- a/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs +++ b/src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs @@ -263,7 +263,7 @@ namespace Umbraco.Extensions return sql.OrderBy("(" + sql.SqlContext.SqlSyntax.GetFieldName(field) + ")"); } - public static Sql OrderBy(this Sql sql, Expression> field, string alias) + public static Sql OrderBy(this Sql sql, Expression> field, string alias) { return sql.OrderBy("(" + sql.SqlContext.SqlSyntax.GetFieldName(field, alias) + ")"); } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TrackedReferencesRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TrackedReferencesRepository.cs index be96d81557..3e239069c4 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TrackedReferencesRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TrackedReferencesRepository.cs @@ -69,6 +69,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement private Sql GetInnerUnionSql() { + if (_scopeAccessor.AmbientScope is null) + { + throw new InvalidOperationException("No Ambient Scope available"); + } + var innerUnionSqlChild = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().Select( "[cr].childId as id", "[cr].parentId as otherId", "[rt].[alias]", "[rt].[name]", "[rt].[isDependency]", "[rt].[dual]") .From("cr").InnerJoin("rt") @@ -134,7 +139,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement aliasRight: "ct") .LeftJoin("ctn").On((left, right) => left.NodeId == right.NodeId, aliasLeft: "ct", aliasRight: "ctn"); - sql = sql.WhereIn((System.Linq.Expressions.Expression>)(x => x.NodeId), subQuery, "n"); + sql = sql?.WhereIn((System.Linq.Expressions.Expression>)(x => x.NodeId), subQuery, "n"); if (filterMustBeIsDependency) { @@ -205,10 +210,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement public int OtherId { get; set; } [Column("alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [Column("name")] - public string Name { get; set; } + public string? Name { get; set; } [Column("isDependency")] public bool IsDependency { get; set; } diff --git a/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs b/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs index 4a8acc1b34..f43bce0488 100644 --- a/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs +++ b/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs @@ -145,7 +145,7 @@ namespace Umbraco.Cms.Core.Routing var route = contentCache?.GetRouteById(publishedContent.Id, culture); if (!IsNotRoute(route)) { - oldRoutes[new ContentIdAndCulture(publishedContent.Id, culture)] = new ContentKeyAndOldRoute(publishedContent.Key, route); + oldRoutes[new ContentIdAndCulture(publishedContent.Id, culture)] = new ContentKeyAndOldRoute(publishedContent.Key, route!); } else if (string.IsNullOrEmpty(culture)) { @@ -153,7 +153,7 @@ namespace Umbraco.Cms.Core.Routing var languages = _localizationService.GetAllLanguages(); foreach (var language in languages) { - route = contentCache.GetRouteById(publishedContent.Id, language.IsoCode); + route = contentCache?.GetRouteById(publishedContent.Id, language.IsoCode); if (!IsNotRoute(route)) { oldRoutes[new ContentIdAndCulture(publishedContent.Id, language.IsoCode)] = new ContentKeyAndOldRoute(publishedContent.Key, route!);