Add nullability to nucache & lucene projects

This commit is contained in:
Nikolaj Geisle
2022-03-30 13:34:56 +02:00
parent b52c4e50cf
commit 05a08bef63
105 changed files with 736 additions and 619 deletions

View File

@@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Routing
public IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
var node = umbracoContext.Content.GetById(id);
var node = umbracoContext.Content?.GetById(id);
if (node == null)
yield break;

View File

@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Routing
if (nodeId > 0)
{
_logger.LogDebug("Id={NodeId}", nodeId);
node = umbracoContext?.Content.GetById(nodeId);
node = umbracoContext?.Content?.GetById(nodeId);
if (node != null)
{

View File

@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Routing
}
if (int.TryParse(_requestAccessor.GetRequestValue("umbPageID"), NumberStyles.Integer, CultureInfo.InvariantCulture, out int pageId))
{
IPublishedContent? doc = umbracoContext?.Content.GetById(pageId);
IPublishedContent? doc = umbracoContext.Content?.GetById(pageId);
if (doc != null)
{

View File

@@ -62,7 +62,7 @@ namespace Umbraco.Cms.Core.Routing
return false;
}
IPublishedContent? content = umbracoContext.Content.GetById(redirectUrl.ContentId);
IPublishedContent? content = umbracoContext.Content?.GetById(redirectUrl.ContentId);
var url = content == null ? "#" : content.Url(_publishedUrlProvider, redirectUrl.Culture);
if (url.StartsWith("#"))
{

View File

@@ -72,7 +72,7 @@ namespace Umbraco.Cms.Core.Routing
_logger.LogDebug("Test route {Route}", route);
IPublishedContent? node = umbracoContext?.Content.GetByRoute(umbracoContext.InPreviewMode, route, culture: docreq.Culture);
IPublishedContent? node = umbracoContext.Content?.GetByRoute(umbracoContext.InPreviewMode, route, culture: docreq.Culture);
if (node != null)
{
docreq.SetPublishedContent(node);

View File

@@ -69,7 +69,7 @@ namespace Umbraco.Cms.Core.Routing
return node != null;
}
private IPublishedContent? FindContentByAlias(IPublishedContentCache cache, int rootNodeId, string? culture, string alias)
private IPublishedContent? FindContentByAlias(IPublishedContentCache? cache, int rootNodeId, string? culture, string alias)
{
if (alias == null)
{
@@ -131,16 +131,19 @@ namespace Umbraco.Cms.Core.Routing
// but the only solution is to entirely refactor URL providers to stop being dynamic
if (rootNodeId > 0)
{
IPublishedContent? rootNode = cache.GetById(rootNodeId);
IPublishedContent? rootNode = cache?.GetById(rootNodeId);
return rootNode?.Descendants(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
}
foreach (IPublishedContent rootContent in cache.GetAtRoot())
if (cache is not null)
{
IPublishedContent? c = rootContent.DescendantsOrSelf(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
if (c != null)
foreach (IPublishedContent rootContent in cache.GetAtRoot())
{
return c;
IPublishedContent? c = rootContent.DescendantsOrSelf(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
if (c != null)
{
return c;
}
}
}

View File

@@ -70,7 +70,7 @@ namespace Umbraco.Cms.Core.Routing
public virtual IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
{
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
IPublishedContent? node = umbracoContext.Content.GetById(id);
IPublishedContent? node = umbracoContext.Content?.GetById(id);
if (node == null)
{
yield break;
@@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Routing
var culture = d.Culture;
// although we are passing in culture here, if any node in this path is invariant, it ignores the culture anyways so this is ok
var route = umbracoContext.Content.GetRouteById(id, culture);
var route = umbracoContext.Content?.GetRouteById(id, culture);
if (route == null)
{
continue;
@@ -131,7 +131,7 @@ namespace Umbraco.Cms.Core.Routing
IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
// will not use cache if previewing
var route = umbracoContext.Content.GetRouteById(content.Id, culture);
var route = umbracoContext.Content?.GetRouteById(content.Id, culture);
return GetUrlFromRoute(route, umbracoContext, content.Id, current, mode, culture);
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Routing
/// <param name="contentId">The identifier of the content which supports the domain.</param>
/// <param name="culture">The culture of the domain.</param>
/// <param name="isWildcard">A value indicating whether the domain is a wildcard domain.</param>
public Domain(int id, string name, int contentId, string culture, bool isWildcard)
public Domain(int id, string name, int contentId, string? culture, bool isWildcard)
{
Id = id;
Name = name;
@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Routing
/// <summary>
/// Gets the culture of the domain.
/// </summary>
public string Culture { get; }
public string? Culture { get; }
/// <summary>
/// Gets a value indicating whether the domain is a wildcard domain.

View File

@@ -39,8 +39,8 @@ namespace Umbraco.Cms.Core.Routing
// get the published route, else the preview route
// if both are null then the content does not exist
var route = umbracoContext.Content.GetRouteById(contentId) ??
umbracoContext.Content.GetRouteById(true, contentId);
var route = umbracoContext.Content?.GetRouteById(contentId) ??
umbracoContext.Content?.GetRouteById(true, contentId);
if (route == null)
return null;

View File

@@ -282,7 +282,7 @@ namespace Umbraco.Cms.Core.Routing
bool IsPublishedContentDomain(Domain domain)
{
// just get it from content cache - optimize there, not here
IPublishedContent? domainDocument = umbracoContext.PublishedSnapshot.Content.GetById(domain.ContentId);
IPublishedContent? domainDocument = umbracoContext.PublishedSnapshot.Content?.GetById(domain.ContentId);
// not published - at all
if (domainDocument == null)
@@ -297,7 +297,7 @@ namespace Umbraco.Cms.Core.Routing
}
// variant, ensure that the culture corresponding to the domain's language is published
return domainDocument.Cultures.ContainsKey(domain.Culture);
return domain.Culture is not null && domainDocument.Cultures.ContainsKey(domain.Culture);
}
domains = domains?.Where(IsPublishedContentDomain).ToList();
@@ -510,7 +510,7 @@ namespace Umbraco.Cms.Core.Routing
{
// try and get the redirect node from a legacy integer ID
valid = true;
internalRedirectNode = umbracoContext.Content.GetById(internalRedirectId);
internalRedirectNode = umbracoContext.Content?.GetById(internalRedirectId);
}
else
{
@@ -519,7 +519,7 @@ namespace Umbraco.Cms.Core.Routing
{
// try and get the redirect node from a UDI Guid
valid = true;
internalRedirectNode = umbracoContext.Content.GetById(udiInternalRedirectId.Guid);
internalRedirectNode = umbracoContext.Content?.GetById(udiInternalRedirectId.Guid);
}
}

View File

@@ -52,17 +52,17 @@ namespace Umbraco.Cms.Core.Routing
private IPublishedContent? GetDocument(int id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
return umbracoContext.Content.GetById(id);
return umbracoContext.Content?.GetById(id);
}
private IPublishedContent GetDocument(Guid id)
private IPublishedContent? GetDocument(Guid id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
return umbracoContext.Content.GetById(id);
return umbracoContext.Content?.GetById(id);
}
private IPublishedContent GetMedia(Guid id)
private IPublishedContent? GetMedia(Guid id)
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
return umbracoContext.Media.GetById(id);
return umbracoContext.Media?.GetById(id);
}
/// <summary>
@@ -189,7 +189,7 @@ namespace Umbraco.Cms.Core.Routing
/// <param name="current"></param>
/// <returns></returns>
public string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
=> GetMediaUrl(GetMedia(id), mode, culture, propertyAlias, current);
=> GetMediaUrl( GetMedia(id), mode, culture, propertyAlias, current);
/// <summary>
/// Gets the URL of a media item.
@@ -206,7 +206,7 @@ namespace Umbraco.Cms.Core.Routing
/// when no culture is specified, the current culture.</para>
/// <para>If the provider is unable to provide a URL, it returns <see cref="String.Empty"/>.</para>
/// </remarks>
public string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
public string GetMediaUrl(IPublishedContent? content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri? current = null)
{
if (propertyAlias == null)
throw new ArgumentNullException(nameof(propertyAlias));