Merge branch 'dev-v7.7' into temp-U4-10333

This commit is contained in:
Shannon
2017-09-05 19:23:45 +10:00
6 changed files with 54 additions and 7 deletions

View File

@@ -260,6 +260,19 @@ namespace Umbraco.Core.Persistence.Repositories
return GetByQuery(query);
}
public Dictionary<string, Guid> GetDictionaryItemKeyMap()
{
var columns = new[] { "key", "id" }.Select(x => (object) SqlSyntax.GetQuotedColumnName(x)).ToArray();
var sql = new Sql().Select(columns).From<DictionaryDto>(SqlSyntax);
return Database.Fetch<DictionaryItemKeyIdDto>(sql).ToDictionary(x => x.Key, x => x.Id);
}
private class DictionaryItemKeyIdDto
{
public string Key { get; set; }
public Guid Id { get; set; }
}
public IEnumerable<IDictionaryItem> 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

View File

@@ -9,5 +9,6 @@ namespace Umbraco.Core.Persistence.Repositories
IDictionaryItem Get(Guid uniqueId);
IDictionaryItem Get(string key);
IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId);
Dictionary<string, Guid> GetDictionaryItemKeyMap();
}
}

View File

@@ -136,5 +136,11 @@ namespace Umbraco.Core.Services
/// <param name="language"><see cref="ILanguage"/> to delete</param>
/// <param name="userId">Optional id of the user deleting the language</param>
void Delete(ILanguage language, int userId = 0);
/// <summary>
/// Gets the full dictionary key map.
/// </summary>
/// <returns>The full dictionary key map.</returns>
Dictionary<string, Guid> GetDictionaryItemKeyMap();
}
}

View File

@@ -405,6 +405,15 @@ namespace Umbraco.Core.Services
}
}
public Dictionary<string, Guid> GetDictionaryItemKeyMap()
{
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
{
var repository = RepositoryFactory.CreateDictionaryRepository(uow);
return repository.GetDictionaryItemKeyMap();
}
}
#region Event Handlers
/// <summary>
/// Occurs before Delete

View File

@@ -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<string, Guid> 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()
{

View File

@@ -269,7 +269,7 @@ namespace Umbraco.Web.Routing
/// <remarks>Eg the relative part of <c>/foo/bar/nil</c> to domain <c>example.com/foo</c> is <c>/bar/nil</c>.</remarks>
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