December 26, 2013 by Alistair Deneys
Merry Christmas Sitecore devs! And what better way to say Merry Christmas than by releasing a new version of Revolver for the Sitecore community.
That’s right, Revolver 2.2 is now available for download from the Revolver Download Page .
Revolver 2.2 brings a variety of new commands for your scripting pleasure.
The most immediately noticeable improvement when you start up Revolver 2.2 is that we have a new UI. The old UI was very bare bones…kind of on purpose. It was essentially just a text area with a status bar at the bottom of the window.
The new UI is a bit more structured and paves the way for easier formatting of output (such as tables, etc) in the future. We’ve added only a small amount of output styling in this release by making the output colour of the text red when an error occurs. Much easier to see at a glance if your command errored or not.
A number of workflow utilities have been added to help get more information about an item’s workflow status and interact with item workflow.
To get a quick view of an item’s workflow status, execute the new script
The script takes no parameters so just execute it by name:
# Show workflow status for the context item workflow-status
To move an item through workflow we could always just set the appropriate system workflow fields of the item. The problem with this approach however is that although the item may end up in the desired workflow and state, the actions connected to commands and states will not fire. To overcome this we’ve added the new
Without parameters the command will list out the available worklfow commands for the context item given it’s workflow state. If you provide the name of a command (case insensitive), that command will be executed as long as it’s available for the item in the current workflow state. Here’s a few examples of using the command
# List out the available commands for the context item wfc # Execute the 'Approve' command wfc approve
Getting an item through workflow is half the picture to getting something live. The other half is publishing. Revolver 2.2 adds a new
publish command. The command contains options for incremental and full publish as well as options for selecting which languages to publish and which targets to publish to.
In it’s simplest form, the
publish command can be executed with no parameters which will cause the context item to be published in all languages to all targets. As always, refer to the command’s help (
help publish) to get more information on the command and what parameters are available.
# Publish the context item to all targets publish # Perform an incremental publish to the web-live database publish -i -t web-live # Perform a smart publish for Danish and English publish -s -l (da|en)
As publishing can take quite a while to complete the command executes asynchronously. You can check what the publish job is doing by using the
ps command to list all jobs including the publishing jobs.
Maths! Everyone loves maths. Right? Revolver 2.2 adds common maths operations as commands. Many of the Revolver commands already allow you to get a number for commands which list many output lines (such as
search). Now you can perform mathematical operations on that output.
The 5 maths commands are
mod (modulo). All these commands work in the same way, taking any number of numerical input parameters and working on them from left to right. Here’s a few examples.
add 4 6 10 subtract 20 3.5 multiply 2 6 0.1 divide 10 5 mod 9 2
And to operate on the output of something like the number of items found by a search:
add 1 < (search -so name:sitecore)
Remember, the “less than” character (
<) in a Revolver command denotes a subcommand.
In Revolver a function is basically an operator that can be used in conditionals such as the
if command. This allows more flexibility when writing conditionals. The following lists the functions available and what they can be used for.
isbound function can be used to see if a command is bound by a certain name. For example, let’s say I wanted to check if the
ls command existed.
if isbound(ls) (echo (ls has been bound))
The idea behind this function was to allow users to create scripts that could be used across Revolver and Sitecore versions and check for command availability before use. For example,
clone is not available in Sitecore 6.2. So using the
isbound function combined with an
if command you could check if you could create a clone or not.
Checking for an empty parameter in a Revolver script is a little contrived at the moment. This is due to how Revolver substitutes parameters in the script. Revolver will only replace numbered parameter tokens (
$2$, etc) that were provided, leaving those that weren’t.
Let’s say you have the following script called
gf -f $1$
If I invoked this script as follows:
Revolver would replace the
$1$ token because it was provided, to transform the script to:
gf -f title
And if I invoked the script without any parameters, nothing would get transformed and the script would remain as:
gf -f $1$
Currently, to check if a parameter was missing I would need to check that the substituted value was still the token using something like:
if($1$ = \$1\$) (exit (Missing parameter 1))
In the expression used in the
if command I have to escape the
$ characters so the token don’t get replaced.
isempty command simplifies this:
if(isempty($1$)) (exit (Missing parameter 1))
isempty simply results in
true if the input has length of zero (is an empty string).
not function negates the value of the expression passed to it.
if(not(@title = 'sitecore')) (echo (Title is not Sitecore))
This is very handy as you’re not always wanting to know if some condition is true, sometimes you want to find the opposite case.
Sitecore 7 and Content Search
Revolver 2.2 adds support for Sitecore 7 and 7.1. Plus, we’ve added a new command enabling users to use Sitecore 7’s content search within Revolver. The new
csearch command uses the content search API. It is very similar to the
search command, which remains in the Sitecore 7 build of Revolver because the Sitecore search API still exists in Sitecore 7.
You may now realize that this command is the reason for the
isbound function above, to allow users to test if they can use
csearch or not in their scripts. Of course
csearch does not exist in Revolver 2.2 for Sitecore < 7.
csearch command uses the same syntax used by the search UI in Sitecore 7. So to search for something by name:
csearch _name:sitecore pwd
And to combine multiple clauses, separate each by a semi-colon (
csearch (_name:sitecore;_templatename:sample item) pwd
The default combination operator used is “SHOULD” (or) so the above query is searching for items with name “sitecore” or template name “sample item”. To change the operators, prefix the field name with a plus (
+) for “MUST” or a minus (
-) for a “MUST NOT”.
csearch (+_name:sitecore;+_templatename:sample item) pwd
Now you’re search for items with name “sitecore” AND template name “sample item”.
Fixed Some Regression
So it appears Revolver 2.1 may have lost the
clone command for Sitecore 6.4 and above…damn conditional symbols! But they’re back in Revolver 2.2.
Revolver 2.2 has moved a few of it’s installation files round. In particular, it’s moved all text assets (the Sheer UI form XML, JS and CSS files) out of the
sitecore folder and into the
sitecore modules folder to keep everything together and separate from Sitecore. As a result, if you have an older version of Revolver already installed then as part of the installation process you’ll need to remove the old folder so the new Sheer XML file can be found. The details are provided in the “read me” of the installation package, just don’t forget to read the “read me” and delete the old folder.
And as always, you can get help on these new commands simply by executing the
# Get a list of available commands help # Get help for a specific command such as csearch help csearch
Happy scripting everyone!