diff --git a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs index 968c2d9cb0..7196165e6f 100644 --- a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs @@ -260,6 +260,19 @@ namespace Umbraco.Core.Persistence.Repositories return GetByQuery(query); } + public Dictionary GetDictionaryItemKeyMap() + { + var columns = new[] { "key", "id" }.Select(x => (object) SqlSyntax.GetQuotedColumnName(x)).ToArray(); + var sql = new Sql().Select(columns).From(SqlSyntax); + return Database.Fetch(sql).ToDictionary(x => x.Key, x => x.Id); + } + + private class DictionaryItemKeyIdDto + { + public string Key { get; set; } + public Guid Id { get; set; } + } + public IEnumerable GetDictionaryItemDescendants(Guid? parentId) { //This methods will look up children at each level, since we do not store a path for dictionary (ATM), we need to do a recursive diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDictionaryRepository.cs index d030bcda2a..5c120c76cb 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IDictionaryRepository.cs @@ -9,5 +9,6 @@ namespace Umbraco.Core.Persistence.Repositories IDictionaryItem Get(Guid uniqueId); IDictionaryItem Get(string key); IEnumerable GetDictionaryItemDescendants(Guid? parentId); + Dictionary GetDictionaryItemKeyMap(); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/ILocalizationService.cs b/src/Umbraco.Core/Services/ILocalizationService.cs index e6563b7ee9..a49b8e203e 100644 --- a/src/Umbraco.Core/Services/ILocalizationService.cs +++ b/src/Umbraco.Core/Services/ILocalizationService.cs @@ -136,5 +136,11 @@ namespace Umbraco.Core.Services /// to delete /// Optional id of the user deleting the language void Delete(ILanguage language, int userId = 0); + + /// + /// Gets the full dictionary key map. + /// + /// The full dictionary key map. + Dictionary GetDictionaryItemKeyMap(); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index 12a2afb6ad..fa09d539ee 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -405,6 +405,15 @@ namespace Umbraco.Core.Services } } + public Dictionary GetDictionaryItemKeyMap() + { + using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) + { + var repository = RepositoryFactory.CreateDictionaryRepository(uow); + return repository.GetDictionaryItemKeyMap(); + } + } + #region Event Handlers /// /// Occurs before Delete diff --git a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs index 3a85978f40..5527817caa 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Moq; using NUnit.Framework; @@ -122,7 +123,7 @@ namespace Umbraco.Tests.Persistence.Repositories //re-get dictionaryItem = repository.Get(dictionaryItem.Id); - + // Assert Assert.That(dictionaryItem, Is.Not.Null); @@ -140,10 +141,10 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - + using (var repository = CreateRepository(unitOfWork)) { - var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235"); + var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235"); repository.AddOrUpdate(dictionaryItem); unitOfWork.Commit(); @@ -160,7 +161,6 @@ namespace Umbraco.Tests.Persistence.Repositories } - [Test] public void Can_Perform_GetAll_On_DictionaryRepository() { @@ -319,7 +319,7 @@ namespace Umbraco.Tests.Persistence.Repositories unitOfWork.Commit(); var dictionaryItem = (DictionaryItem)repository.Get(1); - + // Assert Assert.That(dictionaryItem, Is.Not.Null); Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3)); @@ -364,6 +364,24 @@ namespace Umbraco.Tests.Persistence.Repositories } } + [Test] + public void Can_Perform_GetDictionaryItemKeyMap_On_DictionaryRepository() + { + Dictionary keyMap; + + var provider = new PetaPocoUnitOfWorkProvider(Logger); + using (var unitOfWork = provider.GetUnitOfWork(readOnly: true)) + { + var repository = CreateRepository(unitOfWork); + keyMap = repository.GetDictionaryItemKeyMap(); + } + + Assert.IsNotNull(keyMap); + Assert.IsNotEmpty(keyMap); + foreach (var kvp in keyMap) + Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); + } + [TearDown] public override void TearDown() { diff --git a/src/Umbraco.Web/Routing/DomainHelper.cs b/src/Umbraco.Web/Routing/DomainHelper.cs index 6934b08cf2..ab2c14f009 100644 --- a/src/Umbraco.Web/Routing/DomainHelper.cs +++ b/src/Umbraco.Web/Routing/DomainHelper.cs @@ -269,7 +269,7 @@ namespace Umbraco.Web.Routing /// Eg the relative part of /foo/bar/nil to domain example.com/foo is /bar/nil. public static string PathRelativeToDomain(Uri domainUri, string path) { - return path.Substring(domainUri.AbsolutePath.Length).EnsureStartsWith('/'); + return Uri.EscapeUriString(path).Substring(domainUri.AbsolutePath.Length).EnsureStartsWith('/'); } #endregion