Specifying when content history is purged

October 8, 2024

By default, content history is kept for a year, and a job is executed every year to purge the content that is older than a year. This document explains how to modify this default configuration to fit your needs.

In Jahia 7

In the file "DIGITAL_FACTORY_HOME/digital-factory-config/jahia/applicationcontext-custom.xml", add between the tag "<beans>" the following code to change the frequency of execution of the script :

<bean parent="jobSchedulingBean">
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.JobDetailBean" depends-on="settingsBean">
                <property name="name" value="ContentHistoryPurgeJob" />
                <property name="jobClass" value="org.jahia.services.scheduler.JSR223ScriptJob" />
                <property name="group" value="Maintenance" />
                <property name="description" value="Content history purge" />
                <property name="jobDataAsMap">
                    <map>
                        <entry key="userkey" value=" system " />
                        <entry key="jobScriptAbsolutePath" value="#{settingsBean.jahiaVarDiskPath}/scripts/groovy/purgeContentHistory.groovy" />
                    </map>
                </property>
            </bean>
        </property>
        <property name="trigger">
            <bean class="org.quartz.CronTrigger">
                <property name="name" value="ContentHistoryPurgeTrigger"/>
                <!-- run every year -->
                <property name="cronExpression" value="0 0 0 L DEC ? *"/>
            </bean>
        </property>
    </bean>

The value you want to change is the cronExpression. For more information on the CRON syntax, please refer to the following URL : http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

Then in the "DIGITAL_FACTORY_HOME/digital-factory-data/scripts/groovy/purgeContentHistory.groovy" file, you can modify the date for purging the history. Here is the default configuration :

    // This removes all history older than a year.
    calendar.add(Calendar.YEAR, -1);

You can find the reference to the available Calendar fields here : http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html

In Jahia 6

The following section in the WEB-INF/etc/spring/applicationcontext-scheduler-jobs.xml contains the configuration for the frequency of execution of the script that will purge the content history :

    <bean id="contentHistoryPurgeTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="contentHistoryPurgeJob"/>
        <!-- run every minute to debug -->
        <property name="cronExpression" value="0 0 0 L DEC ? *"/>
    </bean>

The value you want to change is the cronExpression. For more information on the CRON syntax, please refer to the following URL : http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

Then in the WEB-INF/var/scripts/groovy/purgeContentHistory.groovy file, you can modify the date for purging the history. Here is the default configuration :

    // This removes all history older than a year.
    calendar.add(Calendar.YEAR, -1);

You can find the reference to the available Calendar fields here : http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.htm