25

Our editors would like to be able to see all locked items at a glance to be able to clean up locks.

There is of course the option to show locked items in the Quick Action Bar in the content tree, but it doesn't show if any descendents are locked, only items currently showing so this doesn't really help.

Is there something out of the box or do we need to use Sitecore Powershell Extensions or something else?

7 Answers 7

23

Sitecore Powershell Extensions is always the answer. There is a standard report available. More info here.

But just in case you might want to try something else:

  1. Sitecore query : /sitecore//*[@__lock!='' and @__lock!='<r />'] This could take a while though..
  2. Index query: (lock:true AND _latestversion:true) You could skip the latest version here if you want it for all versions..

Credits to Dan Sinclair.

3
  • In the Sitecore query version, could @__lock ever be null? Is it worth including @__lock!=null in the query? Commented Oct 11, 2016 at 10:48
  • A null check wouldn't add relevance to the query, it's not needed. Can you even do that in a query? (never did it myself, but I also can't remember the last time I actually used a Sitecore query...)
    – Gatogordo
    Commented Oct 11, 2016 at 11:01
  • You can use SPE to run Sitecore queries. Check out the -Query parameter on Get-Item. Commented Oct 11, 2016 at 15:23
10

If the users just want to see their own locked items then they can see a list of all the items and unlock them all via the My Items options in the Ribbon:

My Items

Locked Items List

7

You can use powershell to achieve this:

gci master:\content -rec | where { $_.Locking.IsLocked() } | 
    select Name, Id, @{n="IsLocked";e={$_.Locking.IsLocked()}}

The following aliases or shortened commands were used:

gci = Get-ChildItem
where = Where-Object
select = Select-Object

More info at http://michaellwest.blogspot.com/2013/09/SPE-UnlockItems.html

Or, using XPath

/sitecore//*[@__lock!='' and @__lock!='<r />']

Note that it is not recommended to run XPATH on Live site since it may cause performance issue if you have too many items.

More info at https://blog.horizontalintegration.com/2016/09/08/sitecore-query-xpath-for-finding-all-locked-items/

4

I've installed the Advanced System Reporter module in the past, and the content team really enjoyed some of the reports that could be created. Viewing locked items is one, but the tool is pretty granular so it can give a bunch of different insights.

1
  • This module looks really useful, thanks for sharing! Commented Oct 15, 2016 at 9:52
3

Instead of getting Content Editors to do this you could look at an solution to Auto-unlock items.

We've implemented a solution for this as a Sitecore Tasks as described by Mike Reynolds here:

https://sitecorejunkie.com/2013/09/28/periodically-unlock-items-of-idle-users-in-sitecore/

We've got it set in config to run every 4hrs:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="UnlockItems.ElapsedTimeWhenIdle" value="00:04:00:00" />
    </settings>
  </sitecore>
</configuration> 

This works really well for us and avoid content authors leaving items locked and having to manually unlock them.

--Update--

Another option is to allow users to unlock other users items based on a permission you can assign them. Here are two articles explaining how to go about this:

http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/02/allow-users-to-unlock-items-locked-to-others-in-the-sitecore-aspnet-cms.aspx

https://briancaos.wordpress.com/2010/09/10/unlock-sitecore-items/

We didn't do this but It seems like a nice solution also for trusted content authors.

4
  • This could also be a solution, depending on why they want the list. Commented Oct 11, 2016 at 10:58
  • Yeah if thats why they want a list then this may work better. We've had no problems with locked items since we implemented this. As @jammykam has mentioned below though if users want to check items they have locked themselves then they should use the 'My Items' menu option - however this doesn't show items locked by others. Annoying there isn't an 'View All Locked Items' menu option for admins to see them for "all users / specific users". A nice idea for a plugin maybe - with a screen to unlock them all. I've updated my answer above to include some info on another option we considered too. Commented Oct 11, 2016 at 11:02
  • @aseabridge I used this a long time ago, I believe it should still work in latest Sitecore: learnsitecore.cmsuniverse.net/en/Developers/Articles/2009/10/…
    – jammykam
    Commented Oct 11, 2016 at 12:34
  • @jammykam - Nice. So it's a SheerUI implementation of a lock manager for all users. Could come in useful. Commented Oct 11, 2016 at 12:40
0

Here is an example on how to get all locked items by language and version.

Import-Function -Name Invoke-SqlCommand

$owner = "sitecore\admin"

$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")

$fieldId = [Sitecore.FieldIDs]::Lock

$query = @"
SELECT [ItemId], [Value], [Language], [Version]
  FROM [dbo].[VersionedFields]
  WHERE [FieldId] = '$($fieldId.ToString())'
    AND [Value] <> '' AND [Value] <> '<r />'
"@
$records = Invoke-SqlCommand -Connection $connection -Query $query

if($records -and ![string]::IsNullOrEmpty($owner)) {
    $pattern = [regex]::Escape("owner=`"$($owner)`"")
    $records | Where-Object { $_.Value -match $pattern } | ForEach-Object { Get-Item -Path "master:" -ID $_.ItemId -Language $_.Language -Version $_.Version }
} else {
    $records | ForEach-Object { Get-Item -Path "master:" -ID $_.ItemId -Language $_.Language -Version $_.Version }
}
0

Just in case if anyone wants a SQL query

SELECT  DISTINCT ItemId, value
FROM VersionedFields
WHERE FieldId = '001DD393-96C5-490B-924A-B0F25CD9EFD8' -- __LOCK Field Id
AND [Value] NOT LIKE '<r />'
AND [Value] NOT LIKE ''

Your Answer

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

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