diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 22c409d8b1..4ead233d6a 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -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 _publishInfos; private HashSet _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); } - + /// [IgnoreDataMember] //public IReadOnlyDictionary PublishNames => _publishNames ?? NoNames; public IReadOnlyDictionary PublishNames => _publishInfos?.ToDictionary(x => x.Key, x => x.Value.Name) ?? NoNames; - + /// 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; } - + /// public bool IsCulturePublished(string culture) => !string.IsNullOrWhiteSpace(GetPublishName(culture)); - + /// public DateTime GetDateCulturePublished(string culture) { @@ -270,26 +270,35 @@ namespace Umbraco.Core.Models throw new InvalidOperationException($"Culture \"{culture}\" is not published."); } + /// + public IEnumerable PublishedCultures => _publishInfos.Keys; + /// 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(StringComparer.OrdinalIgnoreCase); _edited.Add(culture); - } - + } + // sets all publish edited internal void SetCultureEdited(IEnumerable cultures) { _edited = new HashSet(cultures, StringComparer.OrdinalIgnoreCase); } - + + /// + public IEnumerable EditedCultures => Names.Keys.Where(IsCultureEdited); + + /// + public IEnumerable 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; } /// 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; } /// 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)); } diff --git a/src/Umbraco.Core/Models/IContent.cs b/src/Umbraco.Core/Models/IContent.cs index ab995b9b04..25f980a597 100644 --- a/src/Umbraco.Core/Models/IContent.cs +++ b/src/Umbraco.Core/Models/IContent.cs @@ -90,10 +90,18 @@ namespace Umbraco.Core.Models /// bool IsCulturePublished(string culture); - // fixme doc + /// + /// Gets the date a culture was published. + /// DateTime GetDateCulturePublished(string culture); - // fixme doc + /// + /// Gets a value indicated whether a given culture is edited. + /// + /// + /// A culture is edited when it is not published, or when it is published but + /// it has changes. + /// bool IsCultureEdited(string culture); /// @@ -114,6 +122,21 @@ namespace Umbraco.Core.Models /// name, which must be get via the property. /// IReadOnlyDictionary PublishNames { get; } + + /// + /// Gets the available cultures. + /// + IEnumerable AvailableCultures { get; } + + /// + /// Gets the published cultures. + /// + IEnumerable PublishedCultures { get; } + + /// + /// Gets the edited cultures. + /// + IEnumerable EditedCultures { get; } // fixme - these two should move to some kind of service