October 6, 2012 by Alistair Deneys
It’s been a while since the last update to Revolver so this release is long overdue. Today I have released version 2 of Revolver, the scripting module for Sitecore. The timing of this release is in preparation for Sitecore Symposium Australia where I’ll be presenting on scripting with Sitecore. Of course I’ll be covering Revolver and I will also be covering other scripting modules available.
Anyway, back to the release.
There have been lots of changes to the module in this update, so let’s cover them off, starting with the biggest change:
Revolver is Now Free!
Yes, I have removed the commercial licensing from the module. I am a huge supporter of open source software and I also use many open source tools. So it was kind of odd that I was going against open source and was holding the module as commercial. I’ve still got a bit of clean up I want to do in the codebase before releasing it into the wild, so I’m stopping short of going open source just yet, but I’m allowing it’s use free of charge.
This change in licensing was also encouraged by the other freely available scripting modules out there, the Sitecore Rocks Power Shell integration, Sitecore Rocks Query Analyser and the Power Shell Console. It was getting very hard to justify the cost of Revolver given the capabilities of the other modules.
search command allows searching within the Lucene indexes. It works in the same fashion as the
query commands. The command is used to locate items and then execute some command against each item.
So if we wanted to search for any items that contain “Lorem” in the title field (left over test data anyone?) and just print the path to the item, we could use the following command.
search title:lorem pwd
Note that the fields used in the search are Lucene fields, not Sitecore item fields.
The Revolver application window now has a status bar to tell you when the client app is communicating with the server. This helps inform you about whether Revolver is waiting for your input or if it’s off and processing your data for you.
Find using Wildcard Field
find command has been updated to allow use of a wildcard field name when matching items on field values. This allows users to search inside all fields which can come in handy when trying to locate items that might contain a token in a number of different fields.
find -f * lorem pwd
Excluding Standard Values
Sometimes when you’re searching for content you want to be able to exclude anything coming from standard values. For example, if you want to search for items that have overridden presentation. When using the
find command you can pass the new flag
-nsv (no standard values) to exclude standard values in the operation, and only assess items on field values they contain.
So to find item’s that have overridden their presentation we could use this command:
find -r -f __renderings .+ -nsv pwd
Better Version Support
This version of Revolver has better support for item versions, allowing you to list the various versioned and also change your context to a specific numbered version.
To list the versions of an item:
To see which version you’re looking at:
To change to a specific numbered version of an item:
cd command also got an update to make it easier to change your context between languages and versions.
Arguments can now include the language and version you want to change your context to. The language is separated from the item path with a single-semi colon, and the version is separated from the language with a single semi-colon. If the language, path or version is omitted then it won’t be changed. Here’s a few examples.
cd /sitecore/content/home:en:3 cd :de cd ::6 cd :jp:7
Launch Content Editor
In the previous version of Revolver the
ce script which could be used to open a content editor with the current context was broken. This has now been fixed and the script renamed to
content-editor. So to open a content editor application on the current context item, just type the following:
Scripting also got better in this release of Revolver.
if command allows simple conditions to be evaluated using the expression syntax used by the
find command. This can be used to ensure all the required parameters have been provided to a script.
exit command allows a script to bail out if required, such as when a parameter is missing.
The following example shows a check for the first parameter and exits if the parameter is not provided.
if ($1$ = \$1\$) (exit (Missing required parameter))
if command accepts 2 parameters. The first is the expression to evaluate. In the above example if the parameter is provided then the
$1$ token will be replaced with the parameter. Note how the dollar signs on the right hand side of the expression are escaped? This prevents the argument from being replaced with the provided parameter, so this expression is checking if the provided parameter was substituted or not.
The second parameter to the
if command if the command to execute if the expression evaluates to true.
exit command accepts an optional message which will be output to the user.
Revolver also ships with some handy scripts out-of-the-box:
|ls-scripts||Lists the scripts available|
|content-editor||Opens a content editor application with the current item selected|
|field-info||Get extended information about a specific field of an item|
|replace-in-field||Replace a token in a field of an item|
|set-prompt||Sets the default prompt|
|updates||Locates all descendant items that have been updated or created since the given date|
Don’t forget that help is built right into Revolver, so you can get more help on any of the commands by using the
help command and passing it the name of the command you want help on:
help search help lsv
Help is also available for scripts. Access it the same way: