codeflood logo

Common uses for Revolver

When developing Sitecore solutions I use Revolver a lot. I find it easier and quicker at times to do things in the command prompt than clicking through the beautiful UI. So here's a bit of a list of common scenarios I use Revolver for.

Most of the scripts below utilise the find command. By far I think the ability to execute the same command against a set of items is the biggest benefit.

You can set 'filters' on the find command through the parameters you pass to the command. This will include the items which pass the filter into the execution set, and have the command (last parameter passed) executed against them. You can also optionally pass the recursive (-r) parameter to cause the command to recurse down the tree using the current item as the root. If you leave the recursive parameter out then only the children of the current item are looked at.

  1. Unlock all content items. Sitecore 6.0 introduced UI utilities to unlock all of your own content items, but what about unlocking all content for all users? This is good to run before your create a deployment package for a client, as it releases all the locks the developers are holding. Saves you from those calls from the client who can't update some piece of content cause one of the developers has it locked. (The client was not an admin). Locks on items are controlled through the __lock field. So it's just a matter of changing that field to an empty lock. Because we want this command to be executed against every item, we don't pass any filters in this time. Start at the root (/sitecore).
find -r (sf __lock ())
  1. Find items with spaces in their names. Sitecore by default allows you to create items with spaces in the names. The problem is you end up with a validation warning cause the space will get encoded to '%20' when used in URLs (bad for SEO). This script allows you to find all items that have a space in their name so you can change it. The items it finds will have their paths printed into the command prompt window. The field value we're matching on here is a regular expression.
find -r -a key \s pwd
  1. Find updated items. This script is good when generating deployment packages. To find all content which has been updated since a certain date, we'll use the find command (of course) with an expression filter so we can specify a date the __updated field must be later than. Expressions are specific to Revolver. They are a way of writing a test based on attribute and field values. I based expressions on Sitecore query, so a single at (@) denotes a field and double at (@@) denotes an attribute.
find -r -e (@__updated >= 20081201) pwd
  1. Find created items. This script is the same as the script above, except now we use the __created field for comparison.
find -r -e (@__created >= 20081202) pwd

For more detail on the find command you can see the help topic on the find command from within the command prompt.

help find

Help has been baked into Revolver from the start. Each help topic describes the usage of the command, gives explanation to the parameters you can pass to it, and gives some examples of how to use the command.

You could also achieve the above using the query command. Query does the same as find except you can use a Sitecore query instead of the filter parameters. One other major difference between these 2 commands is how the get executed. Query is executed as a Sitecore query and so is limited to the 'Query.MaxItems' setting in web.config. By default this value is set to 100. So if you're running queries and keep getting 100 results back, try increasing this value. Find on the other hand uses the API to recurse down to each item it needs to address based on whether the find command executed is recursive and the filters applied. So I would expect find to run slower than query, but it will always hit each item I expect.

Comments

Brad

Do you know of a way to do step 1 using the GUI?

Alistair Deneys

Hi Brad, Do you mean using the Sitecore GUI? As far as I know you can't. The Sitecore UI allows unlocking all your own items, but I haven't found anything in the UI allowing you to unlock all items, regardless of owner. That's why I showed how to do that using Revolver.

Leave a comment

All fields are required.