Fix for Issue #135 - Variation < null >, < null> is not supported by the property type (#9524)

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Sebastiaan Janssen <sebastiaan@umbraco.com>
This commit is contained in:
BeardinaSuit
2021-02-20 08:37:11 -05:00
committed by GitHub
parent 2c54adacf2
commit f064c074d1
2 changed files with 43 additions and 4 deletions

View File

@@ -358,12 +358,28 @@ namespace Umbraco.Core.Packaging
Key = key
};
// Handle culture specific node names
const string nodeNamePrefix = "nodeName-";
// Get the installed culture iso names, we create a localized content node with a culture that does not exist in the project
// We have to use Invariant comparisons, because when we get them from ContentBase in EntityXmlSerializer they're all lowercase.
var installedLanguages = _localizationService.GetAllLanguages().Select(l => l.IsoCode).ToArray();
foreach (var localizedNodeName in element.Attributes().Where(a => a.Name.LocalName.InvariantStartsWith(nodeNamePrefix)))
{
var newCulture = localizedNodeName.Name.LocalName.Substring(nodeNamePrefix.Length);
// Skip the culture if it does not exist in the current project
if (installedLanguages.InvariantContains(newCulture))
{
content.SetCultureName(localizedNodeName.Value, newCulture);
}
}
//Here we make sure that we take composition properties in account as well
//otherwise we would skip them and end up losing content
var propTypes = contentType.CompositionPropertyTypes.Any()
? contentType.CompositionPropertyTypes.ToDictionary(x => x.Alias, x => x)
: contentType.PropertyTypes.ToDictionary(x => x.Alias, x => x);
var foundLanguages = new HashSet<string>();
foreach (var property in properties)
{
string propertyTypeAlias = property.Name.LocalName;
@@ -371,14 +387,30 @@ namespace Umbraco.Core.Packaging
{
var propertyValue = property.Value;
// Handle properties language attributes
var propertyLang = property.Attribute(XName.Get("lang"))?.Value;
foundLanguages.Add(propertyLang);
if (propTypes.TryGetValue(propertyTypeAlias, out var propertyType))
{
//set property value
content.SetValue(propertyTypeAlias, propertyValue);
// set property value
// Skip unsupported language variation, otherwise we'll get a "not supported error"
// We allow null, because that's invariant
if (installedLanguages.InvariantContains(propertyLang) || propertyLang is null)
{
content.SetValue(propertyTypeAlias, propertyValue, propertyLang);
}
}
}
}
foreach (var propertyLang in foundLanguages)
{
if (string.IsNullOrEmpty(content.GetCultureName(propertyLang)) && installedLanguages.InvariantContains(propertyLang))
{
content.SetCultureName(nodeName, propertyLang);
}
}
return content;
}