Table garbage collection task 

Deprecated since version 14.0

The table garbage collection task can take a more elaborate configuration which is detailed below.

Using the garbage collection task 

The task can be registered to clean up a particular table, in which case you simply choose the table and the minimum age of the records to delete from the task configuration screen.

Table Garbage Collection task configuration

Configuring the table garbage collection task

In case no minimum age is choosen, the configured expirePeriod is used.

Table Garbage Collection task configuration default expire period

Configuring the table garbage collection task with default expire period

It is also possible to clean up all configured table by checking the "Clean all available tables" box.

The configuration for the tables to clean up is stored in the TCA of table tx_scheduler_task, in field tables.

This configuration is an array with the table names as fields and the following entries:

  • option expireField can be used to point to a table field containing an expiry timestamp. This timestamp will then be used to decide whether a record has expired or not. If its timestamp is in the past, the record will be deleted.
  • if a table has no expiry field, one can use a combination of a date field and an expiry period to decide which records should be deleted. The corresponding options are dateField and expirePeriod. The expiry period is expressed in days.

Example: Configure additional tables for the "Garbage Collection" task 

packages/my_extension/Configuration/TCA/Overrides/tx_scheduler_garbage_collection.php
<?php

use TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask;

if (isset($GLOBALS['TCA']['tx_scheduler_task'])) {
    $garbageCollectionTables =& $GLOBALS['TCA']['tx_scheduler_task']['types'][TableGarbageCollectionTask::class]['taskOptions']['tables'];

    $garbageCollectionTables = array_replace($garbageCollectionTables ?? [], [
        'tx_myextension_my_table' => [
            'dateField' => 'tstamp',
            'expirePeriod' => 180,
        ],
        'tx_myextension_my_other_table' => [
            'expireField' => 'expire',
        ],
    ]);
}
Copied!

The first part of the configuration indicates that records older than 180 days should be removed from table tx_myextension_my_table , based on the timestamp field called "tstamp". The second part indicates that old records should be removed from table tx_myextension_my_other_table directly based on the field expire which contains expiration dates for each record.

Migration: Supporting custom tables for garbage collection for both TYPO3 13 and 14 

If your extension supports both TYPO3 13 (or below) and 14 keep the registration of additional tables in the extensions ext_localconf.php until support for TYPO3 13 is removed:

packages/my_extension/ext_localconf.php
<?php

use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask;

if ((new Typo3Version())->getMajorVersion() < 14) {
    // TODO: Remove once TYPO3 13 support is dropped
    // TYPO3 14 configuration can be found in Configuration/TCA/Overrides/tx_scheduler_garbage_collection.php
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][TableGarbageCollectionTask::class]['options']['tables']['tx_myextension_errorlog'] = [
        'dateField' => 'tstamp',
        'expirePeriod' => '180',
    ];
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][TableGarbageCollectionTask::class]['options']['tables']['tx_myextension_uniqalias'] = [
        'expireField' => 'expire',
    ];
}
Copied!