I have been trying to publish items through code that have been changed in the Sitecore editor. If I update field values programatically and publish those changes, it works fine though.
Our content management editors regularly make changes in the editor without necessarily publishing them. We want to provide them with a functionality to click one button that publishes all relevant changes and clears the Sitecore cache.
I don't want to publish the whole site, only several predefined items.
We are currently using Sitecore.NET 6.4.1 (rev. 110720). I am not in the possibility to update Sitecore.
I tried these options:
Option 1: instantiating 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: using the static publishmanager
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 wrapped in a using statement to use the same account which is used by the 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))
{
// publish code ...
}
}
The logs don't show anything noteworthy as far as I can tell
ManagedPoolThread #7 13:41:46 INFO Job started: Publish to 'web'
ManagedPoolThread #7 13:41:46 INFO HtmlCacheClearer clearing HTML caches for all sites (5).
ManagedPoolThread #7 13:41:46 INFO HtmlCacheClearer done.
ManagedPoolThread #7 13:41:46 INFO Job ended: Publish to 'web' (units processed: 2)
ManagedPoolThread #5 13:41:46 INFO Job ended: Publish (units processed: )
It is definetely not a caching issue, because when publishing manually in the editor before clearing the cache programatically, the changes are visible in code.
So I'm looking for a way to programatically publish a predefined list of updated items, disregarding the way the edit has been made.