Merge branch 'dev-v7' into 7.3.0

Conflicts:
	src/Umbraco.Core/Services/EntityService.cs
	src/Umbraco.Core/Services/ServiceContext.cs
	src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs
	src/Umbraco.Web/Cache/TemplateCacheRefresher.cs
	src/umbraco.cms/businesslogic/template/Template.cs
This commit is contained in:
Shannon
2015-05-13 12:20:43 +10:00
46 changed files with 816 additions and 315 deletions

View File

@@ -1,4 +1,7 @@
using Umbraco.Core.Logging;
using System.Linq;
using System.Web;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
namespace Umbraco.Web.Routing
@@ -17,17 +20,22 @@ namespace Umbraco.Web.Routing
{
LogHelper.Debug<ContentFinderByLegacy404>("Looking for a page to handle 404.");
// TODO - replace the whole logic and stop calling into library!
var error404 = global::umbraco.library.GetCurrentNotFoundPageId();
var id = int.Parse(error404);
// TODO - replace the whole logic
var error404 = NotFoundHandlerHelper.GetCurrentNotFoundPageId(
//TODO: The IContentSection should be ctor injected into this class in v8!
UmbracoConfig.For.UmbracoSettings().Content.Error404Collection.ToArray(),
//TODO: Is there a better way to extract this value? at least we're not relying on singletons here though
pcr.RoutingContext.UmbracoContext.HttpContext.Request.ServerVariables["SERVER_NAME"],
pcr.RoutingContext.UmbracoContext.Application.Services.EntityService,
new PublishedContentQuery(pcr.RoutingContext.UmbracoContext.ContentCache, pcr.RoutingContext.UmbracoContext.MediaCache));
IPublishedContent content = null;
if (id > 0)
if (error404.HasValue)
{
LogHelper.Debug<ContentFinderByLegacy404>("Got id={0}.", () => id);
LogHelper.Debug<ContentFinderByLegacy404>("Got id={0}.", () => error404.Value);
content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById(id);
content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById(error404.Value);
LogHelper.Debug<ContentFinderByLegacy404>(content == null
? "Could not find content with that id."

View File

@@ -4,84 +4,90 @@ using System.Linq;
using System.Web;
using System.Xml;
using System.Reflection;
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Core.Logging;
using umbraco.interfaces;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Xml;
namespace Umbraco.Web.Routing
{
// provides internal access to legacy url -- should get rid of it eventually
internal class NotFoundHandlerHelper
{
const string ContextKey = "Umbraco.Web.Routing.NotFoundHandlerHelper.Url";
// provides internal access to legacy url -- should get rid of it eventually
internal class NotFoundHandlerHelper
{
const string ContextKey = "Umbraco.Web.Routing.NotFoundHandlerHelper.Url";
static NotFoundHandlerHelper()
{
InitializeNotFoundHandlers();
}
public static string GetLegacyUrlForNotFoundHandlers()
{
// that's not backward-compatible because when requesting "/foo.aspx"
// 4.9 : url = "foo.aspx"
// 4.10 : url = "/foo"
//return pcr.Uri.AbsolutePath;
public static string GetLegacyUrlForNotFoundHandlers()
{
// that's not backward-compatible because when requesting "/foo.aspx"
// 4.9 : url = "foo.aspx"
// 4.10 : url = "/foo"
//return pcr.Uri.AbsolutePath;
// so we have to run the legacy code for url preparation :-(
// so we have to run the legacy code for url preparation :-(
var httpContext = HttpContext.Current;
var httpContext = HttpContext.Current;
if (httpContext == null)
return "";
if (httpContext == null)
return "";
var url = httpContext.Items[ContextKey] as string;
if (url != null)
return url;
var url = httpContext.Items[ContextKey] as string;
if (url != null)
return url;
// code from requestModule.UmbracoRewrite
var tmp = httpContext.Request.Path.ToLower();
// code from requestModule.UmbracoRewrite
var tmp = httpContext.Request.Path.ToLower();
// note: requestModule.UmbracoRewrite also did some stripping of &umbPage
// from the querystring... that was in v3.x to fix some issues with pre-forms
// auth. Paul Sterling confirmed in jan. 2013 that we can get rid of it.
// note: requestModule.UmbracoRewrite also did some stripping of &umbPage
// from the querystring... that was in v3.x to fix some issues with pre-forms
// auth. Paul Sterling confirmed in jan. 2013 that we can get rid of it.
// code from requestHandler.cleanUrl
var root = Core.IO.SystemDirectories.Root.ToLower();
if (!string.IsNullOrEmpty(root) && tmp.StartsWith(root))
tmp = tmp.Substring(root.Length);
tmp = tmp.TrimEnd('/');
if (tmp == "/default.aspx")
tmp = string.Empty;
else if (tmp == root)
tmp = string.Empty;
// code from requestHandler.cleanUrl
var root = Core.IO.SystemDirectories.Root.ToLower();
if (!string.IsNullOrEmpty(root) && tmp.StartsWith(root))
tmp = tmp.Substring(root.Length);
tmp = tmp.TrimEnd('/');
if (tmp == "/default.aspx")
tmp = string.Empty;
else if (tmp == root)
tmp = string.Empty;
// code from UmbracoDefault.Page_PreInit
if (tmp != "" && httpContext.Request["umbPageID"] == null)
{
var tryIntParse = tmp.Replace("/", "").Replace(".aspx", string.Empty);
int result;
if (int.TryParse(tryIntParse, out result))
tmp = tmp.Replace(".aspx", string.Empty);
}
else if (!string.IsNullOrEmpty(httpContext.Request["umbPageID"]))
{
int result;
if (int.TryParse(httpContext.Request["umbPageID"], out result))
{
tmp = httpContext.Request["umbPageID"];
}
}
// code from UmbracoDefault.Page_PreInit
if (tmp != "" && httpContext.Request["umbPageID"] == null)
{
var tryIntParse = tmp.Replace("/", "").Replace(".aspx", string.Empty);
int result;
if (int.TryParse(tryIntParse, out result))
tmp = tmp.Replace(".aspx", string.Empty);
}
else if (!string.IsNullOrEmpty(httpContext.Request["umbPageID"]))
{
int result;
if (int.TryParse(httpContext.Request["umbPageID"], out result))
{
tmp = httpContext.Request["umbPageID"];
}
}
// code from requestHandler.ctor
if (tmp != "")
tmp = tmp.Substring(1);
// code from requestHandler.ctor
if (tmp != "")
tmp = tmp.Substring(1);
httpContext.Items[ContextKey] = tmp;
return tmp;
}
httpContext.Items[ContextKey] = tmp;
return tmp;
}
private static IEnumerable<Type> _customHandlerTypes;
private static Type _customLastChanceHandlerType;
private static Type _customLastChanceHandlerType;
static void InitializeNotFoundHandlers()
{
@@ -175,14 +181,14 @@ namespace Umbraco.Web.Routing
return handlers;
}
public static bool IsNotFoundHandlerEnabled<T>()
{
return _customHandlerTypes.Contains(typeof (T));
}
public static bool IsNotFoundHandlerEnabled<T>()
{
return _customHandlerTypes.Contains(typeof(T));
}
public static INotFoundHandler GetNotFoundLastChanceHandler()
{
if (_customLastChanceHandlerType == null) return null;
public static INotFoundHandler GetNotFoundLastChanceHandler()
{
if (_customLastChanceHandlerType == null) return null;
try
{
@@ -214,5 +220,121 @@ namespace Umbraco.Web.Routing
return finder;
}
/// <summary>
/// Returns the Umbraco page id to use as the Not Found page based on the configured 404 pages and the current request
/// </summary>
/// <param name="error404Collection"></param>
/// <param name="requestServerName">
/// The server name attached to the request, normally would be the source of HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
/// </param>
/// <param name="entityService"></param>
/// <param name="publishedContentQuery"></param>
/// <returns></returns>
internal static int? GetCurrentNotFoundPageId(
IContentErrorPage[] error404Collection,
string requestServerName,
IEntityService entityService,
PublishedContentQuery publishedContentQuery)
{
if (error404Collection.Count() > 1)
{
// try to get the 404 based on current culture (via domain)
IContentErrorPage cultureErr;
//TODO: Remove the dependency on this legacy Domain service,
// in 7.3 the real domain service should be passed in as a parameter.
if (Domain.Exists(requestServerName))
{
var d = Domain.GetDomain(requestServerName);
// test if a 404 page exists with current culture
cultureErr = error404Collection
.FirstOrDefault(x => x.Culture == d.Language.CultureAlias);
if (cultureErr != null)
{
return GetContentIdFromErrorPageConfig(cultureErr, entityService, publishedContentQuery);
}
}
// test if a 404 page exists with current culture thread
cultureErr = error404Collection
.FirstOrDefault(x => x.Culture == System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
if (cultureErr != null)
{
return GetContentIdFromErrorPageConfig(cultureErr, entityService, publishedContentQuery);
}
// there should be a default one!
cultureErr = error404Collection
.FirstOrDefault(x => x.Culture == "default");
if (cultureErr != null)
{
return GetContentIdFromErrorPageConfig(cultureErr, entityService, publishedContentQuery);
}
}
else
{
return GetContentIdFromErrorPageConfig(error404Collection.First(), entityService, publishedContentQuery);
}
return null;
}
/// <summary>
/// Returns the content id based on the configured IContentErrorPage section
/// </summary>
/// <param name="errorPage"></param>
/// <param name="entityService"></param>
/// <param name="publishedContentQuery"></param>
/// <returns></returns>
internal static int? GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, PublishedContentQuery publishedContentQuery)
{
if (errorPage.HasContentId) return errorPage.ContentId;
if (errorPage.HasContentKey)
{
//need to get the Id for the GUID
//TODO: When we start storing GUIDs into the IPublishedContent, then we won't have to look this up
// but until then we need to look it up in the db. For now we've implemented a cached service for
// converting Int -> Guid and vice versa.
var found = entityService.GetIdForKey(errorPage.ContentKey, UmbracoObjectTypes.Document);
if (found)
{
return found.Result;
}
return null;
}
if (errorPage.ContentXPath.IsNullOrWhiteSpace() == false)
{
try
{
//we have an xpath statement to execute
var xpathResult = UmbracoXPathPathSyntaxParser.ParseXPathQuery(
xpathExpression: errorPage.ContentXPath,
nodeContextId: null,
getPath: nodeid =>
{
var ent = entityService.Get(nodeid);
return ent.Path.Split(',').Reverse();
},
publishedContentExists: i => publishedContentQuery.TypedContent(i) != null);
//now we'll try to execute the expression
var nodeResult = publishedContentQuery.TypedContentSingleAtXPath(xpathResult);
if (nodeResult != null)
return nodeResult.Id;
}
catch (Exception ex)
{
LogHelper.Error<NotFoundHandlerHelper>("Could not parse xpath expression: " + errorPage.ContentXPath, ex);
return null;
}
}
return null;
}
}
}