Skip to content

Commit

Permalink
Major rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Mar 14, 2021
1 parent 7b4941f commit d342e68
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 338 deletions.
68 changes: 44 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,66 @@
# Version truncator for SilverStripe
# Version truncator for Silverstripe

An extension for SilverStripe to automatically delete old SiteTree page versions,
keeping the last XX versions per page.
An extension for Silverstripe to automatically delete old versioned DataObject records from your database when a record is published, following predefined retention policies (see [configuration](#configuration)).

When a record is being edited (such as a Page), no changes are made until it is published, so it could have 50 draft versions while you work on the copy. When you publish the page, the module prunes the (by default) all draft copies, leaving just the 10 latest published versions (configurable).

It works for any page extending the SiteTree model, and includes all child models
(eg: Page extends SiteTree, so both Page_versions & SiteTree_versions are truncated).

## Features

* Delete all but the last XX **published** versions of a page (default 10)
* Delete all but the last XX **draft** versions of a page (default 5)
* Optionally keep old versions where the URLSegment has changed to preserve redirects (default true)
* Delete all **redundant** versions of a page when switching Page Type (default true)
* Delete all but the last XX **published** versions of a DataObject on publish
* Delete all but the last YY **draft** versions of a DataObject on publish
* Optionally keep old SiteTree objects where the URLSegment has changed (to preserve redirects)


## Tasks

The module adds two manual tasks to:
The module adds three manual tasks to:

1. Force a run over the entire database - this task is generally not needed unless you either just install the module and wish to tidy up, or change your DataObject configurations.
2. Silverstripe does not currently delete any File records once the file had been physically deleted (probably due to the immediate post-delete functionality relating to internal file linking). I cannot see any purpose of keeping these records after this, so this task will remove all records pertaining to deleted files/folders.
3. Force a "reset", keeping only the latest published version of each currently published DataObject (regardless of policy). Unpublished / modified DataObjects are not touched.

The tasks can be run via `/dev/tasks/TruncateVersionsTask`.

1. Force a run over the entire database
2. Force a "reset", keeping only the latest published version of each currently published page.

## Requirements

* SilverStripe 4+
* Silverstripe 4+

## Installation

Installation can be done either by composer or by manually downloading a release.
## Installation

### Via composer
`composer require axllent/silverstripe-version-truncator`

`composer require "axllent/silverstripe-version-truncator"`

## Configuration

Configuration is optional, however you can create a YML file (eg: `mysite/_config/version-truncator.yml`)
and add/edit the following values:
Configuration is optional (see [Default config](#default-config)), however you can create a YML file (eg: `app/_config/version-truncator.yml`):

```yaml
MyCustomObject:
keep_versions: 5
keep_drafts: 5
```
Axllent\VersionTruncator\VersionTruncator:
keep_versions: 10 # how many (published) versions of each page to keep
keep_drafts: 5 # how many drafts of each page to keep
keep_redirects: true # keep page versions that have a different URLSegment (for redirects)
keep_old_page_types: false # keep page versions where page type (ClassName) has changed
To skip pruning altogether for a particular DataObject, set `keep_versions: 0` for that object class.

To overwrite the global defaults, see [`_config/extension.yml`](_config/extension.yml), eg:

```yaml
SilverStripe\CMS\Model\SiteTree:
keep_versions: 20
keep_drafts: 10
```


## Default config

### SiteTree (and extending classes eg: Page etc)

On publish, the last 10 published versions are kept, and all draft copied are removed. The only exception is if the `URLSegment` and/or `ParentID` is has changed, in which case the module will keep a single record for each differing URLSegment to allow auto-redirection.


### All other DataObjects

For all other versioned DataObjects, only the latest published version is kept, and all drafts deleted. This can be adjusted per DataObject, or globally (see above).
15 changes: 10 additions & 5 deletions _config/extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
Name: versiontruncator
---
SilverStripe\CMS\Model\SiteTree:
SilverStripe\ORM\DataObject:
extensions:
- Axllent\VersionTruncator\SiteTreeVersionTruncator
- Axllent\VersionTruncator\VersionTruncator
keep_versions: 1
keep_drafts: 0

SilverStripe\CMS\Model\SiteTree:
keep_versions: 10
keep_drafts: 0
keep_redirects: true

48 changes: 26 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{
"name": "axllent/silverstripe-version-truncator",
"description": "Automatically delete old SiteTree page versions from SilverStripe",
"type": "silverstripe-vendormodule",
"homepage": "https://github.com/axllent/silverstripe-version-truncator",
"keywords": [
"silverstripe",
"cms",
"sitetree"
],
"license": "MIT",
"authors": [
{
"name": "Ralph Slooten",
"homepage": "http://www.axllent.org/"
}
],
"support": {
"issues": "https://github.com/axllent/silverstripe-version-truncator/issues"
},
"require": {
"silverstripe/framework": "^4.0"
},
"name": "axllent/silverstripe-version-truncator",
"description": "Automatically delete old versioned Silverstripe records from the database",
"type": "silverstripe-vendormodule",
"homepage": "https://github.com/axllent/silverstripe-version-truncator",
"keywords": [
"silverstripe",
"framework",
"sitetree",
"dataobject",
"database",
"performance",
"versioned"
],
"license": "MIT",
"authors": [
{
"name": "Ralph Slooten",
"homepage": "https://www.axllent.org/"
}
],
"support": {
"issues": "https://github.com/axllent/silverstripe-version-truncator/issues"
},
"require": {
"silverstripe/framework": "^4.5"
},
"autoload": {
"psr-4": {
"Axllent\\VersionTruncator\\": "src/"
Expand Down
192 changes: 0 additions & 192 deletions src/Classes/VersionTruncator.php

This file was deleted.

35 changes: 0 additions & 35 deletions src/SiteTreeVersionTruncator.php

This file was deleted.

Loading

0 comments on commit d342e68

Please sign in to comment.