PublishAgent skipping all items when CheckSecurity is activated

We ran into an issue when trying to publish the entire site on a regular basis using PublishAgent. We have it set up to publish the entire site every hour.

<agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="01:00:00">
 <param desc="source database">master</param>
 <param desc="target database">web</param>
 <param desc="mode (full or smart or incremental)">smart</param>
 <param desc="languages">en</param>
 </agent>

We noticed though, that new items weren’t being published. The publish log showed the following:

ManagedPoolThread #14 13:12:13 INFO PublishAgent started (source: master, target: web, mode: Smart, languages: en)
ManagedPoolThread #14 13:12:13 INFO Asynchronous publishing started. Job name: Publish to 'web'. Languages: en
10580 13:12:13 WARN SitePublish detected. PublishContext was overridden with DisableDatabaseCaches=True.
10580 13:12:13 INFO Starting [Publishing] - ProcessQueue
10580 13:13:04 INFO Finished [Publishing] - ProcessQueue in 50986 ms
10580 13:13:04 INFO Publish Mode : Full
10580 13:13:04 INFO Created : 0
10580 13:13:04 INFO Updated : 0
10580 13:13:04 INFO Deleted : 0
10580 13:13:04 INFO Skipped : 36712

Publishing manually was working fine.

After searching for a while, we found out the reason for PublishAgent skipping all items was quite obvious: We have set Publishing.CheckSecurity=true to make sure users could only publish the items they were allowed to. Unfortunately PublishAgent runs as sitecore\Anonymous who of course doesn’t have sufficient rights.

To solve this problem, you can implement a class that inherits PublishAgent and overrides the Run method. Then use UserSwitcher to switch to a user that has the appropriate rights.


3 responses to “PublishAgent skipping all items when CheckSecurity is activated”

  1. Hi Mark,

    Thanks a lot for this , When i was about to lose my hope and head to Sitecore Support i found this.

    Due to this setting i am getting all my logs proper just data was not getting transferred from master to web database, this setting triggered final solution. thank you

    You are a savior.

    – Vaibhao C

  2. Hi Mark,

    I am using this config setting as “true” in sitecore 9. In sitecore 9, Canpublish has below definition in Sitecore.Kernel
    public bool CanPublish(ID itemId, User user, ref string explanation)
    {
    Assert.ArgumentNotNull(itemId, “itemId”);
    Assert.ArgumentNotNull(user, “user”);
    Assert.ArgumentNotNull(explanation, “explanation”);
    if (!Settings.Publishing.CheckSecurity)
    {
    return true;
    }
    if (!this.CanPublishLanguage(itemId, user, ref explanation))
    {
    return false;
    }
    Item sourceItem = this.GetSourceItem(itemId);
    if (sourceItem == null)
    {
    return this.CanPublishDeletion(itemId, user, ref explanation);
    }
    return this.CanPublishUpdate(sourceItem, user, ref explanation);
    }

    Earlier (Sitecore 8.1) “CanPublishLanguage” was not there. I have given all the access on language but still, my items are getting skipped while publishing. It is returning false.

    If I make this setting as false then it is working fine.

    Please suggest if I am missing some more config change for this.

Leave a Reply to Vaibhao Chawale Cancel reply

Your email address will not be published. Required fields are marked *