Skip to content

Commit 95b9a46

Browse files
author
Stephan
committed
U4-4928 - issue with missing media content properties
1 parent 8fb4469 commit 95b9a46

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ internal class DictionaryPublishedContent : PublishedContentBase
464464
// I'm not sure that _properties contains all properties including those without a value,
465465
// neither that GetProperty will return a property without a value vs. null... @zpqrtbnk
466466

467+
// List of properties that will appear in the XML and do not match
468+
// anything in the ContentType, so they must be ignored.
469+
private static readonly string[] IgnoredKeys = { "version", "isDoc", "key" };
470+
467471
public DictionaryPublishedContent(
468472
IDictionary<string, string> valueDictionary,
469473
Func<DictionaryPublishedContent, IPublishedContent> getParent,
@@ -509,47 +513,36 @@ public DictionaryPublishedContent(
509513
_contentType = PublishedContentType.Get(PublishedItemType.Media, _documentTypeAlias);
510514
_properties = new Collection<IPublishedContentProperty>();
511515

516+
//handle content type properties
517+
//make sure we create them even if there's no value
518+
foreach (var propertyType in _contentType.PropertyTypes)
519+
{
520+
var alias = propertyType.PropertyTypeAlias;
521+
_keysAdded.Add(alias);
522+
string value;
523+
const bool isPreviewing = false; // false :: never preview a media
524+
var property = valueDictionary.TryGetValue(alias, out value) == false
525+
? new XmlPublishedProperty(propertyType, isPreviewing)
526+
: new XmlPublishedProperty(propertyType, isPreviewing, value);
527+
_properties.Add(property);
528+
}
529+
512530
//loop through remaining values that haven't been applied
513-
foreach (var i in valueDictionary.Where(x => !_keysAdded.Contains(x.Key)))
531+
foreach (var i in valueDictionary.Where(x =>
532+
_keysAdded.Contains(x.Key) == false // not already processed
533+
&& IgnoredKeys.Contains(x.Key) == false)) // not ignorable
514534
{
515-
IPublishedContentProperty property;
516-
517-
// must ignore that one
518-
if (i.Key == "version" || i.Key == "isDoc") continue;
519-
520535
if (i.Key.InvariantStartsWith("__"))
521-
{
522-
// no type for tha tone, dunno how to convert
523-
property = new PropertyResult(i.Key, i.Value, Guid.Empty, PropertyResultType.CustomProperty);
524-
}
536+
{
537+
// no type for that one, dunno how to convert
538+
IPublishedContentProperty property = new PropertyResult(i.Key, i.Value, Guid.Empty, PropertyResultType.CustomProperty);
539+
_properties.Add(property);
540+
}
525541
else
526542
{
527-
// use property type to ensure proper conversion
528-
var propertyType = _contentType.GetPropertyType(i.Key);
529-
530-
// note: this is where U4-4144 and -3665 were born
531-
//
532-
// because propertyType is null, the XmlPublishedProperty ctor will throw
533-
// it's null because i.Key is not a valid property alias for the type...
534-
// the alias is case insensitive (verified) so it means it really is not
535-
// a correct alias.
536-
//
537-
// in every cases this is after a ConvertFromXPathNavigator, so it means
538-
// that we get some properties from the XML that are not valid properties.
539-
// no idea which property. could come from the cache in library, could come
540-
// from so many places really.
541-
542-
// workaround: just ignore that property
543-
if (propertyType == null)
544-
{
545-
LogHelper.Warn<PublishedMediaCache>("Dropping property \"" + i.Key + "\" because it does not belong to the content type.");
546-
continue;
547-
}
548-
549-
property = new XmlPublishedProperty(propertyType, false, i.Value); // false :: never preview a media
543+
// this is a property that does not correspond to anything, ignore and log
544+
LogHelper.Warn<PublishedMediaCache>("Dropping property \"" + i.Key + "\" because it does not belong to the content type.");
550545
}
551-
552-
_properties.Add(property);
553546
}
554547
}
555548

0 commit comments

Comments
 (0)