Triggering to affect archiving

The archive trigger type is used in conjunction with the +X filetype modifier to replace the mechanism by which the Helix Core Server archives files within the repository. Archive triggers are used for storing, managing, or generating content archived outside of the Helix Server repository. See Execution environment for platform-specific considerations.

The following table describes the fields of an archive trigger definition:

Field Meaning

name

The name of the trigger.

type

archive: Execute the script when a user accesses any file with a filetype containing the +X filetype modifier. The script can read, write, or delete files in the archive.

The script is run once per file requested.

For read operations, scripts should deliver the file to the user on standard output. For write operations, scripts receive the file on standard input.

path

A file pattern to match the name of the file being accessed in the archive.

command

The trigger for the Helix Core Server to run when a file matching path is found in the archive.

Specify the command in a way that allows the Helix Core Server account to locate and run the command. The command (typically a call to a script) must be quoted, and can take as arguments any argument that your command is capable of parsing, including any applicable Helix Server trigger variables.

When your trigger script is stored in the depot, its path must be specified in depot syntax, delimited by percent characters. For example, if your script is stored in the depot as //depot/scripts/myScript.pl, the corresponding value for the command field might be "/usr/bin/perl %//depot/scripts/myScript.pl%". See Storing triggers in the depot for more information.

If the command succeeds, the command’s standard output is the file content. If the command fails, the command standard output is sent to the client as the text of a trigger failure error message.

Example    

This archive trigger fires when users access files that have the +X (archive) modifier set.

#!/bin/sh
# archive.sh - illustrate archive trigger

OP=$1
FILE=$2
REV=$3

if [ "$OP" = read ]
then
    cat ${FILE}${REV}
fi

if [ "$OP" = delete ]
then
    rm ${FILE}${REV}
fi

if [ "$OP" = write ]
then
    # Create new file from user's submission via stdin
    while read LINE; do
        echo ${LINE} >> ${FILE}${REV}
    done
    ls -t ${FILE}* |
    {
        read first; read second;
        cmp -s $first $second
        if [ $? -eq 0 ]
        then
            # Files identical, remove file, replace with symlink.
            rm ${FILE}${REV}
            ln -s $second $first
        fi
    }
fi

To use the trigger, add the following line to the trigger table:

arch  archive  path  "archive.sh %op% %file% %rev%"

When the user attempts to submit (write) a file of type +X in the specified path, if there are no changes between the current revision and the previous revision, the current revision is replaced with a symlink pointing to the previous revision.