Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Sitecore publish draft items from the C# API, and how do I stop it doing so?
    primarykey
    data
    text
    <p>I'm running a scheduled publish of my Sitecore master DB using the Sitecore publishing API. I call a web service at scheduled intervals during the day which runs the following code (slightly condensed for readability):</p> <pre class="lang-cs prettyprint-override"><code>// grab the root content node from sitecore Item contentNode = dbSource.Items[ID.Parse("{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}")]; PublishOptions options = new PublishOptions(sourceDatabase, targetDatabase, PublishMode.Smart, lang, DateTime.Now); options.RootItem = contentNode; options.Deep = true; Publisher p = new Publisher(options); p.PublishAsync(); </code></pre> <p>When we run the above code it publishes everything in the content node, including all descendants, regardless of workflow state. It's like it is ignoring the workflow completely. This is not what we are after, and is causing lots of problems on our live website.</p> <p>If we run the same action from within Sitecore Desktop it publishes everything in the content node, including all descendants, that are <strong>publishable</strong> (I.e. in the final workflow stage). <strong><em>It does not publish any items in the tree that are still in draft mode. This is the required bahaviour.</em></strong></p> <p>I have tried implementing the code as a non-admin user by surrounding the above code with the following using statement:</p> <pre class="lang-cs prettyprint-override"><code>string userName = @"sitecore\******"; Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(userName, true); user.RuntimeSettings.IsAdministrator = false; using (new Sitecore.Security.Accounts.UserSwitcher(user)) { ... } </code></pre> <p>Unfortunately this has had no effect.</p> <p>Is there something obvious I've missed, or am I doing it right and Sitecore is doing it wrong? Can anyone help please?</p> <p>The strange thing I noticed, also, is that the draft items that were published, when viewed on the live database, were showing absolutely nothing in the Sitecore Desktop in terms of fields or meta data. They were also showing a warning that "The current item does not have a version in "English : English".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload