A Master Key to Your Content

Wednesday, February 22, 2017 @ 08:00

By: Scott Gillis, Lead Consultant – Once in a while, I find myself in a situation where workflow hasn't been completed, but users have begun content entry or cleanup. Normally, these users also have not been setup as site admins, but with some level of custom accesses. This causes the editors to spend time dealing with locking and unlocking items for editing. At times, they'll not even realize and they locked the item, and you start to get a trail of items locked for editing and then forgotten.

What's an admin to do?

Without too much work, you can turn-on the gutter icon for 'Locked Items' and then drill through the Sitecore tree visually identifying and jotting down what's locked and by who.

Gutter Image

But that's tedious (and a bit error prone). As with all cool administrative tasks in Sitecore, we are best to turn our attention to Sitecore PowerShell Extensions (SPE) in the marketplace.

The SPE ships with functions that give us the ability to see and react to locked items on our site.

Get-LockedChildItem

Step 1 - Import Function

By default, the function Get-LockedChildItem is not callable. You must first 'import' it into your console or ISE session.

Import Function Image

    Import-Function Get-LockedChildItem

If you don't perform an import of the function, then you'll receive a red error message like the following

Get-LockedChildItem : The term 'Get-LockedChildItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Step 2 - Get a Report

Before performing any sort of automation on our content tree, we should always produce a report that provides some context of what may get changed. In this case, we want to get a listing of all items that are locked

    Get-LockedChildItem -Recurse | Show-ListView

Here we are using the 'Recurse' flag to walk the entire tree. The collection of items that are locked are then piped to the very nice Show-ListView, allowing for easy review and export.

Report Image

We can also run the report for specific users via the -LockedBy parameter

    Get-LockedChildItem -Recurse -LockedBy 'sitecore\editor' | Show-ListView

Step 3 - Time to Free the Content

Once we understand who has what locked, we can start performing some mass freeing of content with the -Unlock parameter. To unlock everything, we run

    Get-LockedChildItem -Recurse -Unlock

If we want to hand-pick a section of the site, we can either open the console to a certain node of the tree and run the commands above or define the start point with the -Path parameter. This will unlock all the children of the item defined by path, even providing a nice output of what was unlocked.

    Get-LockedChildItem -Recurse -Unlock -Path {85E0AF8C-ED9F-4CDA-BFB2-084015E17634}
    #or
    Get-LockedChildItem -Recurse -Unlock -Path /sitecore/content/Coffeehouse/Home/About-Us

Children Unlock Image

Finally, if we want to unlock for a specific individual, we can re-use the -LockedBy parameter:

    Get-LockedChildItem -Recurse -Unlock -LockedBy 'sitecore\editor'

Not a Replacement for workflow (i.e. the Disclaimer)

Being able to execute unlocking of content on a mass scale is helpful, but this shouldn't be the replacement for properly planned and built-out workflow on your site.

 

 

Scott Gillis, Lead Consultant at Paragon and 2017 Sitecore MVP, has been working with Sitecore for several years. He has a deep passion for helping clients leverage their content and data into powerful new capabilities in Sitecore and has produced successful outcomes as the technical lead on numerous, complex implementations. Recently, Scott has been focusing on helping these clients take advantage of the wealth of data collected by Sitecore Experience Analytics.