diff --git a/src/Umbraco.Web/WebServices/BulkPublishController.cs b/src/Umbraco.Web/WebServices/BulkPublishController.cs index 88fe6965ee..74fdf75919 100644 --- a/src/Umbraco.Web/WebServices/BulkPublishController.cs +++ b/src/Umbraco.Web/WebServices/BulkPublishController.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Publishing; using Umbraco.Core.Services; using Umbraco.Web.Mvc; using umbraco; +using umbraco.cms.businesslogic.web; namespace Umbraco.Web.WebServices { @@ -26,11 +27,13 @@ namespace Umbraco.Web.WebServices [HttpPost] public JsonResult PublishDocument(int documentId, bool publishDescendants, bool includeUnpublished) { - var doc = Services.ContentService.GetById(documentId); - var contentService = (ContentService) Services.ContentService; - if (!publishDescendants) + var content = Services.ContentService.GetById(documentId); + var doc = new Document(content); + //var contentService = (ContentService) Services.ContentService; + if (publishDescendants == false) { - var result = contentService.SaveAndPublishInternal(doc); + //var result = contentService.SaveAndPublishInternal(content); + var result = doc.SaveAndPublish(UmbracoUser.Id); return Json(new { success = result.Success, @@ -39,13 +42,14 @@ namespace Umbraco.Web.WebServices } else { - var result = ((ContentService) Services.ContentService) - .PublishWithChildrenInternal(doc, UmbracoUser.Id, includeUnpublished) - .ToArray(); + /*var result = ((ContentService) Services.ContentService) + .PublishWithChildrenInternal(content, UmbracoUser.Id, includeUnpublished) + .ToArray();*/ + var result = doc.PublishWithSubs(UmbracoUser.Id, includeUnpublished); return Json(new { success = result.All(x => x.Success), - message = GetMessageForStatuses(result.Select(x => x.Result), doc) + message = GetMessageForStatuses(result.Select(x => x.Result), content) }); } } @@ -63,7 +67,7 @@ namespace Umbraco.Web.WebServices foreach (var msg in statuses .Where(x => ((int)x.StatusType) >= 10) .Select(GetMessageForStatus) - .Where(msg => !msg.IsNullOrWhiteSpace())) + .Where(msg => msg.IsNullOrWhiteSpace() == false)) { sb.AppendLine(msg.Trim()); } diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 815aa81fba..6be26cfa77 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Logging; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Persistence.Caching; +using Umbraco.Core.Publishing; using Umbraco.Core.Services; using umbraco.BusinessLogic; using umbraco.BusinessLogic.Actions; @@ -914,13 +915,76 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - var publishedResults = ((ContentService)ApplicationContext.Current.Services.ContentService) + IEnumerable> publishedResults = ((ContentService)ApplicationContext.Current.Services.ContentService) .PublishWithChildrenInternal(Content, u.Id); FireAfterPublish(e); } } + [Obsolete("Don't use! Only used internally to support the legacy events", false)] + internal IEnumerable> PublishWithSubs(int userId, bool includeUnpublished) + { + PublishEventArgs e = new PublishEventArgs(); + FireBeforePublish(e); + + IEnumerable> publishedResults = Enumerable.Empty>(); + + if (!e.Cancel) + { + publishedResults = ((ContentService) ApplicationContext.Current.Services.ContentService) + .PublishWithChildrenInternal(Content, userId, includeUnpublished); + + FireAfterPublish(e); + } + + return publishedResults; + } + + [Obsolete("Don't use! Only used internally to support the legacy events", false)] + internal Attempt SaveAndPublish(int userId) + { + var result = new Attempt(false, + new PublishStatus(Content, + PublishStatusType + .FailedCancelledByEvent)); + foreach (var property in GenericProperties) + { + Content.SetValue(property.PropertyType.Alias, property.Value); + } + + var saveArgs = new SaveEventArgs(); + FireBeforeSave(saveArgs); + + if (!saveArgs.Cancel) + { + var publishArgs = new PublishEventArgs(); + FireBeforePublish(publishArgs); + + 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); + base.VersionDate = Content.UpdateDate; + this.UpdateDate = Content.UpdateDate; + + //NOTE: This is just going to call the CMSNode Save which will launch into the CMSNode.BeforeSave and CMSNode.AfterSave evenths + // which actually do dick all and there's no point in even having them there but just in case for some insane reason someone + // has bound to those events, I suppose we'll need to keep this here. + base.Save(); + + //Launch the After Save event since we're doing 2 things in one operation: Saving and publishing. + FireAfterSave(saveArgs); + + //Now we need to fire the After publish event + FireAfterPublish(publishArgs); + } + } + + return result; + } + [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.UnPublish()", false)] public void UnPublish() {