CQ Workflow Tutorial: Export Workflow Models Quickly
Update (5/17/2013):
There is a bug in the script when there are more than 10 files. This part will fix it:
# Do not change any of these INDEX=1 FILES=$TARGET_DIR/$PACKAGE_NAME-*.zip for f in $FILES do echo File Name: $f FILE=$f NTEMP=`echo ${FILE##*-}|cut -d . -f1` echo NTEMP: $NTEMP if [ "$NTEMP" -gt "$INDEX" ]; then INDEX=$NTEMP fi done;
So far I did not discuss how to manage the project even though if you look at the final project files I posted at the end of the Post you will see that it contains the Workflow Models as well.
In General I always keep the Workflow Models in my VCS (often my personal GIT as well as the Client’s VCS) just to make sure I have a track record of all the changes and can see how it evolves over time but also to have a way to easily undo a problematic current version. Because Workflow Models can only be edited inside the CQ Workflow Model Editor we need to find a way to export them quickly, easily and fast otherwise we might loose changes. That said I never to export the workflows directly into the VCS but rather export them into a temporary folder and then use a DIFF tool like Delta Walker for the Mac to move them over even if I just copy them without ever merging.
Setup
We need to do some setup work in order to make sure we can export the Package with a Script. The only thing we need to do is to create a Package inside the Package Manager (/crx/packmgr) with this pattern:
- Name: {Group Name}-workflow-export
- Version: 1.0
-
Group: {Group Name}
Then we need to edit the Package to add a Package Filter. You can add as many as you like but for me the only thing I need for now is the path to the Workflow Model which is either /etc/workflow/models or a Child Resource of it. Build the Package just to make sure it contain everything you want.
Script
The script uses the RESTful API to the Package Manager which is not very difficult to understand. The bigger problem is to create a Unix script that is making sure I can keep a history of my downloaded packages. So this script will do that:
#!/bin/bash # This script will create a new build of the given package # and download it to the given Directory with the next # next number not taken. Then it will extract it into that # folder with the same name. # ATTENTION: This script has a few conditions: # 1. Package with the Given Name must already exist in the # Package Manager ($PACKAGE_NAME-1.0.zip) # 2. Package in part of the given Group # 3. The Given Target Directory only contains files with # the given Pattern ($PACKAGE_NAME-<integer>.zip) # 4. CQ Host, Port, Admin Username and Password are correct # First variable here is the Group Name which is used to prefix # the Package, the Target Directory etc. To make it easier # to use this is the first parameter. Create another script # per project. GROUP_NAME=$1 # Second Variable is the Port Number PORT=$2 # Name of the Package without the Version PACKAGE_NAME=$GROUP_NAME-workflow-export # Directory where the generated ZIP file will be placed in # If it does not exist it will be created TARGET_DIR=~/Downloads/$GROUP_NAME echo Create Dir: $TARGET_DIR mkdir -p $TARGET_DIR # Name of the CQ Server HOST=localhost # Port of the CQ Server #PORT=8080 # CQ Administrator User Name USER=admin # CQ Administrator Password PWD=admin # Do not change any of these INDEX=1 FILES=$TARGET_DIR/$PACKAGE_NAME-*.zip for f in $FILES do echo File Name: $f FILE=$f NTEMP=`echo ${FILE##*-}|cut -d . -f1` echo NTEMP: $NTEMP INDEX=$NTEMP done; # If it does not list any files then it will # set index to '*' so we set it to the default # of 0 if [ "$INDEX" = '*' ]; then INDEX=0 fi # Take next index number let INDEX=$INDEX+1 echo Final Index: $INDEX FOLDER=$TARGET_DIR/$PACKAGE_NAME-$INDEX FILE=$FOLDER.zip echo $FILE HOST_PART=http://$USER:$PWD@$HOST:$PORT PACK_SVC=/crx/packmgr/service/.json PACK_PATH=/etc/packages/$GROUP_NAME/$PACKAGE_NAME-1.0.zip ACTION=build # Build the Package through the Package Manager echo Build the Package: $PACK_PATH echo URL: $HOST_PART$PACK_SVC$PACK_PATH?cmd=$ACTION curl -X POST $HOST_PART$PACK_SVC$PACK_PATH?cmd=$ACTION # Download the Package into our file echo Download Package: $PACK_PATH to file $FILE curl -u $USER:$PWD http://$HOST:$PORT$PACK_PATH > "$FILE" # Unzip the Downloaded File into a folder of the same name mkdir -p $FOLDER echo Unzip File: $FILE into Folder: $FOLDER unzip $FILE -d $FOLDER
You can use that script like this:
workflow.eport.sh tutorial 4502
This will create a folder called tutorial in your Home Folder’s Download Folder, build and download the tutorial-workflow-export-1.0.zip package and extract it in a sub folder of the same folder. Each downloaded ZIP file and extracted folder has this pattern tutorial-workflow-export-{index}.
For my various projects I created another Unix Shell Script with the Name of the Project which will have the Parameters already set.
Conclusion
Yes, you could do that with FileVault but my experience is that it is not very reliable and so I stopped using at all. Also if you are editing your workflows in a package that includes other parts like UI components etc then you must be very carful to download any changes from the Workflow before you start a build otherwise you might overwrite your changes with the old Workflow Models you have in your project. That is why this script is so handy because it takes literally no time to execute.
Finally, you could use a cron job to backup the Workflows automatically in the background using that script.
— Andy
Leave a comment
You must be logged in to post a comment.