Publishing Page Drafts Systematically
Hi,
I have a question about systematically publishing page drafts. I have the following code (which runs only when the app is first started):
PageManager pageManager = PageManager.GetManager();
App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
.ThatAreDrafts()
.ForEach(dr =>
List<PageData> drafts = pageManager
.GetPageDataList()
.Where(
pd => pd.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
.ToList();
drafts.ForEach(dp =>
pageManager.PublishPageDraft(dp.Id,
true
);
pageManager.SaveChanges();
);
//ends ForEeach body on Page Drafts
);
You are trying to access item that no longer exists. The most probable reason
is
that it has been deleted by another user.
Exception Details: Telerik.Sitefinity.SitefinityExceptions.ItemNotFoundException: You are trying to access item that no longer exists. The most probable reason
is
that it has been deleted by another user.
Line 63: drafts.ForEach(dp =>
Line 64:
Line 65: pageManager.PublishPageDraft(dp.Id,
true
);
Line 66: pageManager.SaveChanges();
Line 67: );
[ItemNotFoundException: You are trying to access item that no longer exists. The most probable reason
is
that it has been deleted by another user.]
DynamicModule.ns.Wrapped_OpenAccessPageProvider_1d5e01b9d17e4c38be1673cc0f9c55f3.GetDraft(Guid id) +293
Telerik.Sitefinity.Modules.Pages.PageManager.GetDraft(Guid id) +87
Telerik.Sitefinity.Modules.Pages.PageManager.PublishPageDraft(Guid draftId, Boolean makeVisible) +58
Just thought I would note, I did try this first:
App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend) .ThatAreDrafts().Publish(); Also, I am impersonating a user with:User user = UserManager.GetManager().GetUser("admin");SitefinityPrincipal principal = new SitefinityPrincipal(new UserIdentity(user));Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
Hi Todd,
Please try using the below sample, it will take all draft pages and publish them accordingly:
var pageManager = PageManager.GetManager();
var pages = pageManager.GetPageNodes().Where(p => p.Page !=
null
&& p.Page.Status != Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).ToList();
foreach
(var pD
in
pages)
var draft = pageManager.EditPage(pD.Page.Id);
var master = pageManager.PagesLifecycle.CheckOut(draft);
if
(master !=
null
)
master = pageManager.PagesLifecycle.CheckIn(master);
pageManager.PagesLifecycle.Publish(master);
pageManager.SaveChanges();
WorkflowManager.MessageWorkflow(pD.Id,
typeof
(PageNode),
null
,
"Publish"
,
false
,
new
Dictionary<
string
,
string
>());