diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index ed438d6967..a65b37f31d 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -1054,6 +1054,22 @@ namespace Umbraco.Core.Services
return SaveAndPublishDo(content, omitCacheRefresh, userId, raiseEvents);
}
+ ///
+ /// Gets a collection of descendants by the first Parent.
+ ///
+ /// item to retrieve Descendants from
+ /// An Enumerable list of objects
+ internal IEnumerable GetPublishedDescendants(IContent content)
+ {
+ using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
+ {
+ var query = Query.Builder.Where(x => x.Id != content.Id && x.Path.StartsWith(content.Path) && x.Published == true && x.Trashed == false);
+ var contents = repository.GetByQuery(query);
+
+ return contents;
+ }
+ }
+
#endregion
#region Private Methods
@@ -1243,6 +1259,9 @@ namespace Umbraco.Core.Services
return false;
}
+ //Has this content item previously been published? If so, we don't need to refresh the children
+ var previouslyPublished = HasPublishedVersion(content.Id);
+
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
if (content.ParentId != -1 && content.ParentId != -20 && IsPublishable(content) == false)
{
@@ -1294,13 +1313,12 @@ namespace Umbraco.Core.Services
if (omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
- //We need to check if children and their publish state to ensure that we republish content that was previously published
- if (omitCacheRefresh == false && HasChildren(content.Id))
+ //We need to check if children and their publish state to ensure that we 'republish' content that was previously published
+ if (omitCacheRefresh == false && previouslyPublished == false && HasChildren(content.Id))
{
- var children = GetDescendants(content);
- var shouldBeRepublished = children.Where(child => HasPublishedVersion(child.Id));
+ var descendants = GetPublishedDescendants(content);
- _publishingStrategy.PublishingFinalized(shouldBeRepublished, false);
+ _publishingStrategy.PublishingFinalized(descendants, false);
}
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId, content.Id);
diff --git a/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs b/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
index 46bc9099ac..282d93bd1c 100644
--- a/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
+++ b/src/Umbraco.Tests/Persistence/Querying/QueryBuilderTests.cs
@@ -1,6 +1,7 @@
using System;
using NUnit.Framework;
using Umbraco.Core.Models;
+using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Tests.TestHelpers;
@@ -78,5 +79,35 @@ namespace Umbraco.Tests.Persistence.Querying
Assert.That(strResult, Is.EqualTo(expectedResult));
Console.WriteLine(strResult);
}
+
+ [Test]
+ public void Can_Build_PublishedDescendants_Query_For_IContent()
+ {
+ // Arrange
+ var path = "-1,1046,1076,1089";
+ var id = 1046;
+ var nodeObjectTypeId = new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972");
+
+ var sql = new Sql();
+ sql.Select("*")
+ .From()
+ .InnerJoin()
+ .On(left => left.VersionId, right => right.VersionId)
+ .InnerJoin()
+ .On(left => left.NodeId, right => right.NodeId)
+ .InnerJoin()
+ .On(left => left.NodeId, right => right.NodeId)
+ .Where(x => x.NodeObjectType == nodeObjectTypeId);
+
+ var query = Query.Builder.Where(x => x.Path.StartsWith(path) && x.Id != id && x.Published == true && x.Trashed == false);
+
+ // Act
+ var translator = new SqlTranslator(sql, query);
+ var result = translator.Translate();
+ var strResult = result.SQL;
+
+ // Assert
+ Console.WriteLine(strResult);
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs
index 08fa0f6ed8..d6ef34ee67 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs
@@ -4,6 +4,7 @@ using System.Web.UI.WebControls;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
+using Umbraco.Core.Services;
using umbraco.BusinessLogic.Actions;
using umbraco.IO;
using umbraco.uicontrols.DatePicker;
@@ -316,6 +317,8 @@ namespace umbraco.cms.presentation
{
if (_document.Level == 1 || _document.PathPublished)
{
+ var previouslyPublished = _document.HasPublishedVersion();
+
Trace.Warn("before d.publish");
if (_document.PublishWithResult(base.getUser()))
@@ -330,15 +333,19 @@ namespace umbraco.cms.presentation
_documentHasPublishedVersion = _document.HasPublishedVersion();
- var descendants = ApplicationContext.Current.Services.ContentService.GetDescendants(_document.Id);
- var publishableDescendants = descendants.Where(descendant => descendant.HasPublishedVersion()).ToList();
- if(publishableDescendants.Any())
+ if (previouslyPublished == false)
{
- foreach (var descendant in publishableDescendants)
+ var descendants = ((ContentService) ApplicationContext.Current.Services.ContentService)
+ .GetPublishedDescendants(_document.Content).ToList();
+
+ if (descendants.Any())
{
- library.UpdateDocumentCache(descendant.Id);
+ foreach (var descendant in descendants)
+ {
+ library.UpdateDocumentCache(descendant.Id);
+ }
+ library.RefreshContent();
}
- library.RefreshContent();
}
}
else