diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs
index eca2b79984..622c9c347b 100644
--- a/src/Umbraco.Core/Models/Content.cs
+++ b/src/Umbraco.Core/Models/Content.cs
@@ -246,14 +246,14 @@ namespace Umbraco.Core.Models
///
/// Changes the Published state of the content object
///
- /// Boolean indicating whether content is published (true) or unpublished (false)
- 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; }
+
///
/// Changes the Trashed state of the content object
///
@@ -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);
}
}
diff --git a/src/Umbraco.Core/Models/IContent.cs b/src/Umbraco.Core/Models/IContent.cs
index 6583184d76..b2a35fabd2 100644
--- a/src/Umbraco.Core/Models/IContent.cs
+++ b/src/Umbraco.Core/Models/IContent.cs
@@ -69,8 +69,7 @@ namespace Umbraco.Core.Models
///
/// Changes the Published state of the content object
///
- /// Boolean indicating whether content is published (true) or unpublished (false)
- void ChangePublishedState(bool isPublished);
+ void ChangePublishedState(PublishedState state);
///
/// Changes the Trashed state of the content object
diff --git a/src/Umbraco.Core/Models/PublishedState.cs b/src/Umbraco.Core/Models/PublishedState.cs
new file mode 100644
index 0000000000..4469eba9cc
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedState.cs
@@ -0,0 +1,9 @@
+namespace Umbraco.Core.Models
+{
+ public enum PublishedState
+ {
+ Published,
+ Unpublished,
+ Saved
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
index 87faaf70df..29a0e14930 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
@@ -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("WHERE nodeId = @Id AND published = @IsPublished", new { Id = entity.Id, IsPublished = true });
foreach (var doc in publishedDocs)
diff --git a/src/Umbraco.Core/Publishing/PublishingStrategy.cs b/src/Umbraco.Core/Publishing/PublishingStrategy.cs
index e8d0958eec..17a80be37b 100644
--- a/src/Umbraco.Core/Publishing/PublishingStrategy.cs
+++ b/src/Umbraco.Core/Publishing/PublishingStrategy.cs
@@ -54,7 +54,7 @@ namespace Umbraco.Core.Publishing
return false;
}
- content.ChangePublishedState(true);
+ content.ChangePublishedState(PublishedState.Published);
LogHelper.Info(
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(
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(
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(
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index bfcb0ec2fe..58d7569d29 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -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();
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 1f3f033e44..c957a76178 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -182,6 +182,7 @@
+
diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs
index c0edec6979..4159380860 100644
--- a/src/Umbraco.Tests/Models/ContentTests.cs
+++ b/src/Umbraco.Tests/Models/ContentTests.cs
@@ -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);
diff --git a/src/Umbraco.Tests/Services/BaseServiceTest.cs b/src/Umbraco.Tests/Services/BaseServiceTest.cs
index ad8cf22596..6fb9334fd7 100644
--- a/src/Umbraco.Tests/Services/BaseServiceTest.cs
+++ b/src/Umbraco.Tests/Services/BaseServiceTest.cs
@@ -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
diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs
index 6b904bd71b..8a7731f665 100644
--- a/src/umbraco.cms/businesslogic/web/Document.cs
+++ b/src/umbraco.cms/businesslogic/web/Document.cs
@@ -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);
+
+ }
}
}