Merge branch temp8 into temp8-U4-11227

This commit is contained in:
Stephan
2018-05-02 17:50:58 +02:00
45 changed files with 682 additions and 533 deletions

View File

@@ -31,8 +31,8 @@ namespace Umbraco.Core.Models
/// <param name="name">Name of the content</param>
/// <param name="parent">Parent <see cref="IContent"/> object</param>
/// <param name="contentType">ContentType for the current Content object</param>
public Content(string name, IContent parent, IContentType contentType)
: this(name, parent, contentType, new PropertyCollection())
public Content(string name, IContent parent, IContentType contentType, string culture = null)
: this(name, parent, contentType, new PropertyCollection(), culture)
{ }
/// <summary>
@@ -42,8 +42,8 @@ namespace Umbraco.Core.Models
/// <param name="parent">Parent <see cref="IContent"/> object</param>
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="properties">Collection of properties</param>
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties)
: base(name, parent, contentType, properties)
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string culture = null)
: base(name, parent, contentType, properties, culture)
{
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_publishedState = PublishedState.Unpublished;
@@ -56,8 +56,8 @@ namespace Umbraco.Core.Models
/// <param name="name">Name of the content</param>
/// <param name="parentId">Id of the Parent content</param>
/// <param name="contentType">ContentType for the current Content object</param>
public Content(string name, int parentId, IContentType contentType)
: this(name, parentId, contentType, new PropertyCollection())
public Content(string name, int parentId, IContentType contentType, string culture = null)
: this(name, parentId, contentType, new PropertyCollection(), culture)
{ }
/// <summary>
@@ -67,8 +67,8 @@ namespace Umbraco.Core.Models
/// <param name="parentId">Id of the Parent content</param>
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="properties">Collection of properties</param>
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties)
: base(name, parentId, contentType, properties)
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null)
: base(name, parentId, contentType, properties, culture)
{
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_publishedState = PublishedState.Unpublished;
@@ -207,20 +207,27 @@ namespace Umbraco.Core.Models
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullOrEmptyException(nameof(name));
if (culture == null)
// this is the only place where we set PublishName (apart from factories etc), and we must ensure
// that we do have an invariant name, as soon as we have a variant name, else we would end up not
// being able to publish - and not being able to change the name, as PublishName is readonly.
// see also: DocumentRepository.EnsureInvariantNameValues() - which deals with Name.
// see also: U4-11286
if (culture == null || string.IsNullOrEmpty(PublishName))
{
PublishName = name;
PublishDate = date;
return;
}
if (culture != null)
{
// private method, assume that culture is valid
if (_publishInfos == null)
_publishInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
_publishInfos[culture] = (name, date);
}
// private method, assume that culture is valid
if (_publishInfos == null)
_publishInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
_publishInfos[culture] = (name, date);
}
/// <inheritdoc/>

View File

@@ -31,8 +31,8 @@ namespace Umbraco.Core.Models
/// <summary>
/// Initializes a new instance of the <see cref="ContentBase"/> class.
/// </summary>
protected ContentBase(string name, int parentId, IContentTypeComposition contentType, PropertyCollection properties)
: this(name, contentType, properties)
protected ContentBase(string name, int parentId, IContentTypeComposition contentType, PropertyCollection properties, string culture = null)
: this(name, contentType, properties, culture)
{
if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId));
ParentId = parentId;
@@ -41,22 +41,23 @@ namespace Umbraco.Core.Models
/// <summary>
/// Initializes a new instance of the <see cref="ContentBase"/> class.
/// </summary>
protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties)
: this(name, contentType, properties)
protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties, string culture = null)
: this(name, contentType, properties, culture)
{
if (parent == null) throw new ArgumentNullException(nameof(parent));
SetParent(parent);
}
private ContentBase(string name, IContentTypeComposition contentType, PropertyCollection properties)
private ContentBase(string name, IContentTypeComposition contentType, PropertyCollection properties, string culture = null)
{
ContentTypeBase = contentType ?? throw new ArgumentNullException(nameof(contentType));
// initially, all new instances have
Id = 0; // no identity
VersionId = 0; // no versions
SetName(culture, name);
Name = name;
_contentTypeId = contentType.Id;
_properties = properties ?? throw new ArgumentNullException(nameof(properties));
_properties.EnsurePropertyTypes(PropertyTypes);

View File

@@ -159,20 +159,7 @@ namespace Umbraco.Core.Models
return Current.Services.MediaService.GetById(media.ParentId);
}
#endregion
#region Variants
/// <summary>
/// Returns true if the content has any property type that allows language variants
/// </summary>
public static bool HasPropertyTypeVaryingByCulture(this IContent content)
{
// fixme - what about CultureSegment? what about content.ContentType.Variations?
return content.PropertyTypes.Any(x => x.Variations.Has(ContentVariation.CultureNeutral));
}
#endregion
/// <summary>
/// Removes characters that are not valide XML characters from all entity properties
/// of type string. See: http://stackoverflow.com/a/961504/5018