loading table of contents...
3.14.2.3.2. Clean Versions

Run Clean Versions using the following command line:

usage: cm cleanversions -u <user> <other options> [--simulate]
          [--export]
          [--directory <directory>]
          [--export-to-subdirs <mode>]
          [--keep-number <n>]
          [--keep-days <d>]
          [--published-only | --unpublished-only]
          [--approved-only | --unapproved-only]
          [ -R ] [ -l <limit> ] [ <id1>... | -I <id1>... |
            -t <path1>... | -cq <query1>... ]

          - OR -

       cm cleanversions -u <user> <other options> [--simulate]
          [--export]
          [--directory <directory>]
          [--export-to-subdirs <mode>]
          --selector-class <classname>
          [--selector-param <name1:value1>]
          [ -R ] [ -l <limit> ] [ <id1>... | -I <id1>... |
            -t <path1>... | -cq <query1>... ]

available options:

 -ao,--approved-only             clean approved versions only
 -c,--cache <arg>                size of cache (in bytes)
                                 (default=64MB)
 -cq,--contentquery <query>      query/queries to select contents
 -d,--domain <domain name>       domain for login
                                 (default=<builtin>)
 -dir,--directory <arg>          directory where document shall be
                                 exported <default=destroy>
 -es,--export-to-subdirs <arg>   structure of export
                                 subdirectories
                                 (default=creationDate). One of
                                 [base|creationDate|
                                  modificationDate|exportDate]
 -I,--id <id>                    id(s) to select content objects
 -kd,--keep-days <arg>           minimum number of days after last
                                 modification <default=7>
 -kn,--keep-number <arg>         minimum Number of versions to
                                 keep (default=1)
 -l,--limit <limit>              limits the number of content objects
                                 to select, negative for unlimited
                                 which is also the default
 -lc,--selector-class <arg>      custom VersionSelector
                                 implementation class
 -lp,--selector-param <arg>      custom VersionSelector parameter
 -p,--password <password>        password for login
 -po,--published-only            clean published versions only
 -R,--recyclebin                 include contents from recycle bin
 -s,--simulate                   simulation mode where no versions
                                 will be destroyed
 -t,--path <path>                path(s) to select content objects
 -u,--user <user name>           user for login (required)
 -uao,--unapproved-only          clean unapproved versions only
 -upo,--unpublished-only         clean unpublished versions only
 -url <ior url>                  url to connect to
 -v,--verbose                    enables verbose output
 -x,--export                     export destroyed versions as xml

Clean Versions is applied to every content selected via the content selection parameters. If folders are selected the clean operation is performed recursively on every content item inside.

No matter which versions you select by command line arguments or by custom VersionSelector (see below), some versions will never be cleaned up, which are:

  • the working version,
  • the latest published version,
  • the latest checked in version and
  • for multi-site set ups: the versions which are referred to as master from the latest versions of the referrers.
  • the latest version sent into a translation workflow
Parameter Description
--keep-number Minimum number of versions to keep (default = 1). This option precedes all other options. Will be ignored for custom version selectors.
--keep-days Do only destroy versions that are at least the given number of days older than the last modification date of the content (default = 7 days). Will be ignored for custom version selectors.

--published-only

--unpublished-only

Clean published or unpublished versions only. These options can not be used together. If none of them is used, both types will be deleted. Keep in mind, that the latest published version will never be deleted by this tool. Will be ignored for custom version selectors.

--approved-only

--unapproved-only

Clean approved or unapproved versions only. These options can not be used together. If none of them is used, both types will be deleted. Will be ignored for custom version selectors.
--simulate Do not destroy any version but perform a simulation.
--cache Capacity of cache in Bytes. Default is 64MB.
--selector-class

The class name of a custom VersionSelector (implementing com.coremedia.cotopaxi.util.VersionSelector). Mind that using a custom VersionSelector will ignore some of the parameters stated above, because the custom selector replaces the default selection criterias. Use --selector-param instead to feed parameters to your custom selector.

--selector-param An optional parameter that will be passed to the custom VersionSelector.
--export Export versions to file system as XML representation before destroying them.
--directory The directory where the content items will be exported before destruction. Default is ./destroy.

