Implement getting avail/edit/publish cultures
This commit is contained in:
@@ -19,7 +19,7 @@ namespace Umbraco.Core.Models
|
||||
private bool _published;
|
||||
private PublishedState _publishedState;
|
||||
private DateTime? _releaseDate;
|
||||
private DateTime? _expireDate;
|
||||
private DateTime? _expireDate;
|
||||
private Dictionary<string, (string Name, DateTime Date)> _publishInfos;
|
||||
private HashSet<string> _edited;
|
||||
|
||||
@@ -196,12 +196,12 @@ namespace Umbraco.Core.Models
|
||||
|
||||
[IgnoreDataMember]
|
||||
public ITemplate PublishTemplate { get; internal set; }
|
||||
|
||||
|
||||
[IgnoreDataMember]
|
||||
public string PublishName { get; internal set; }
|
||||
|
||||
// sets publish infos
|
||||
// internal for repositories
|
||||
// internal for repositories
|
||||
// clear by clearing name
|
||||
internal void SetPublishInfos(string culture, string name, DateTime date)
|
||||
{
|
||||
@@ -222,12 +222,12 @@ namespace Umbraco.Core.Models
|
||||
|
||||
_publishInfos[culture] = (name, date);
|
||||
}
|
||||
|
||||
|
||||
/// <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/>
|
||||
public string GetPublishName(string culture)
|
||||
{
|
||||
@@ -235,7 +235,7 @@ namespace Umbraco.Core.Models
|
||||
if (_publishInfos == null) return null;
|
||||
return _publishInfos.TryGetValue(culture, out var infos) ? infos.Name : null;
|
||||
}
|
||||
|
||||
|
||||
// clears a publish name
|
||||
private void ClearPublishName(string culture)
|
||||
{
|
||||
@@ -250,18 +250,18 @@ namespace Umbraco.Core.Models
|
||||
if (_publishInfos.Count == 0)
|
||||
_publishInfos = null;
|
||||
}
|
||||
|
||||
|
||||
// clears all publish names
|
||||
private void ClearPublishNames()
|
||||
{
|
||||
PublishName = null;
|
||||
_publishInfos = null;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsCulturePublished(string culture)
|
||||
=> !string.IsNullOrWhiteSpace(GetPublishName(culture));
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTime GetDateCulturePublished(string culture)
|
||||
{
|
||||
@@ -270,26 +270,35 @@ namespace Umbraco.Core.Models
|
||||
throw new InvalidOperationException($"Culture \"{culture}\" is not published.");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<string> PublishedCultures => _publishInfos.Keys;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsCultureEdited(string culture)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(GetPublishName(culture)) || (_edited != null && _edited.Contains(culture));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// sets a publish edited
|
||||
internal void SetCultureEdited(string culture)
|
||||
{
|
||||
if (_edited == null)
|
||||
_edited = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
_edited.Add(culture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// sets all publish edited
|
||||
internal void SetCultureEdited(IEnumerable<string> cultures)
|
||||
{
|
||||
_edited = new HashSet<string>(cultures, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<string> EditedCultures => Names.Keys.Where(IsCultureEdited);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<string> AvailableCultures => Names.Keys;
|
||||
|
||||
[IgnoreDataMember]
|
||||
public int PublishedVersionId { get; internal set; }
|
||||
|
||||
@@ -303,7 +312,7 @@ namespace Umbraco.Core.Models
|
||||
if (ValidateAll().Any())
|
||||
return false;
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// must be managed here as they depend on the existing / supported variations.
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
throw new InvalidOperationException($"Cannot publish invariant culture without a name.");
|
||||
@@ -319,21 +328,21 @@ namespace Umbraco.Core.Models
|
||||
// property.PublishAllValues only deals with supported variations (if any)
|
||||
foreach (var property in Properties)
|
||||
property.PublishAllValues();
|
||||
|
||||
|
||||
_publishedState = PublishedState.Publishing;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool PublishValues(string culture = null, string segment = null)
|
||||
{
|
||||
// the variation should be supported by the content type
|
||||
ContentType.ValidateVariation(culture, segment, throwIfInvalid: true);
|
||||
|
||||
{
|
||||
// the variation should be supported by the content type
|
||||
ContentType.ValidateVariation(culture, segment, throwIfInvalid: true);
|
||||
|
||||
// the values we want to publish should be valid
|
||||
if (Validate(culture, segment).Any())
|
||||
return false;
|
||||
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// must be managed here as they depend on the existing / supported variations.
|
||||
if (segment == null)
|
||||
@@ -347,18 +356,18 @@ namespace Umbraco.Core.Models
|
||||
// property.PublishValue throws on invalid variation, so filter them out
|
||||
foreach (var property in Properties.Where(x => x.PropertyType.ValidateVariation(culture, segment, throwIfInvalid: false)))
|
||||
property.PublishValue(culture, segment);
|
||||
|
||||
|
||||
_publishedState = PublishedState.Publishing;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool PublishCultureValues(string culture = null)
|
||||
{
|
||||
{
|
||||
// the values we want to publish should be valid
|
||||
if (ValidateCulture(culture).Any())
|
||||
return false;
|
||||
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// must be managed here as they depend on the existing / supported variations.
|
||||
var name = GetName(culture);
|
||||
@@ -369,7 +378,7 @@ namespace Umbraco.Core.Models
|
||||
// property.PublishCultureValues only deals with supported variations (if any)
|
||||
foreach (var property in Properties)
|
||||
property.PublishCultureValues(culture);
|
||||
|
||||
|
||||
_publishedState = PublishedState.Publishing;
|
||||
return true;
|
||||
}
|
||||
@@ -383,8 +392,8 @@ namespace Umbraco.Core.Models
|
||||
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// must be managed here as they depend on the existing / supported variations.
|
||||
ClearPublishNames();
|
||||
|
||||
ClearPublishNames();
|
||||
|
||||
_publishedState = PublishedState.Publishing;
|
||||
}
|
||||
|
||||
@@ -393,7 +402,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
// the variation should be supported by the content type
|
||||
ContentType.ValidateVariation(culture, segment, throwIfInvalid: true);
|
||||
|
||||
|
||||
// property.ClearPublishedValue throws on invalid variation, so filter them out
|
||||
foreach (var property in Properties.Where(x => x.PropertyType.ValidateVariation(culture, segment, throwIfInvalid: false)))
|
||||
property.ClearPublishedValue(culture, segment);
|
||||
@@ -415,10 +424,10 @@ namespace Umbraco.Core.Models
|
||||
// Name and PublishName are managed by the repository, but Names and PublishNames
|
||||
// must be managed here as they depend on the existing / supported variations.
|
||||
ClearPublishName(culture);
|
||||
|
||||
|
||||
_publishedState = PublishedState.Publishing;
|
||||
}
|
||||
|
||||
|
||||
private bool CopyingFromSelf(IContent other)
|
||||
{
|
||||
// copying from the same Id and VersionPk
|
||||
@@ -456,10 +465,10 @@ namespace Umbraco.Core.Models
|
||||
var value = published ? pvalue.PublishedValue : pvalue.EditedValue;
|
||||
SetValue(alias, value, pvalue.Culture, pvalue.Segment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// copy names
|
||||
ClearNames();
|
||||
ClearNames();
|
||||
foreach (var (languageId, name) in other.Names)
|
||||
SetName(languageId, name);
|
||||
Name = other.Name;
|
||||
@@ -498,9 +507,9 @@ namespace Umbraco.Core.Models
|
||||
|
||||
var alias = otherProperty.PropertyType.Alias;
|
||||
SetValue(alias, otherProperty.GetValue(culture, segment, published), culture, segment);
|
||||
}
|
||||
}
|
||||
|
||||
// copy name
|
||||
// copy name
|
||||
SetName(culture, other.GetName(culture));
|
||||
}
|
||||
|
||||
@@ -532,9 +541,9 @@ namespace Umbraco.Core.Models
|
||||
var value = published ? pvalue.PublishedValue : pvalue.EditedValue;
|
||||
SetValue(alias, value, pvalue.Culture, pvalue.Segment);
|
||||
}
|
||||
}
|
||||
|
||||
// copy name
|
||||
}
|
||||
|
||||
// copy name
|
||||
SetName(culture, other.GetName(culture));
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,18 @@ namespace Umbraco.Core.Models
|
||||
/// </remarks>
|
||||
bool IsCulturePublished(string culture);
|
||||
|
||||
// fixme doc
|
||||
/// <summary>
|
||||
/// Gets the date a culture was published.
|
||||
/// </summary>
|
||||
DateTime GetDateCulturePublished(string culture);
|
||||
|
||||
// fixme doc
|
||||
/// <summary>
|
||||
/// Gets a value indicated whether a given culture is edited.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>A culture is edited when it is not published, or when it is published but
|
||||
/// it has changes.</para>
|
||||
/// </remarks>
|
||||
bool IsCultureEdited(string culture);
|
||||
|
||||
/// <summary>
|
||||
@@ -114,6 +122,21 @@ namespace Umbraco.Core.Models
|
||||
/// name, which must be get via the <see cref="PublishName"/> property.</para>
|
||||
/// </remarks>
|
||||
IReadOnlyDictionary<string, string> PublishNames { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available cultures.
|
||||
/// </summary>
|
||||
IEnumerable<string> AvailableCultures { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published cultures.
|
||||
/// </summary>
|
||||
IEnumerable<string> PublishedCultures { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the edited cultures.
|
||||
/// </summary>
|
||||
IEnumerable<string> EditedCultures { get; }
|
||||
|
||||
// fixme - these two should move to some kind of service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user