Cleans up more of the IContentService and ensures that we have PublishStatus returned from the publishing methods instead of hiding them internally.
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Umbraco.Core.Publishing
|
||||
/// <summary>
|
||||
/// The result of publishing a content item
|
||||
/// </summary>
|
||||
internal class PublishStatus
|
||||
public class PublishStatus
|
||||
{
|
||||
public PublishStatus()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Umbraco.Core.Publishing
|
||||
/// <remarks>
|
||||
/// Anything less than 10 = Success!
|
||||
/// </remarks>
|
||||
internal enum PublishStatusType
|
||||
public enum PublishStatusType
|
||||
{
|
||||
/// <summary>
|
||||
/// The publishing was successful.
|
||||
|
||||
@@ -627,28 +627,53 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
public Attempt<PublishStatus> PublishWithStatus(IContent content, int userId = 0)
|
||||
{
|
||||
return SaveAndPublishDo(content, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a <see cref="IContent"/> object and all its children
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a <see cref="IContent"/> object and all its children
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="includeUnpublished">set to true if you want to also publish children that are currently unpublished</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
public IEnumerable<Attempt<PublishStatus>> PublishWithChildrenWithStatus(IContent content, int userId = 0, bool includeUnpublished = false)
|
||||
{
|
||||
return PublishWithChildrenDo(content, userId, includeUnpublished);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -669,12 +694,25 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves and Publishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
public Attempt<PublishStatus> SaveAndPublishWithStatus(IContent content, int userId = 0, bool raiseEvents = true)
|
||||
{
|
||||
return SaveAndPublishDo(content, userId, raiseEvents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
@@ -1329,42 +1367,30 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
/// <summary>
|
||||
/// Internal method that Publishes a single <see cref="IContent"/> object for legacy purposes.
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
internal Attempt<PublishStatus> PublishInternal(IContent content, int userId = 0)
|
||||
{
|
||||
return SaveAndPublishDo(content, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method that Publishes a <see cref="IContent"/> object and all its children for legacy purposes.
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="includeUnpublished">If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
internal IEnumerable<Attempt<PublishStatus>> PublishWithChildrenInternal(
|
||||
IContent content, int userId = 0, bool includeUnpublished = false)
|
||||
{
|
||||
return PublishWithChildrenDo(content, userId, includeUnpublished);
|
||||
}
|
||||
///// <summary>
|
||||
///// Internal method that Publishes a single <see cref="IContent"/> object for legacy purposes.
|
||||
///// </summary>
|
||||
///// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
///// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
///// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
//internal Attempt<PublishStatus> PublishInternal(IContent content, int userId = 0)
|
||||
//{
|
||||
// return SaveAndPublishDo(content, userId);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Saves and Publishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
internal Attempt<PublishStatus> SaveAndPublishInternal(IContent content, int userId = 0, bool raiseEvents = true)
|
||||
{
|
||||
return SaveAndPublishDo(content, userId, raiseEvents);
|
||||
}
|
||||
///// <summary>
|
||||
///// Internal method that Publishes a <see cref="IContent"/> object and all its children for legacy purposes.
|
||||
///// </summary>
|
||||
///// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
///// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
///// <param name="includeUnpublished">If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published</param>
|
||||
///// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
//internal IEnumerable<Attempt<PublishStatus>> PublishWithChildrenInternal(
|
||||
// IContent content, int userId = 0, bool includeUnpublished = false)
|
||||
//{
|
||||
// return PublishWithChildrenDo(content, userId, includeUnpublished);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> 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.
|
||||
/// </returns>
|
||||
private IEnumerable<Attempt<PublishStatus>> PublishWithChildrenDo(
|
||||
private IEnumerable<Attempt<PublishStatus>> PublishWithChildrenDo(
|
||||
IContent content, int userId = 0, bool includeUnpublished = false)
|
||||
{
|
||||
if (content == null) throw new ArgumentNullException("content");
|
||||
|
||||
@@ -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
|
||||
/// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[Obsolete("Use PublishWithStatus instead, that method will provide more detailed information on the outcome")]
|
||||
bool Publish(IContent content, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>The published status attempt</returns>
|
||||
Attempt<PublishStatus> PublishWithStatus(IContent content, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a <see cref="IContent"/> object and all its children
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a <see cref="IContent"/> object and all its children
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="includeUnpublished"></param>
|
||||
/// <returns>The list of statuses for all published items</returns>
|
||||
IEnumerable<Attempt<PublishStatus>> PublishWithChildrenWithStatus(IContent content, int userId = 0, bool includeUnpublished = false);
|
||||
|
||||
/// <summary>
|
||||
/// UnPublishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
@@ -271,8 +291,18 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
[Obsolete("Use SaveAndPublishWithStatus instead, that method will provide more detailed information on the outcome")]
|
||||
bool SaveAndPublish(IContent content, int userId = 0, bool raiseEvents = true);
|
||||
|
||||
/// <summary>
|
||||
/// Saves and Publishes a single <see cref="IContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
Attempt<PublishStatus> SaveAndPublishWithStatus(IContent content, int userId = 0, bool raiseEvents = true);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes an <see cref="IContent"/> object.
|
||||
/// </summary>
|
||||
|
||||
@@ -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<Attempt<PublishStatus>> publishedResults = ((ContentService)ApplicationContext.Current.Services.ContentService)
|
||||
.PublishWithChildrenInternal(Content, u.Id);
|
||||
IEnumerable<Attempt<PublishStatus>> 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user