Mark's Sitecore Blog

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.

TwitterGoogle+Facebook 

3 thoughts on “PublishAgent skipping all items when CheckSecurity is activated

  1. Vaibhao Chawale

    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. Harmanjot Singh

    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.

    1. Harmanjot Singh

      This issue is with Sitecore 9 and got fixed in Sitecore 9.2. Raised this issue with sitecore and got the resolution for this.

      The reported issue looks like one that has been fixed in the Sitecore 9.0 Update-2: https://dev.sitecore.net/Downloads/Sitecore%20Experience%20Platform/90/Sitecore%20Experience%20Platform%2090%20Update2/Release%20Notes

      When the Publishing.CheckSecurity setting is set to true, non-admin users are not able to publish content items even when they have all the appropriate security permissions 206940
      To fix the issue we suggest you upgrade your Sitecore solution to the Sitecore XP 9.0 Update 2 (rev. 180604).

      In case it is not possible, you can try the following patch: https://sitecore.box.com/s/swae96e2hhgrbid3keccmvzr4e8kbvr7 To install the patch follow the instructions from the readme file inside the archive.

Leave a Reply to Vaibhao Chawale Cancel reply

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