PruneContentRevisionsJob
extends MaintenanceJob
in package
Prunes the content_revisions table.
Content revisions are immutable snapshots created on every page/post save and are never deleted by the application, so they grow without bound. This job enforces a retention policy:
- keep_per_content: keep at most this many newest revisions per content item (default 50; 0 disables count-based pruning)
- max_age_days: delete revisions older than this many days (default 365; 0 disables age-based pruning)
Table of Contents
Methods
- getName() : string
- run() : bool
- Apply the retention policy to content_revisions.
- getBasePath() : string|null
- Resolve the application base path from the Registry.
- getConnection() : PDO|null
- Build a PDO connection from the application database settings.
- getSettings() : SettingManager|null
- Resolve the application SettingManager from the Registry.
- intArg() : int
- Read an integer argument with a default fallback.
- deleteOlderThan() : int
- Delete revisions older than the given age.
- trimPerContent() : int
- Keep only the newest $keep revisions per content item, deleting the rest.
Methods
getName()
public
getName() : string
Tags
Return values
stringrun()
Apply the retention policy to content_revisions.
public
run([array<string|int, mixed> $argv = [] ]) : bool
Parameters
- $argv : array<string|int, mixed> = []
Return values
bool —True on success.
getBasePath()
Resolve the application base path from the Registry.
protected
getBasePath() : string|null
Return values
string|nullgetConnection()
Build a PDO connection from the application database settings.
protected
getConnection() : PDO|null
Return values
PDO|null —Null when the connection cannot be established.
getSettings()
Resolve the application SettingManager from the Registry.
protected
getSettings() : SettingManager|null
Return values
SettingManager|null —Null when settings are unavailable.
intArg()
Read an integer argument with a default fallback.
protected
intArg(array<string|int, mixed> $argv, string $key, int $default) : int
Parameters
- $argv : array<string|int, mixed>
- $key : string
- $default : int
Return values
intdeleteOlderThan()
Delete revisions older than the given age.
private
deleteOlderThan(PDO $pdo, int $maxAgeDays) : int
Parameters
- $pdo : PDO
- $maxAgeDays : int
Return values
int —Rows deleted.
trimPerContent()
Keep only the newest $keep revisions per content item, deleting the rest.
private
trimPerContent(PDO $pdo, int $keep) : int
Uses portable SQL (no window functions) so it works on SQLite, MySQL and PostgreSQL.
Parameters
- $pdo : PDO
- $keep : int
Return values
int —Rows deleted.