I am trying to publish elements through code that has been modified in the Sitecore editor. If I update the field values ββprogrammatically and post these changes, it works fine.
Our content management editors regularly make changes to the editor without publishing them. We want to provide them with the functionality to click one button, which publishes all the relevant changes and clears the Sitecore cache.
I do not want to publish the entire site, only a few predefined elements.
We are currently using Sitecore.NET 6.4.1 (version 110720). I have no way to update Sitecore.
I tried these options:
Option 1: Create an Instance of a New Publisher Object
Database master = Sitecore.Configuration.Factory.GetDatabase("master"); Database web = Sitecore.Configuration.Factory.GetDatabase("web"); Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(master, web, Sitecore.Publishing.PublishMode.SingleItem, item.Language, System.DateTime.Now); Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions); publisher.Options.RootItem = item; publisher.Options.Deep = true; publisher.Publish();
Option 2: use a static publication editor
Database db = Sitecore.Configuration.Factory.GetDatabase("web"); Database[] databases = new Database[1] { db }; Sitecore.Handle publishHandle = Sitecore.Publishing.PublishManager.PublishItem(item, databases, db.Languages, true, false);
Both methods are enclosed in a using statement to use the same account that is used by content management editors.
string domainUser = @"sitecore\admin"; if (Sitecore.Security.Accounts.User.Exists(domainUser)) { Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(domainUser, false); using (new Sitecore.Security.Accounts.UserSwitcher(user)) {
Magazines show nothing remarkable as far as I can tell
ManagedPoolThread
This is definitely not a caching problem, because when manually published in the editor before clearing the cache programmatically, the changes are visible in the code.
So, I'm looking for a way to programmatically publish a predefined list of updated items, ignoring the editing method.