4

During certain periods we have the requirement to disable publishing for a period of time. The current approach for this is pretty brute-force. Delete the Publishing Targets and then restore them from the Recycle bin later that day as required.

Does anyone know of a nicer way of doing this which ideally maintains the Publishing Targets but disables the Publishing Targets in some way or removes permissions for all users? - something along those lines, maybe using SPE to automate it.

1
  • I haven’t had chance to try this yet but your answer is what I was after so I’ll upvote and accept. Nov 26, 2018 at 10:19

3 Answers 3

7

a) Manual way through Sitecore PowerShell IDE

You can achieve this by Sitecore Powershell Extensions (SPE).

As your requirement is to enable/disable publishing targets, I would set Write permissions and keep Read permissions enabled. This will still show those publishing targets but enable/disable them as needed.

SPE script to disable Publishing Target:

$acl = New-ItemAcl -AccessRight item:write -PropagationType Any -SecurityPermission DenyAccess -Identity "{username_goes_here}"

Get-Item -Path "master:\system\Publishing targets\{your publishing target goes here}" | Set-ItemAcl -AccessRules $acl -PassThru

SPE script to enable Publishing Target:

$acl = New-ItemAcl -AccessRight item:write -PropagationType Any -SecurityPermission AllowAccess -Identity "{username_goes_here}"

Get-Item -Path "master:\system\Publishing targets\{your publishing target goes here}" | Set-ItemAcl -AccessRules $acl -PassThru

b) Automated way through Sitecron

More automated way would be to combine SiteCron and these Powershell scripts mentioned above.

To do that:

  1. Create corresponding Powershell Script items under /sitecore/system/Modules/PowerShell/Script Library/Sitecron/Publishing Targets/. I have created these items based on "PowerShell Script" template. The parent item "Publishing Target" was created based on "PowerShell Script Library" template

    enter image description here

    enter image description here

  2. Create corresponding Sitecron Jobs under /sitecore/system/Modules/Sitecron/. Specify Type field as Sitecron.Jobs.PowerShell.ExecuteScript, Sitecron. I have created them based on "Sitecron job" template:

    enter image description here

    enter image description here

    and just assigned scripts created in step 1 in "Items" field:

    enter image description here

    enter image description here

3
  • Thanks Peter, this looks spot on. I had a look at the docs last night and got the basics of this but you’ve done a much better job. I’ll let you know if it all works ok. Nov 7, 2018 at 9:10
  • I have even gone further and will update answer with how to make it working in Sitecron in more automated / scheduled way soon Nov 7, 2018 at 9:12
  • Nice one Peter. I believe SPE has integration with SiteCron to run the Powershell script on a schedule now so that shouldn’t be too tricky. Nov 7, 2018 at 9:14
0

Use SPE to remove the Read permission of the publishing target, then reinstate it later. One option is to use SiteCron, another option is to install SPE.Remoting, then use an external schedule task (windows schedule task or azure webjobs) to trigger the powershell scripts.

4
  • Thanks Vincent, if you've done this before do you have a script you'd be able to share with the Community? Nov 6, 2018 at 22:44
  • Does this help ? doc.sitecorepowershell.com/appendix/security/set-itemacl Nov 6, 2018 at 22:59
  • 2
    This is "meta describing" a solution and answer - not actually answering. Nov 6, 2018 at 23:03
  • Thanks Vincent. Ideally I’m looking for a usable solution and am aware of SPE and SiteCron etc and what they can do. I though someone may have a script they have written to do this perhaps. Nov 6, 2018 at 23:11
0

If this restriction is frequent, you could make use of third-party modules on the Marketplace. One example is Deployment Mode

This module allows you to go on Deployment Mode and prevent non-admin users from logging in to Sitecore (you can exclude specified Roles from this restriction) or you can prevent users from publishing anything until deployment is done. It is easy to use. you will only have to work with one settings item under /sitecore/System/Settings/Deployment Mode Settings.

Or you could create such a simple module yourself and make use of it every time you need this restriction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.