Deal with fixmes in IContent IsCultureSomething
This commit is contained in:
@@ -32,6 +32,7 @@ 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>
|
||||
/// <param name="culture">An optional culture.</param>
|
||||
public Content(string name, IContent parent, IContentType contentType, string culture = null)
|
||||
: this(name, parent, contentType, new PropertyCollection(), culture)
|
||||
{ }
|
||||
@@ -43,6 +44,7 @@ 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>
|
||||
/// <param name="culture">An optional culture.</param>
|
||||
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string culture = null)
|
||||
: base(name, parent, contentType, properties, culture)
|
||||
{
|
||||
@@ -57,6 +59,7 @@ 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>
|
||||
/// <param name="culture">An optional culture.</param>
|
||||
public Content(string name, int parentId, IContentType contentType, string culture = null)
|
||||
: this(name, parentId, contentType, new PropertyCollection(), culture)
|
||||
{ }
|
||||
@@ -68,6 +71,7 @@ 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>
|
||||
/// <param name="culture">An optional culture.</param>
|
||||
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null)
|
||||
: base(name, parentId, contentType, properties, culture)
|
||||
{
|
||||
@@ -213,23 +217,23 @@ namespace Umbraco.Core.Models
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<string> PublishedCultures => _publishInfos?.Keys ?? Enumerable.Empty<string>();
|
||||
|
||||
//fixme should this return false if ID == 0?
|
||||
//fixme should this return false if IsCultureAvailable(culture) is false?
|
||||
/// <inheritdoc />
|
||||
public bool IsCulturePublished(string culture)
|
||||
// just check _publishInfos
|
||||
// a non-available culture could not become published anyways
|
||||
=> _publishInfos != null && _publishInfos.ContainsKey(culture);
|
||||
|
||||
//fixme should this return false if ID == 0?
|
||||
//fixme should this return false if IsCultureAvailable(culture) is false?
|
||||
/// <inheritdoc />
|
||||
public bool WasCulturePublished(string culture)
|
||||
// just check _publishInfosOrig - a copy of _publishInfos
|
||||
// a non-available culture could not become published anyways
|
||||
=> _publishInfosOrig != null && _publishInfosOrig.ContainsKey(culture);
|
||||
|
||||
//fixme should this return false if ID == 0?
|
||||
//fixme should this return false if IsCultureAvailable(culture) is false?
|
||||
/// <inheritdoc />
|
||||
public bool IsCultureEdited(string culture)
|
||||
=> !IsCulturePublished(culture) || (_editedCultures != null && _editedCultures.Contains(culture));
|
||||
=> IsCultureAvailable(culture) && // is available, and
|
||||
(!IsCulturePublished(culture) || // is not published, or
|
||||
(_editedCultures != null && _editedCultures.Contains(culture))); // is edited
|
||||
|
||||
/// <inheritdoc/>
|
||||
[IgnoreDataMember]
|
||||
|
||||
@@ -87,6 +87,8 @@ namespace Umbraco.Core.Models
|
||||
/// <para>A culture becomes published whenever values for this culture are published,
|
||||
/// and the content published name for this culture is non-null. It becomes non-published
|
||||
/// whenever values for this culture are unpublished.</para>
|
||||
/// <para>A culture becomes published as soon as PublishCulture has been invoked,
|
||||
/// even though the document might now have been saved yet (and can have no identity).</para>
|
||||
/// </remarks>
|
||||
bool IsCulturePublished(string culture);
|
||||
|
||||
@@ -107,8 +109,9 @@ namespace Umbraco.Core.Models
|
||||
/// 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>
|
||||
/// <para>A culture is edited when it is available, and not published or published but
|
||||
/// with changes.</para>
|
||||
/// <para>A culture can be edited even though the document might now have been saved yet (and can have no identity).</para>
|
||||
/// </remarks>
|
||||
bool IsCultureEdited(string culture);
|
||||
|
||||
|
||||
@@ -1073,7 +1073,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
NodeId = content.Id,
|
||||
LanguageId = LanguageRepository.GetIdByIsoCode(culture) ?? throw new InvalidOperationException("Not a valid culture."),
|
||||
Culture = culture,
|
||||
Edited = !content.IsCulturePublished(culture) || (editedCultures != null && editedCultures.Contains(culture)) // if not published, always edited
|
||||
|
||||
// if not published, always edited
|
||||
// no need to check for availability: it *is* available since it is in content.CultureNames
|
||||
Edited = !content.IsCulturePublished(culture) || (editedCultures != null && editedCultures.Contains(culture))
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -745,7 +745,7 @@ namespace Umbraco.Web.Editors
|
||||
//Check if a mandatory language is missing from being published
|
||||
|
||||
var variant = cultureVariants.First(x => x.Culture == lang.IsoCode);
|
||||
var isPublished = contentItem.PersistedContent.IsCultureAvailable(lang.IsoCode) && contentItem.PersistedContent.IsCulturePublished(lang.IsoCode);
|
||||
var isPublished = contentItem.PersistedContent.IsCulturePublished(lang.IsoCode);
|
||||
var isPublishing = variant.Publish;
|
||||
|
||||
if (!isPublished && !isPublishing)
|
||||
|
||||
@@ -28,8 +28,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
? PublishedState.Published
|
||||
: PublishedState.Unpublished;
|
||||
|
||||
//it can only be 'edited' if the content item is persisted and if the variant has a name and it's flagged as edited
|
||||
isEdited = source.Id > 0 && source.IsCultureAvailable(culture) && source.IsCultureEdited(culture);
|
||||
isEdited = source.IsCultureEdited(culture);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -37,17 +36,16 @@ namespace Umbraco.Web.Models.Mapping
|
||||
? PublishedState.Unpublished
|
||||
: PublishedState.Published;
|
||||
|
||||
isEdited = source.Id > 0 && source.Edited;
|
||||
isEdited = source.Edited;
|
||||
}
|
||||
|
||||
//now we can calculate the content state
|
||||
if (!isEdited && publishedState == PublishedState.Unpublished)
|
||||
return ContentSavedState.NotCreated;
|
||||
if (isEdited && publishedState == PublishedState.Unpublished)
|
||||
return ContentSavedState.Draft;
|
||||
if (!isEdited && publishedState == PublishedState.Published)
|
||||
return ContentSavedState.Published;
|
||||
return ContentSavedState.PublishedPendingChanges;
|
||||
if (publishedState == PublishedState.Unpublished)
|
||||
return isEdited && source.Id > 0 ? ContentSavedState.Draft : ContentSavedState.NotCreated;
|
||||
|
||||
if (publishedState == PublishedState.Published)
|
||||
return isEdited ? ContentSavedState.PublishedPendingChanges : ContentSavedState.Published;
|
||||
|
||||
throw new NotSupportedException($"PublishedState {publishedState} is not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user