Refactor content culture & variations
This commit is contained in:
@@ -225,7 +225,6 @@ namespace Umbraco.Core.Models
|
||||
|
||||
/// <inheritdoc/>
|
||||
[IgnoreDataMember]
|
||||
//public IReadOnlyDictionary<string, string> PublishNames => _publishNames ?? NoNames;
|
||||
public IReadOnlyDictionary<string, string> PublishNames => _publishInfos?.ToDictionary(x => x.Key, x => x.Value.Name) ?? NoNames;
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -263,7 +262,7 @@ namespace Umbraco.Core.Models
|
||||
=> !string.IsNullOrWhiteSpace(GetPublishName(culture));
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTime GetDateCulturePublished(string culture)
|
||||
public DateTime GetCulturePublishDate(string culture)
|
||||
{
|
||||
if (_publishInfos != null && _publishInfos.TryGetValue(culture, out var infos))
|
||||
return infos.Date;
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -25,7 +26,7 @@ namespace Umbraco.Core.Models
|
||||
protected IContentTypeComposition ContentTypeBase;
|
||||
private int _writerId;
|
||||
private PropertyCollection _properties;
|
||||
private Dictionary<string, string> _names;
|
||||
private Dictionary<string, (string Name, DateTime Date)> _cultureInfos;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentBase"/> class.
|
||||
@@ -139,16 +140,30 @@ namespace Umbraco.Core.Models
|
||||
|
||||
/// <inheritdoc />
|
||||
[DataMember]
|
||||
public virtual IReadOnlyDictionary<string, string> Names
|
||||
{
|
||||
get => _names ?? NoNames;
|
||||
set
|
||||
{
|
||||
foreach (var (culture, name) in value)
|
||||
SetName(culture, name);
|
||||
}
|
||||
}
|
||||
public virtual IReadOnlyDictionary<string, string> Names => _cultureInfos?.ToDictionary(x => x.Key, x => x.Value.Name) ?? NoNames;
|
||||
|
||||
// sets culture infos
|
||||
// internal for repositories
|
||||
// clear by clearing name
|
||||
internal void SetCultureInfos(string culture, string name, DateTime date)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
if (culture == null)
|
||||
{
|
||||
Name = name;
|
||||
return;
|
||||
}
|
||||
|
||||
// private method, assume that culture is valid
|
||||
|
||||
if (_cultureInfos == null)
|
||||
_cultureInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
_cultureInfos[culture] = (name, date);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void SetName(string culture, string name)
|
||||
{
|
||||
@@ -166,11 +181,11 @@ namespace Umbraco.Core.Models
|
||||
|
||||
if (!ContentTypeBase.Variations.HasAny(ContentVariation.CultureNeutral | ContentVariation.CultureSegment))
|
||||
throw new NotSupportedException("Content type does not support varying name by culture.");
|
||||
|
||||
if (_cultureInfos == null)
|
||||
_cultureInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (_names == null)
|
||||
_names = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
_names[culture] = name;
|
||||
_cultureInfos[culture] = (name, DateTime.Now) ;
|
||||
OnPropertyChanged(Ps.Value.NamesSelector);
|
||||
}
|
||||
|
||||
@@ -178,8 +193,8 @@ namespace Umbraco.Core.Models
|
||||
public virtual string GetName(string culture)
|
||||
{
|
||||
if (culture == null) return Name;
|
||||
if (_names == null) return null;
|
||||
return _names.TryGetValue(culture, out var name) ? name : null;
|
||||
if (_cultureInfos == null) return null;
|
||||
return _cultureInfos.TryGetValue(culture, out var infos) ? infos.Name : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -194,17 +209,25 @@ namespace Umbraco.Core.Models
|
||||
return;
|
||||
}
|
||||
|
||||
if (_names == null) return;
|
||||
_names.Remove(culture);
|
||||
if (_names.Count == 0)
|
||||
_names = null;
|
||||
if (_cultureInfos == null) return;
|
||||
_cultureInfos.Remove(culture);
|
||||
if (_cultureInfos.Count == 0)
|
||||
_cultureInfos = null;
|
||||
}
|
||||
|
||||
protected virtual void ClearNames()
|
||||
{
|
||||
_names = null;
|
||||
_cultureInfos = null;
|
||||
OnPropertyChanged(Ps.Value.NamesSelector);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTime GetCultureDate(string culture)
|
||||
{
|
||||
if (_cultureInfos != null && _cultureInfos.TryGetValue(culture, out var infos))
|
||||
return infos.Date;
|
||||
throw new InvalidOperationException($"Culture \"{culture}\" is not available.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the date a culture was published.
|
||||
/// </summary>
|
||||
DateTime GetDateCulturePublished(string culture);
|
||||
DateTime GetCulturePublishDate(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicated whether a given culture is edited.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -46,13 +47,13 @@ namespace Umbraco.Core.Models
|
||||
string GetName(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the names of the content item.
|
||||
/// Gets the names of the content item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Because a dictionary key cannot be <c>null</c> this cannot get nor set the invariant
|
||||
/// <para>Because a dictionary key cannot be <c>null</c> this cannot get the invariant
|
||||
/// name, which must be get or set via the <see cref="TreeEntityBase.Name"/> property.</para>
|
||||
/// </remarks>
|
||||
IReadOnlyDictionary<string, string> Names { get; set; }
|
||||
IReadOnlyDictionary<string, string> Names { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a given culture is available.
|
||||
@@ -63,6 +64,11 @@ namespace Umbraco.Core.Models
|
||||
/// </remarks>
|
||||
bool IsCultureAvailable(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date a culture was created.
|
||||
/// </summary>
|
||||
DateTime GetCultureDate(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// List of properties, which make up all the data available for this Content object
|
||||
/// </summary>
|
||||
|
||||
@@ -3,21 +3,6 @@ using Umbraco.Core.Exceptions;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the culture specific data for a <see cref="IPublishedContent"/> item
|
||||
/// </summary>
|
||||
public struct PublishedCultureName
|
||||
{
|
||||
public PublishedCultureName(string name, string urlName) : this()
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
UrlName = urlName ?? throw new ArgumentNullException(nameof(urlName));
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string UrlName { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains culture specific values for <see cref="IPublishedContent"/>.
|
||||
/// </summary>
|
||||
Reference in New Issue
Block a user