From a87b37d6ca9ccab42c808f92c84d3b143fbd0042 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 10 Oct 2013 09:35:23 +1100 Subject: [PATCH] Cleans up more of the IContentService and ensures that we have PublishStatus returned from the publishing methods instead of hiding them internally. --- src/Umbraco.Core/Publishing/PublishStatus.cs | 2 +- .../Publishing/PublishStatusType.cs | 2 +- src/Umbraco.Core/Services/ContentService.cs | 104 +++++++++++------- src/Umbraco.Core/Services/IContentService.cs | 30 +++++ src/umbraco.cms/businesslogic/web/Document.cs | 21 ++-- 5 files changed, 107 insertions(+), 52 deletions(-) diff --git a/src/Umbraco.Core/Publishing/PublishStatus.cs b/src/Umbraco.Core/Publishing/PublishStatus.cs index aee9a1fafe..865f00c58c 100644 --- a/src/Umbraco.Core/Publishing/PublishStatus.cs +++ b/src/Umbraco.Core/Publishing/PublishStatus.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Publishing /// /// The result of publishing a content item /// - internal class PublishStatus + public class PublishStatus { public PublishStatus() { diff --git a/src/Umbraco.Core/Publishing/PublishStatusType.cs b/src/Umbraco.Core/Publishing/PublishStatusType.cs index c3cb76e245..0d9ffcfa02 100644 --- a/src/Umbraco.Core/Publishing/PublishStatusType.cs +++ b/src/Umbraco.Core/Publishing/PublishStatusType.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Publishing /// /// Anything less than 10 = Success! /// - internal enum PublishStatusType + public enum PublishStatusType { /// /// The publishing was successful. diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 64bcaa4d8e..1df2133891 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -627,28 +627,53 @@ namespace Umbraco.Core.Services /// The to publish /// Optional Id of the User issueing the publishing /// True if publishing succeeded, otherwise False + [Obsolete("Use PublishWithStatus instead, that method will provide more detailed information on the outcome")] public bool Publish(IContent content, int userId = 0) { var result = SaveAndPublishDo(content, userId); return result.Success; } + /// + /// Publishes a single object + /// + /// The to publish + /// Optional Id of the User issueing the publishing + /// True if publishing succeeded, otherwise False + public Attempt PublishWithStatus(IContent content, int userId = 0) + { + return SaveAndPublishDo(content, userId); + } + /// /// Publishes a object and all its children /// /// The to publish along with its children /// Optional Id of the User issueing the publishing /// True if publishing succeeded, otherwise False + [Obsolete("Use PublishWithChildrenWithStatus instead, that method will provide more detailed information on the outcome and also allows the includeUnpublished flag")] public bool PublishWithChildren(IContent content, int userId = 0) { var result = PublishWithChildrenDo(content, userId, true); - + //This used to just return false only when the parent content failed, otherwise would always return true so we'll // do the same thing for the moment - if (!result.Any(x => x.Result.ContentItem.Id == content.Id)) - return false; + if (!result.Any(x => x.Result.ContentItem.Id == content.Id)) + return false; - return result.Single(x => x.Result.ContentItem.Id == content.Id).Success; + return result.Single(x => x.Result.ContentItem.Id == content.Id).Success; + } + + /// + /// Publishes a object and all its children + /// + /// The to publish along with its children + /// Optional Id of the User issueing the publishing + /// set to true if you want to also publish children that are currently unpublished + /// True if publishing succeeded, otherwise False + public IEnumerable> PublishWithChildrenWithStatus(IContent content, int userId = 0, bool includeUnpublished = false) + { + return PublishWithChildrenDo(content, userId, includeUnpublished); } /// @@ -669,12 +694,25 @@ namespace Umbraco.Core.Services /// Optional Id of the User issueing the publishing /// Optional boolean indicating whether or not to raise save events. /// True if publishing succeeded, otherwise False + [Obsolete("Use SaveAndPublishWithStatus instead, that method will provide more detailed information on the outcome")] public bool SaveAndPublish(IContent content, int userId = 0, bool raiseEvents = true) { var result = SaveAndPublishDo(content, userId, raiseEvents); return result.Success; } + /// + /// Saves and Publishes a single object + /// + /// The to save and publish + /// Optional Id of the User issueing the publishing + /// Optional boolean indicating whether or not to raise save events. + /// True if publishing succeeded, otherwise False + public Attempt SaveAndPublishWithStatus(IContent content, int userId = 0, bool raiseEvents = true) + { + return SaveAndPublishDo(content, userId, raiseEvents); + } + /// /// Saves a single object /// @@ -1329,42 +1367,30 @@ namespace Umbraco.Core.Services } #region Internal Methods - - /// - /// Internal method that Publishes a single object for legacy purposes. - /// - /// The to publish - /// Optional Id of the User issueing the publishing - /// True if publishing succeeded, otherwise False - internal Attempt PublishInternal(IContent content, int userId = 0) - { - return SaveAndPublishDo(content, userId); - } - /// - /// Internal method that Publishes a object and all its children for legacy purposes. - /// - /// The to publish along with its children - /// Optional Id of the User issueing the publishing - /// If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published - /// True if publishing succeeded, otherwise False - internal IEnumerable> PublishWithChildrenInternal( - IContent content, int userId = 0, bool includeUnpublished = false) - { - return PublishWithChildrenDo(content, userId, includeUnpublished); - } + ///// + ///// Internal method that Publishes a single object for legacy purposes. + ///// + ///// The to publish + ///// Optional Id of the User issueing the publishing + ///// True if publishing succeeded, otherwise False + //internal Attempt PublishInternal(IContent content, int userId = 0) + //{ + // return SaveAndPublishDo(content, userId); + //} - /// - /// Saves and Publishes a single object - /// - /// The to save and publish - /// Optional Id of the User issueing the publishing - /// Optional boolean indicating whether or not to raise save events. - /// True if publishing succeeded, otherwise False - internal Attempt SaveAndPublishInternal(IContent content, int userId = 0, bool raiseEvents = true) - { - return SaveAndPublishDo(content, userId, raiseEvents); - } + ///// + ///// Internal method that Publishes a object and all its children for legacy purposes. + ///// + ///// The to publish along with its children + ///// Optional Id of the User issueing the publishing + ///// If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published + ///// True if publishing succeeded, otherwise False + //internal IEnumerable> PublishWithChildrenInternal( + // IContent content, int userId = 0, bool includeUnpublished = false) + //{ + // return PublishWithChildrenDo(content, userId, includeUnpublished); + //} /// /// Gets a collection of descendants by the first Parent. @@ -1462,7 +1488,7 @@ namespace Umbraco.Core.Services /// then the list will only contain one status item, otherwise it will contain status items for it and all of it's descendants that /// are to be published. /// - private IEnumerable> PublishWithChildrenDo( + private IEnumerable> PublishWithChildrenDo( IContent content, int userId = 0, bool includeUnpublished = false) { if (content == null) throw new ArgumentNullException("content"); diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs index 8ac8ade1fb..a265b15092 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Core/Services/IContentService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; +using Umbraco.Core.Publishing; namespace Umbraco.Core.Services { @@ -246,16 +247,35 @@ namespace Umbraco.Core.Services /// The to publish /// Optional Id of the User issueing the publishing /// True if publishing succeeded, otherwise False + [Obsolete("Use PublishWithStatus instead, that method will provide more detailed information on the outcome")] bool Publish(IContent content, int userId = 0); + /// + /// Publishes a single object + /// + /// The to publish + /// Optional Id of the User issueing the publishing + /// The published status attempt + Attempt PublishWithStatus(IContent content, int userId = 0); + /// /// Publishes a object and all its children /// /// The to publish along with its children /// Optional Id of the User issueing the publishing /// True if publishing succeeded, otherwise False + [Obsolete("Use PublishWithChildrenWithStatus instead, that method will provide more detailed information on the outcome and also allows the includeUnpublished flag")] bool PublishWithChildren(IContent content, int userId = 0); + /// + /// Publishes a object and all its children + /// + /// The to publish along with its children + /// Optional Id of the User issueing the publishing + /// + /// The list of statuses for all published items + IEnumerable> PublishWithChildrenWithStatus(IContent content, int userId = 0, bool includeUnpublished = false); + /// /// UnPublishes a single object /// @@ -271,8 +291,18 @@ namespace Umbraco.Core.Services /// Optional Id of the User issueing the publishing /// Optional boolean indicating whether or not to raise save events. /// True if publishing succeeded, otherwise False + [Obsolete("Use SaveAndPublishWithStatus instead, that method will provide more detailed information on the outcome")] bool SaveAndPublish(IContent content, int userId = 0, bool raiseEvents = true); + /// + /// Saves and Publishes a single object + /// + /// The to save and publish + /// Optional Id of the User issueing the publishing + /// Optional boolean indicating whether or not to raise save events. + /// True if publishing succeeded, otherwise False + Attempt SaveAndPublishWithStatus(IContent content, int userId = 0, bool raiseEvents = true); + /// /// Permanently deletes an object. /// diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index eb5b97160e..32d61a3fe3 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -815,7 +815,7 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - var result = ((ContentService)ApplicationContext.Current.Services.ContentService).PublishInternal(Content, u.Id); + var result = ApplicationContext.Current.Services.ContentService.PublishWithStatus(Content, u.Id); _published = result.Success; FireAfterPublish(e); @@ -831,8 +831,7 @@ namespace umbraco.cms.businesslogic.web [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.PublishWithChildren()", false)] public bool PublishWithChildrenWithResult(User u) { - var result = ((ContentService)ApplicationContext.Current.Services.ContentService) - .PublishWithChildrenInternal(Content, u.Id, true); + var result = ApplicationContext.Current.Services.ContentService.PublishWithChildrenWithStatus(Content, u.Id, true); //This used to just return false only when the parent content failed, otherwise would always return true so we'll // do the same thing for the moment return result.Single(x => x.Result.ContentItem.Id == Id).Success; @@ -872,8 +871,8 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - IEnumerable> publishedResults = ((ContentService)ApplicationContext.Current.Services.ContentService) - .PublishWithChildrenInternal(Content, u.Id); + IEnumerable> publishedResults = ApplicationContext.Current.Services.ContentService + .PublishWithChildrenWithStatus(Content, u.Id); FireAfterPublish(e); } @@ -889,8 +888,8 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - publishedResults = ((ContentService) ApplicationContext.Current.Services.ContentService) - .PublishWithChildrenInternal(Content, userId, includeUnpublished); + publishedResults = ApplicationContext.Current.Services.ContentService + .PublishWithChildrenWithStatus(Content, userId, includeUnpublished); FireAfterPublish(e); } @@ -918,8 +917,8 @@ namespace umbraco.cms.businesslogic.web if (!publishArgs.Cancel) { //NOTE: The 'false' parameter will cause the PublishingStrategy events to fire which will ensure that the cache is refreshed. - result = ((ContentService)ApplicationContext.Current.Services.ContentService) - .SaveAndPublishInternal(Content, userId); + result = ApplicationContext.Current.Services.ContentService + .SaveAndPublishWithStatus(Content, userId); base.VersionDate = Content.UpdateDate; this.UpdateDate = Content.UpdateDate; @@ -1007,8 +1006,8 @@ namespace umbraco.cms.businesslogic.web if (!publishArgs.Cancel) { //NOTE: The 'false' parameter will cause the PublishingStrategy events to fire which will ensure that the cache is refreshed. - var result = ((ContentService)ApplicationContext.Current.Services.ContentService) - .SaveAndPublishInternal(Content, u.Id); + var result = ApplicationContext.Current.Services.ContentService + .SaveAndPublishWithStatus(Content, u.Id); base.VersionDate = Content.UpdateDate; this.UpdateDate = Content.UpdateDate;