Merge remote-tracking branch 'origin/7.3.0' into dev-v8
Conflicts: src/Umbraco.Core/Services/DomainService.cs src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs src/Umbraco.Web/umbraco.presentation/NotFoundHandlers.cs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
@@ -25,6 +26,7 @@ namespace Umbraco.Core.Persistence.Mappers
|
||||
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.Id, dto => dto.Id);
|
||||
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.RootContentId, dto => dto.RootStructureId);
|
||||
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.DefaultLanguageId, dto => dto.DefaultLanguage);
|
||||
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.DomainName, dto => dto.DomainName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,17 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
}
|
||||
|
||||
public IDomain GetByName(string domainName)
|
||||
{
|
||||
using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
|
||||
{
|
||||
var factory = new DomainModelFactory();
|
||||
return factory.BuildDomainEntity(
|
||||
repo.GetByQuery(new Query<CacheableDomain>().Where(x => x.DomainName.InvariantEquals(domainName))).FirstOrDefault(),
|
||||
_contentRepository, _languageRepository);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(string domainName)
|
||||
{
|
||||
using (var repo = new CachedDomainRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax, _mappingResolver))
|
||||
@@ -248,7 +259,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
protected override void PersistNewItem(CacheableDomain entity)
|
||||
{
|
||||
var exists = Database.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoDomains WHERE domainName = @domainName", new {domainName = entity.DomainName});
|
||||
var exists = Database.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoDomains WHERE domainName = @domainName", new { domainName = entity.DomainName });
|
||||
if (exists > 0) throw new DuplicateNameException(string.Format("The domain name {0} is already assigned", entity.DomainName));
|
||||
|
||||
entity.AddingEntity();
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IDomainRepository : IRepositoryQueryable<int, IDomain>
|
||||
{
|
||||
IDomain GetByName(string domainName);
|
||||
bool Exists(string domainName);
|
||||
IEnumerable<IDomain> GetAll(bool includeWildcards);
|
||||
IEnumerable<IDomain> GetAssignedDomains(int contentId, bool includeWildcards);
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Core.Services
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDomainRepository(uow))
|
||||
{
|
||||
return repository.GetByQuery(repository.Query.Where(x => x.DomainName.InvariantEquals(name))).FirstOrDefault();
|
||||
return repository.GetByName(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -207,6 +208,68 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exists()
|
||||
{
|
||||
var provider = new PetaPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
{
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test" + i + ".com") { RootContent = content, Language = lang };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
var found = repo.Exists("test1.com");
|
||||
|
||||
Assert.IsTrue(found);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_By_Name()
|
||||
{
|
||||
var provider = new PetaPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
{
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test" + i + ".com") { RootContent = content, Language = lang };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
var found = repo.GetByName("test1.com");
|
||||
|
||||
Assert.IsNotNull(found);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_All()
|
||||
{
|
||||
|
||||
@@ -44,7 +44,8 @@ namespace Umbraco.Web.Routing
|
||||
//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));
|
||||
new PublishedContentQuery(pcr.RoutingContext.UmbracoContext.ContentCache, pcr.RoutingContext.UmbracoContext.MediaCache),
|
||||
pcr.RoutingContext.UmbracoContext.Application.Services.DomainService);
|
||||
|
||||
IPublishedContent content = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user