--export-to-subdirs [creationDate | modificationDate | exportDate]

Defines which date should be used to create the directory hierarchy. The hierarchy is build in the way Year/Month/Day/Hour. That is, you get up to four directories below the main export directory. "Hour" directories are only created if the option "exportDate" is used. Default is a flat directory structure.
-cq <query> Content Selection Content Query to locate contents. Parameter can be used multiple times. Results will be ORed. Clean Versions will traverse folders recursively.
-R Content Selection Add contents from recyclebin. Could also be done via -cq.
-I <id> Content Selection Select contents via explicit id. This is an alternative if you want to mix explicit ids with for example content queries. Parameter can be used multiple times. Results will be ORed. Clean Versions will traverse folders recursively.
-t <path> Content Selection The path of a content to be cleaned. Parameter can be used multiple times. Results will be ORed. Clean Versions will traverse folders recursively.
<ids> Content Selection Content IDs to be cleaned. If mixing with other content selection parameters it is recommended to explicitly use the parameter -I Parameter can be used multiple times. Results will be ORed. Clean Versions will traverse folders recursively.
-l <limit> Content Selection Limit the number of selected contents. Default is unlimited. Limit does not apply to recursively located contents.

Table 3.23. Switches of the version collector


[Note]Note

For information about the UAPI query syntax see Section 5.5, “Query Service” in CoreMedia Unified API Developer Manual.

Example for calling Clean Version to simulate the cleaning of all content items beneath the root folder but the last two versions:

cm cleanversions -u admin -p admin --simulate
    --keep-number 2 --keep-days 0 --path /

Example for calling Clean Version on all documents despite the /Home folder:

cm cleanversions -u admin -p admin
    -cq "TYPE Document_ : NOT BELOW PATH '/Home'"

Example for calling Clean Version to delete all versions below the folders /Pictures, /Articles and in the recycle bin that are older than 10 days compared to the last modification date but keep at least 3 versions:

cm cleanversions -u admin -p admin --keep-number 3
     --keep-days 10 --recyclebin --path /Pictures /Articles

Example for calling Clean Version to delete all versions below the root folder that are older than 7 days compared to the last modification date (default value) and that are published or approved:

cm cleanversions -u admin -p admin --published-only --approved-only
     --path /

Example for calling Clean Version using a custom VersionSelector on resource with id "135"

cm cleanversions -u admin -p admin 
   --selector-class my.package.TestVersionSelector 
   --selector-param "some parameter" 135 
Performance and Workload Sharing

This tool is implemented as a remote client, and needs to load each visited content item from the content server. This causes network traffic, and puts considerable load on the server, which means that cleaning will not be fast. To avoid obstruction of the regular editorial work, the tool should be run during off-hours (at night, for instance). The workload should be partitioned so that each cleaning run finishes after a sensible time. Try running the clean versions every night and always give it a different folder to work on.

Custom VersionSelectors for cleaning

Using the Unified API it is possible to write your own selector mechanism for selecting content item versions to be cleaned. Given a list of versions of a single content item, the selector returns all versions to be destroyed. The behavior of your class may be adjusted using command line arguments, which are passed to its constructor.

[Note]Note

Keep in mind, that a custom version selector replaces the default selection, it does not extend it.

The named class must be a public class implementing com.coremedia.cotopaxi.util.VersionSelector. It must either define a public no-args constructor, or a public constructor with only one argument of type java.lang.String. In the latter case, a String containing an additional parameter will be passed to the constructor. The simplest example of a customized predicate:

package my.package;

import com.coremedia.cotopaxi.util.VersionSelector;
import com.coremedia.cap.common.CapException;
import com.coremedia.cap.content.Version;
import java.util.ArrayList;
import java.util.List;

public class TestVersionSelector implements VersionSelector {

  public TestVersionSelector(String parameter) {
    System.out.println("Parameter: "+parameter);
  }

  public List selectVersions(List versions) throws CapException {

    List result = new ArrayList();
    for( int x=0; x<versions.size(); x++ ) {

      Version version = (Version) versions.get(x);
      result.add(version);
    }
    return result;
  }
}

Example 3.20. Example of a customized predicate