Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 9e4b481

Browse files
gavinfauxnvisage-gf
authored andcommitted
Handle UmbracoContext.Current null
Issue arises when Examine is indexing grid nodes with DTGE and Nested Content content that are also indexed, avoid null being cached in case of conversion issue; Umbraco 7.3.
1 parent 5aacebb commit 9e4b481

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Src/Our.Umbraco.DocTypeGridEditor/Helpers/DocTypeGridEditorHelper.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
2727
if (string.IsNullOrWhiteSpace(docTypeAlias))
2828
return null;
2929

30+
if (UmbracoContext.Current != null)
31+
{
3032
return (IPublishedContent)ApplicationContext.Current.ApplicationCache.RequestCache.GetCacheItem(
3133
"DocTypeGridEditorHelper.ConvertValueToContent_" + id + "_" + docTypeAlias, () =>
3234
{
35+
return ConvertValue(id, docTypeAlias, dataJson);
36+
});
37+
}
38+
return (IPublishedContent) ConvertValue(id, docTypeAlias, dataJson);
39+
}
40+
41+
private static IPublishedContent ConvertValue(string id, string docTypeAlias, string dataJson)
42+
{
3343
using (var timer = DisposableTimer.DebugDuration<DocTypeGridEditorHelper>(string.Format("ConvertValueToContent ({0}, {1})", id, docTypeAlias)))
3444
{
3545
Guid docTypeGuid;
@@ -83,15 +93,15 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
8393
}
8494

8595
// Get the current request node we are embedded in
86-
var pcr = UmbracoContext.Current.PublishedContentRequest;
96+
var pcr = UmbracoContext.Current == null ? null : UmbracoContext.Current.PublishedContentRequest;
8797
var containerNode = pcr != null && pcr.HasPublishedContent ? pcr.PublishedContent : null;
8898

8999
return new DetachedPublishedContent(nameObj == null ? null : nameObj.ToString(),
90100
publishedContentType,
91101
properties.ToArray(),
92102
containerNode);
93103
}
94-
});
104+
95105
}
96106
}
97-
}
107+
}

0 commit comments

Comments
 (0)