From 2aef75a70aa940eb702f8e01b6e40f7e9e6051cb Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Wed, 6 Feb 2013 09:10:08 -0100 Subject: [PATCH] Fixing SaveAndPublish method related to U4-1624 --- src/Umbraco.Core/Services/ContentService.cs | 58 ++++++++++--------- .../config/ClientDependency.config | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index c46e75faf9..ec1d53867e 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1261,6 +1261,7 @@ namespace Umbraco.Core.Services //Has this content item previously been published? If so, we don't need to refresh the children var previouslyPublished = HasPublishedVersion(content.Id); + var validForPublishing = true; //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) @@ -1269,7 +1270,7 @@ namespace Umbraco.Core.Services string.Format( "Content '{0}' with Id '{1}' could not be published because its parent is not published.", content.Name, content.Id)); - return false; + validForPublishing = false; } //Content contains invalid property values and can therefore not be published - fire event? @@ -1279,11 +1280,11 @@ namespace Umbraco.Core.Services string.Format( "Content '{0}' with Id '{1}' could not be published because of invalid properties.", content.Name, content.Id)); - return false; + validForPublishing = false; } //Publish and then update the database with new status - bool published = _publishingStrategy.Publish(content, userId); + bool published = validForPublishing && _publishingStrategy.Publish(content, userId); var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentRepository(uow)) @@ -1295,37 +1296,38 @@ namespace Umbraco.Core.Services uow.Commit(); + var xml = content.ToXml(); + //Preview Xml + var previewPoco = new PreviewXmlDto + { + NodeId = content.Id, + Timestamp = DateTime.Now, + VersionId = content.Version, + Xml = xml.ToString(SaveOptions.None) + }; + var previewExists = + uow.Database.ExecuteScalar("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version", + new { Id = content.Id, Version = content.Version }) != 0; + int previewResult = previewExists + ? uow.Database.Update( + "SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version", + new + { + Xml = previewPoco.Xml, + Timestamp = previewPoco.Timestamp, + Id = previewPoco.NodeId, + Version = previewPoco.VersionId + }) + : Convert.ToInt32(uow.Database.Insert(previewPoco)); + if (published) { - var xml = content.ToXml(); //Content Xml var contentPoco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) }; var contentExists = uow.Database.ExecuteScalar("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @Id", new { Id = content.Id }) != 0; int contentResult = contentExists ? uow.Database.Update(contentPoco) : Convert.ToInt32(uow.Database.Insert(contentPoco)); - //Preview Xml - var previewPoco = new PreviewXmlDto - { - NodeId = content.Id, - Timestamp = DateTime.Now, - VersionId = content.Version, - Xml = xml.ToString(SaveOptions.None) - }; - var previewExists = - uow.Database.ExecuteScalar("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version", - new {Id = content.Id, Version = content.Version}) != 0; - int previewResult = previewExists - ? uow.Database.Update( - "SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version", - new - { - Xml = previewPoco.Xml, - Timestamp = previewPoco.Timestamp, - Id = previewPoco.NodeId, - Version = previewPoco.VersionId - }) - : Convert.ToInt32(uow.Database.Insert(previewPoco)); } } @@ -1334,11 +1336,11 @@ namespace Umbraco.Core.Services Saved.RaiseEvent(new SaveEventArgs(content, false), this); //Save xml to db and call following method to fire event through PublishingStrategy to update cache - if (omitCacheRefresh == false) + if (published && 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 && previouslyPublished == false && HasChildren(content.Id)) + if (published && omitCacheRefresh == false && previouslyPublished == false && HasChildren(content.Id)) { var descendants = GetPublishedDescendants(content); diff --git a/src/Umbraco.Web.UI/config/ClientDependency.config b/src/Umbraco.Web.UI/config/ClientDependency.config index 91d1e0bb24..cb7e5c8250 100644 --- a/src/Umbraco.Web.UI/config/ClientDependency.config +++ b/src/Umbraco.Web.UI/config/ClientDependency.config @@ -10,7 +10,7 @@ NOTES: * Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config * A new version will invalidate both client and server cache and create new persisted files --> - +