Refactoring ChangePublishedState to use an enum instead of a boolean.

This commit is contained in:
Morten Christensen
2013-01-10 14:07:07 -01:00
parent 9974e9b312
commit ca2942fdd9
10 changed files with 40 additions and 23 deletions

View File

@@ -246,14 +246,14 @@ namespace Umbraco.Core.Models
/// <summary>
/// Changes the Published state of the content object
/// </summary>
/// <param name="isPublished">Boolean indicating whether content is published (true) or unpublished (false)</param>
public void ChangePublishedState(bool isPublished)
public void ChangePublishedState(PublishedState state)
{
Published = isPublished;
//NOTE Should this be checked against the Expire/Release dates?
//TODO possibly create new (unpublished version)?
Published = state == PublishedState.Published;
PublishedState = state;
}
internal PublishedState PublishedState { get; set; }
/// <summary>
/// Changes the Trashed state of the content object
/// </summary>
@@ -276,7 +276,7 @@ namespace Umbraco.Core.Models
//If the content is trashed and is published it should be marked as unpublished
if (isTrashed && Published)
{
ChangePublishedState(false);
ChangePublishedState(PublishedState.Unpublished);
}
}

View File

@@ -69,8 +69,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Changes the Published state of the content object
/// </summary>
/// <param name="isPublished">Boolean indicating whether content is published (true) or unpublished (false)</param>
void ChangePublishedState(bool isPublished);
void ChangePublishedState(PublishedState state);
/// <summary>
/// Changes the Trashed state of the content object

View File

@@ -0,0 +1,9 @@
namespace Umbraco.Core.Models
{
public enum PublishedState
{
Published,
Unpublished,
Saved
}
}

View File

@@ -262,8 +262,9 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistUpdatedItem(IContent entity)
{
var publishedState = ((Content) entity).PublishedState;
//A new version should only be created if published state (or language) has changed
bool shouldCreateNewVersion = ((ICanBeDirty)entity).IsPropertyDirty("Published") || ((ICanBeDirty)entity).IsPropertyDirty("Language");
bool shouldCreateNewVersion = (((ICanBeDirty)entity).IsPropertyDirty("Published") && publishedState != PublishedState.Unpublished) || ((ICanBeDirty)entity).IsPropertyDirty("Language");
if (shouldCreateNewVersion)
{
//Updates Modified date and Version Guid
@@ -299,8 +300,9 @@ namespace Umbraco.Core.Persistence.Repositories
Database.Update(newContentDto);
}
//If Published state has changed then previous versions should have their publish state reset
if (((ICanBeDirty)entity).IsPropertyDirty("Published") && entity.Published)
//If Published state has changed then previous versions should have their publish state reset.
//If state has been changed to unpublished the previous versions publish state should also be reset.
if (((ICanBeDirty)entity).IsPropertyDirty("Published") && (entity.Published || publishedState == PublishedState.Unpublished))
{
var publishedDocs = Database.Fetch<DocumentDto>("WHERE nodeId = @Id AND published = @IsPublished", new { Id = entity.Id, IsPublished = true });
foreach (var doc in publishedDocs)

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Core.Publishing
return false;
}
content.ChangePublishedState(true);
content.ChangePublishedState(PublishedState.Published);
LogHelper.Info<PublishingStrategy>(
string.Format("Content '{0}' with Id '{1}' has been published.",
@@ -106,7 +106,7 @@ namespace Umbraco.Core.Publishing
continue;
}
item.ChangePublishedState(true);
item.ChangePublishedState(PublishedState.Published);
LogHelper.Info<PublishingStrategy>(
string.Format("Content '{0}' with Id '{1}' has been published.",
@@ -138,8 +138,8 @@ namespace Umbraco.Core.Publishing
"Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
content.Name, content.Id));
}
content.ChangePublishedState(false);
content.ChangePublishedState(PublishedState.Unpublished);
LogHelper.Info<PublishingStrategy>(
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
@@ -173,7 +173,7 @@ namespace Umbraco.Core.Publishing
item.Name, item.Id));
}
item.ChangePublishedState(false);
item.ChangePublishedState(PublishedState.Unpublished);
LogHelper.Info<PublishingStrategy>(
string.Format("Content '{0}' with Id '{1}' has been unpublished.",

View File

@@ -652,7 +652,7 @@ namespace Umbraco.Core.Services
//Only change the publish state if the "previous" version was actually published
if (content.Published)
content.ChangePublishedState(false);
content.ChangePublishedState(PublishedState.Saved);
repository.AddOrUpdate(content);
uow.Commit();
@@ -690,7 +690,7 @@ namespace Umbraco.Core.Services
//Only change the publish state if the "previous" version was actually published
if (content.Published)
content.ChangePublishedState(false);
content.ChangePublishedState(PublishedState.Saved);
repository.AddOrUpdate(content);
uow.Commit();

View File

@@ -182,6 +182,7 @@
<Compile Include="Models\PropertyExtensions.cs" />
<Compile Include="Models\PropertyTypeExtensions.cs" />
<Compile Include="Models\PublishedItemType.cs" />
<Compile Include="Models\PublishedState.cs" />
<Compile Include="Models\Rdbms\ContentType2ContentTypeDto.cs" />
<Compile Include="Models\Rdbms\PropertyTypeGroupDto.cs" />
<Compile Include="Models\Relation.cs" />

View File

@@ -319,7 +319,7 @@ namespace Umbraco.Tests.Models
// Act
content.ResetDirtyProperties();
content.ChangePublishedState(true);
content.ChangePublishedState(PublishedState.Published);
// Assert
Assert.That(content.IsPropertyDirty("Published"), Is.True);

View File

@@ -61,7 +61,7 @@ namespace Umbraco.Tests.Services
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1047
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
subpage.ReleaseDate = DateTime.Now.AddMinutes(-5);
subpage.ChangePublishedState(false);
subpage.ChangePublishedState(PublishedState.Saved);
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1048

View File

@@ -665,9 +665,15 @@ namespace umbraco.cms.businesslogic.web
set
{
_published = value;
Content.ChangePublishedState(value);
/*SqlHelper.ExecuteNonQuery(
string.Format("update cmsDocument set published = {0} where nodeId = {1}", Id, value ? 1 : 0));*/
if (_published)
{
Content.ChangePublishedState(PublishedState.Published);
}
else
{
Content.ChangePublishedState(PublishedState.Unpublished);
}
}
}