Fixes import of nested dictionary items #U4-4663

This commit is contained in:
Morten Christensen
2014-05-01 13:51:33 +02:00
parent caf41b74b8
commit 5a862f5c64
2 changed files with 9 additions and 9 deletions

View File

@@ -768,15 +768,15 @@ namespace Umbraco.Core.Services
return ImportDictionaryItems(dictionaryItemElementList, languages);
}
private IEnumerable<IDictionaryItem> ImportDictionaryItems(XElement dictionaryItemElementList, List<ILanguage> languages)
private IEnumerable<IDictionaryItem> ImportDictionaryItems(XElement dictionaryItemElementList, List<ILanguage> languages, Guid? parentId = null)
{
var items = new List<IDictionaryItem>();
foreach (var dictionaryItemElement in dictionaryItemElementList.Elements("DictionaryItem"))
items.AddRange(ImportDictionaryItem(dictionaryItemElement, languages));
items.AddRange(ImportDictionaryItem(dictionaryItemElement, languages, parentId));
return items;
}
private IEnumerable<IDictionaryItem> ImportDictionaryItem(XElement dictionaryItemElement, List<ILanguage> languages)
private IEnumerable<IDictionaryItem> ImportDictionaryItem(XElement dictionaryItemElement, List<ILanguage> languages, Guid? parentId)
{
var items = new List<IDictionaryItem>();
@@ -785,10 +785,10 @@ namespace Umbraco.Core.Services
if (_localizationService.DictionaryItemExists(key))
dictionaryItem = GetAndUpdateDictionaryItem(key, dictionaryItemElement, languages);
else
dictionaryItem = CreateNewDictionaryItem(key, dictionaryItemElement, languages);
dictionaryItem = CreateNewDictionaryItem(key, dictionaryItemElement, languages, parentId);
_localizationService.Save(dictionaryItem);
items.Add(dictionaryItem);
items.AddRange(ImportDictionaryItems(dictionaryItemElement, languages));
items.AddRange(ImportDictionaryItems(dictionaryItemElement, languages, dictionaryItem.Key));
return items;
}
@@ -802,9 +802,9 @@ namespace Umbraco.Core.Services
return dictionaryItem;
}
private static DictionaryItem CreateNewDictionaryItem(string key, XElement dictionaryItemElement, List<ILanguage> languages)
private static DictionaryItem CreateNewDictionaryItem(string key, XElement dictionaryItemElement, List<ILanguage> languages, Guid? parentId)
{
var dictionaryItem = new DictionaryItem(key);
var dictionaryItem = parentId.HasValue ? new DictionaryItem(parentId.Value, key) : new DictionaryItem(key);
var translations = new List<IDictionaryTranslation>();
foreach (var valueElement in dictionaryItemElement.Elements("Value"))

View File

@@ -415,7 +415,7 @@ namespace Umbraco.Tests.Services.Importing
AddLanguages();
// Act
ServiceContext.PackagingService.ImportDictionaryItems(dictionaryItemsElement);
var dictionaryItems = ServiceContext.PackagingService.ImportDictionaryItems(dictionaryItemsElement);
// Assert
Assert.That(ServiceContext.LocalizationService.DictionaryItemExists(parentKey), "DictionaryItem parentKey does not exist");
@@ -425,7 +425,7 @@ namespace Umbraco.Tests.Services.Importing
var childDictionaryItem = ServiceContext.LocalizationService.GetDictionaryItemByKey(childKey);
Assert.That(parentDictionaryItem.ParentId, Is.Not.EqualTo(childDictionaryItem.ParentId));
Assert.That(childDictionaryItem.ParentId, Is.EqualTo(parentDictionaryItem.Id));
Assert.That(childDictionaryItem.ParentId, Is.EqualTo(parentDictionaryItem.Key));
}
[Test]