Refactors IDomain model, simplifies it so that it doesn't contain references, simplifies the domain repository to no longer require lookups of content and languages, updates all other code referencing IDomain and now if a language lookup is required it is made when appropriate.

This commit is contained in:
Shannon
2015-07-27 12:53:09 +02:00
parent 00c13b9939
commit 16c9ca9e4b
23 changed files with 323 additions and 439 deletions

View File

@@ -28,7 +28,8 @@ namespace Umbraco.Web.Routing
pcr.RoutingContext.UmbracoContext.HttpContext.Request.ServerVariables["SERVER_NAME"],
pcr.RoutingContext.UmbracoContext.Application.Services.EntityService,
new PublishedContentQuery(pcr.RoutingContext.UmbracoContext.ContentCache, pcr.RoutingContext.UmbracoContext.MediaCache),
pcr.RoutingContext.UmbracoContext.Application.Services.DomainService);
pcr.RoutingContext.UmbracoContext.Application.Services.DomainService,
pcr.RoutingContext.UmbracoContext.Application.Services.LocalizationService);
IPublishedContent content = null;

View File

@@ -32,7 +32,7 @@ namespace Umbraco.Web.Routing
{
var name = domain.DomainName.ToCSharpString();
throw new ArgumentException(string.Format("Failed to parse invalid domain: node id={0}, hostname=\"{1}\"."
+ " Hostname should be a valid uri.", domain.RootContent.Id, name), "domain");
+ " Hostname should be a valid uri.", domain.RootContentId, name), "domain");
}
}

View File

@@ -235,7 +235,7 @@ namespace Umbraco.Web.Routing
.Reverse()
.Select(int.Parse)
.TakeWhile(id => id != stopNodeId)
.Select(id => domains.FirstOrDefault(d => d.RootContent.Id == id && d.IsWildcard == false))
.Select(id => domains.FirstOrDefault(d => d.RootContentId == id && d.IsWildcard == false))
.SkipWhile(domain => domain == null)
.FirstOrDefault();
}
@@ -256,7 +256,7 @@ namespace Umbraco.Web.Routing
.Reverse()
.Select(int.Parse)
.TakeWhile(id => id != stopNodeId)
.Select(id => domains.FirstOrDefault(d => d.RootContent.Id == id && d.IsWildcard))
.Select(id => domains.FirstOrDefault(d => d.RootContentId == id && d.IsWildcard))
.FirstOrDefault(domain => domain != null);
}

View File

@@ -230,28 +230,30 @@ namespace Umbraco.Web.Routing
/// <param name="entityService"></param>
/// <param name="publishedContentQuery"></param>
/// <param name="domainService"></param>
/// <param name="localizationService"></param>
/// <returns></returns>
internal static int? GetCurrentNotFoundPageId(
IContentErrorPage[] error404Collection,
string requestServerName,
IEntityService entityService,
ITypedPublishedContentQuery publishedContentQuery,
IDomainService domainService)
IDomainService domainService,
ILocalizationService localizationService)
{
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 (domainService.Exists(requestServerName))
var d = domainService.GetByName(requestServerName);
if (d != null && d.LanguageId.HasValue)
{
var d = domainService.GetByName(requestServerName);
var lang = localizationService.GetLanguageById(d.LanguageId.Value);
// test if a 404 page exists with current culture
cultureErr = error404Collection
.FirstOrDefault(x => x.Culture == d.Language.IsoCode);
.FirstOrDefault(x => x.Culture == lang.IsoCode);
if (cultureErr != null)
{

View File

@@ -242,26 +242,39 @@ namespace Umbraco.Web.Routing
var domainAndUri = DomainHelper.DomainForUri(Services.DomainService.GetAll(false), _pcr.Uri);
// handle domain
if (domainAndUri != null)
if (domainAndUri != null && domainAndUri.UmbracoDomain.LanguageId.HasValue)
{
// matching an existing domain
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}Matches domain=\"{1}\", rootId={2}, culture=\"{3}\"",
() => tracePrefix,
() => domainAndUri.UmbracoDomain.DomainName,
() => domainAndUri.UmbracoDomain.RootContent.Id,
() => domainAndUri.UmbracoDomain.Language.IsoCode);
var lang = Services.LocalizationService.GetLanguageById(domainAndUri.UmbracoDomain.LanguageId.Value);
_pcr.UmbracoDomain = domainAndUri.UmbracoDomain;
_pcr.DomainUri = domainAndUri.Uri;
_pcr.Culture = new CultureInfo(domainAndUri.UmbracoDomain.Language.IsoCode);
if (lang != null)
{
// matching an existing domain
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}Matches domain=\"{1}\", rootId={2}, culture=\"{3}\"",
() => tracePrefix,
() => domainAndUri.UmbracoDomain.DomainName,
() => domainAndUri.UmbracoDomain.RootContentId,
() => lang.IsoCode);
// canonical? not implemented at the moment
// if (...)
// {
// _pcr.RedirectUrl = "...";
// return true;
// }
}
_pcr.UmbracoDomain = domainAndUri.UmbracoDomain;
_pcr.DomainUri = domainAndUri.Uri;
_pcr.Culture = new CultureInfo(lang.IsoCode);
// canonical? not implemented at the moment
// if (...)
// {
// _pcr.RedirectUrl = "...";
// return true;
// }
}
else
{
// not matching any language
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}No language with id {1}", () => tracePrefix, () => domainAndUri.UmbracoDomain.LanguageId.Value);
var defaultLanguage = Services.LocalizationService.GetAllLanguages().FirstOrDefault();
_pcr.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode);
}
}
else
{
// not matching any existing domain
@@ -288,14 +301,23 @@ namespace Umbraco.Web.Routing
var nodePath = _pcr.PublishedContent.Path;
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}Path=\"{1}\"", () => tracePrefix, () => nodePath);
var rootNodeId = _pcr.HasDomain ? _pcr.UmbracoDomain.RootContent.Id : (int?)null;
var rootNodeId = _pcr.HasDomain ? _pcr.UmbracoDomain.RootContentId : (int?)null;
var domain = DomainHelper.FindWildcardDomainInPath(Services.DomainService.GetAll(true), nodePath, rootNodeId);
if (domain != null)
if (domain != null && domain.LanguageId.HasValue)
{
_pcr.Culture = new CultureInfo(domain.Language.IsoCode);
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}Got domain on node {1}, set culture to \"{2}\".", () => tracePrefix,
() => domain.RootContent.Id, () => _pcr.Culture.Name);
var lang = Services.LocalizationService.GetLanguageById(domain.LanguageId.Value);
if (lang != null)
{
_pcr.Culture = new CultureInfo(lang.IsoCode);
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}Got domain on node {1}, set culture to \"{2}\".", () => tracePrefix,
() => domain.RootContentId, () => _pcr.Culture.Name);
}
else
{
ProfilingLogger.Logger.Debug<PublishedContentRequestEngine>("{0}No language with id {1}", () => tracePrefix, () => domain.LanguageId.Value);
}
}
else
{