Content Server Manual / Version 2210
Table Of Contents
Run Clean Versions
using the following command line:
usage: cm cleanversions -u <user> <other options> Based on given version selector class: >>> Selector (default): DefaultVersionSelector <<< [--selector-class com.coremedia.cmdline.management.DefaultVersionSelector] [--keep-number <n>] [--keep-days <d>] [--published-only | --unpublished-only] [--approved-only | --unapproved-only] >>> Custom Selector (deprecated): <<< --selector-class <classname> [--selector-param <name1:value1>] And independent of any version selector: [--simulate] [--export] [--directory <directory>] [--export-to-subdirs <mode>] [ -R ] [ -l <limit> ] [ <id1>... | -I <id1>... | -U <uuid1>... | -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|expor tDate] -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> 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) -U,--uuid <uuid> UUID(s) to select contents -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
General Options
Parameter | Description |
---|---|
--simulate | Do not destroy any version but perform a simulation. |
--cache | Capacity of cache in Bytes. Default is 64MB. |
--selector-class |
Defaults to
The class name of a custom For more details how to implement custom selectors, see section below. |
--selector-param |
(deprecated)
An optional parameter that will be passed to the custom
For more details how to implement custom selectors, see section below. |
--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 . |
| 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 linked by OR.
Clean Versions will traverse folders recursively.
|
-R |
Content Selection
Add contents from recycle bin. 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 linked by OR.
Clean Versions will traverse folders recursively.
|
-U <UUID> |
Content Selection
Select contents via UUID. This is an alternative if you want to mix
UUIDs with for example content queries.
Parameter can be used multiple times. Results will be linked by OR.
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 linked by OR.
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 linked by OR.
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
Options of DefaultVersionSelector
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. |
| 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. |
| 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. |
Table 3.24. Switches of the version collector
Note
For information about the UAPI query syntax see Section 5.7, “Query Service” in 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 content items
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" (deprecated approach):
cm cleanversions -u admin -p admin --selector-class my.package.TestVersionSelector --selector-param "some parameter" 135
Example for calling Clean Version using a custom VersionSelector extending the default version selector:
cm cleanversions -u admin -p admin --selector-class my.package.OverriddenDefaultVersionSelector --keep-number 3 --my-custom-option true
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 named class must be a public class
implementing com.coremedia.cmdline.management.VersionSelector
with a no-args constructor.
Deprecated usages with one argument of type java.lang.String
are still supported. In the latter
case, a String
containing an additional parameter
will be passed to the constructor (see --selector-param
).
For enhanced parameter support it is recommended to implement
com.coremedia.cmdline.management.ExtendedVersionSelector
instead, or even better
to extend com.coremedia.cmdline.management.AbstractVersionSelector
instead.
If you want to extend/customize the default version selector, you may also decide to
override com.coremedia.cmdline.management.DefaultVersionSelector
instead.
Having provided a custom ExtendedVersionSelector
you have to register it
to the service loader providing a file META-INF/services/com.coremedia.cmdline.management.ExtendedVersionSelecto
in your classpath mentioning the fully qualified name of your custom selector.
package my.package; import com.coremedia.cap.content.Version; import com.coremedia.cmdline.management.AbstractVersionSelector; import java.util.Collections; import java.util.List; public class SelectOldestVersionSelector extends AbstractVersionSelector { @Override public List<Version> selectVersions(List<Version> versions) { return versions.stream() .findFirst() .map(Collections::singletonList) .orElseThrow(IllegalStateException::new); } }
Example 3.17. Example of simple custom selector
package my.package; import com.coremedia.cap.common.CapStructHelper; import com.coremedia.cap.content.Version; import com.coremedia.cmdline.management.AbstractVersionSelector; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class SkipArchivedVersionSelector extends AbstractVersionSelector { private static final String LONG_OPT = "skip-archived"; private static final String SHORT_OPT = "sa"; private static final String ARCHIVED_PROPERTY = "archived"; private boolean skipArchived; @Override public void fillInOptions(Options options) { addOption(options, OptionBuilder .withDescription("only versions not marked as archived") .withLongOpt(LONG_OPT) .create(SHORT_OPT)); } @Override public List<String> getUsageLines() { return Collections.singletonList( "[--" + LONG_OPT + "]" ); } @Override public boolean parseCommandLine(CommandLine commandLine) { skipArchived = commandLine.hasOption(SHORT_OPT); return true; } @Override public List<Version> selectVersions(List<Version> versions) { Stream<Version> stream = versions.stream(); if (skipArchived) { stream = stream.filter(v -> CapStructHelper.getInt(v, ARCHIVED_PROPERTY) != 1); } return stream.collect(Collectors.toList()); } }
Example 3.18. Example for custom selector with parameter
Note
Note, that you must not add required parameters for version selectors within
fillInOptions
as the parameters will be marked as
required even if other version selectors are used.