Given that this program is actually the first one in this chapter that may have some real-world application, you might find it surprising that it's so simple. Here, the approach has been to define the working environment (the repository) first and then proceed to define the actions to take. Let's look at things in detail.
The definition of the rules list is deliberately simplified so that the structure of the program will be easy to see. For instance, there is no way to define the action to be taken or the archival level to be used for any rule that fires; the only action, by default, is deletion. All you've really done is to define a list of "WHERE" clauses, give them convenient names, and make it possible to define a sort order. The order attribute on the rules list ensures that the wftk will retrieve them in the right order when you want to use them.
In step 2, you define the rules table in MySQL and then insert two rules. Files edited by the user "you" are deleted in three days, but files defined by the user "me" aren't deleted until they're four days old — this is an example of how roles can be used to define a retention policy.
Just to demonstrate a point, the sort order of the two rules is in the opposite of the order they're defined (and, thus, the opposite of the numeric order of their keys.) The point is that the wftk will retrieve them anyway, and in the sort order that you specified, without needing any additional prompting for input from you.
To start the program, then, connect to the repository and define a list of rules to be retrieved; then use the query method to retrieve them. Using the keys method to iterate along the rules, define an fwtk XML object for each retrieved record to make them available to work with. An XML object is the standard record storage structure of the wftk, so after you've defined the object, you can address named fields directly, making it easy to work with list query results. Now, proceed to iterate through the keys and process each rule against each list in turn. After telling the user which rule is active, a second query is built to retrieve all of the documents matching the rule and delete those documents. It's as simple as that.
Was this article helpful?