├── .editorconfig ├── .upgrade.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config └── extension.yml ├── composer.json ├── docs ├── code-of-conduct.md └── install.md └── src ├── Tasks └── TruncateVersionsTask.php └── VersionTruncator.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # For more information about the properties used in this file, 2 | # please see the EditorConfig documentation: 3 | # http://editorconfig.org 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [{*.yml,package.json}] 14 | indent_size = 2 15 | 16 | # The indent size used in the package.json file cannot be changed: 17 | # https://github.com/npm/npm/pull/3180#issuecomment-16336516 18 | -------------------------------------------------------------------------------- /.upgrade.yml: -------------------------------------------------------------------------------- 1 | mappings: 2 | VersionTruncator: Axllent\VersionTruncator\SiteTreeVersionTruncator 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Notable changes to this project will be documented in this file. 4 | 5 | ## [4.0.0] 6 | 7 | - Support for Silverstripe 6 8 | 9 | 10 | ## [3.1.1] 11 | 12 | - Replace deprecated DataExtension with Extension 13 | 14 | 15 | ## [3.1.0] 16 | 17 | - Add task option to delete all archived DataObjects 18 | 19 | 20 | ## [3.0.1] 21 | 22 | - Support for Silverstripe 5 23 | - Ensure versioned object hasStages() 24 | - Move set_reading_mode() to onAfterPublish() 25 | 26 | 27 | ## [3.0.0] 28 | 29 | - Major rewrite, breaking changes - support for all versioned DataObjects 30 | - Deletion policy per class type (and extending classes) 31 | - Prune only on `onPublish()` to simplify and reduce overheads 32 | - Modify tasks 33 | 34 | 35 | ## [2.0.3] 36 | 37 | - Switch to silverstripe-vendormodule 38 | 39 | 40 | ## [2.0.2] 41 | 42 | - Replace default config with static variables 43 | 44 | 45 | ## [2.0.1] 46 | 47 | - Fix potential dependency loop 48 | 49 | 50 | ## [2.0.0] 51 | 52 | - Add support for SilverStripe 4 (new SilverStripe 3 branch) 53 | - Rewrite of the internals 54 | - Add task to manually run cleanup 55 | - Update docs 56 | 57 | 58 | ## [1.0.0] 59 | 60 | - Adopt semantic versioning releases 61 | - Release versions 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013-Now() Techno Joy www.technojoy.co.nz 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Version truncator for Silverstripe 2 | 3 | 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)). 4 | 5 | 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). 6 | 7 | 8 | ## Features 9 | 10 | * Delete all but the last XX **published** versions of a DataObject on publish 11 | * Delete all but the last YY **draft** versions of a DataObject on publish 12 | * Optionally keep old SiteTree objects where the URLSegment has changed (to preserve redirects) 13 | 14 | 15 | ## Tasks 16 | 17 | The module adds four manual tasks to: 18 | 19 | 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. 20 | 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. 21 | 3. Force a "reset", keeping only the latest published version of each currently published DataObject (regardless of policy). Unpublished / modified DataObjects are not touched. 22 | 4. Delete all archived DataObjects. 23 | 24 | The tasks can be run in your browser via `/dev/tasks/TruncateVersionsTask`, 25 | or see `sake tasks:TruncateVersionsTask --help` for CLI options. 26 | 27 | 28 | ## Requirements 29 | 30 | * Silverstripe ^6.0 31 | 32 | Please see the `3` branch for Silverstripe 4 & 5 support. 33 | 34 | 35 | ## Installation 36 | 37 | `composer require axllent/silverstripe-version-truncator` 38 | 39 | 40 | ## Configuration 41 | 42 | Configuration is optional (see [Default config](#default-config)), however you can create a YML file (eg: `app/_config/version-truncator.yml`): 43 | 44 | ```yaml 45 | MyCustomObject: 46 | keep_versions: 5 47 | keep_drafts: 5 48 | ``` 49 | 50 | To skip pruning altogether for a particular DataObject, set `keep_versions: 0` for that object class. 51 | 52 | To overwrite the global defaults, see [`_config/extension.yml`](_config/extension.yml), eg: 53 | 54 | ```yaml 55 | SilverStripe\CMS\Model\SiteTree: 56 | keep_versions: 20 57 | keep_drafts: 10 58 | ``` 59 | 60 | 61 | ## Default config 62 | 63 | ### SiteTree (and extending classes eg: Page etc) 64 | 65 | 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. 66 | 67 | 68 | ### All other DataObjects 69 | 70 | 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). 71 | -------------------------------------------------------------------------------- /_config/extension.yml: -------------------------------------------------------------------------------- 1 | SilverStripe\ORM\DataObject: 2 | extensions: 3 | - Axllent\VersionTruncator\VersionTruncator 4 | keep_versions: 1 5 | keep_drafts: 0 6 | 7 | SilverStripe\CMS\Model\SiteTree: 8 | keep_versions: 10 9 | keep_drafts: 0 10 | keep_redirects: true 11 | 12 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "axllent/silverstripe-version-truncator", 3 | "description": "Automatically delete old versioned Silverstripe records from the database", 4 | "type": "silverstripe-vendormodule", 5 | "homepage": "https://github.com/axllent/silverstripe-version-truncator", 6 | "keywords": [ 7 | "silverstripe", 8 | "framework", 9 | "sitetree", 10 | "dataobject", 11 | "database", 12 | "performance", 13 | "versioned" 14 | ], 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "Ralph Slooten", 19 | "homepage": "https://www.axllent.org/" 20 | } 21 | ], 22 | "support": { 23 | "issues": "https://github.com/axllent/silverstripe-version-truncator/issues" 24 | }, 25 | "require": { 26 | "silverstripe/framework": "^6.0" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Axllent\\VersionTruncator\\": "src/" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Code of conduct 2 | 3 | Any discussions about this module, issues or pull requests should be done through the Github project page. 4 | -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Please refer to the [README.md](../README.md) for installation & configuration options. 4 | -------------------------------------------------------------------------------- /src/Tasks/TruncateVersionsTask.php: -------------------------------------------------------------------------------- 1 | getOption('prune')) { 42 | $this->prune($output); 43 | } 44 | if ($input->getOption('files')) { 45 | $this->pruneDeletedFileVersions($output); 46 | } 47 | if ($input->getOption('reset')) { 48 | $this->reset($output); 49 | } 50 | if ($input->getOption('archived')) { 51 | $this->deleteArchivedDataObjects($output); 52 | } 53 | 54 | $output->writeForHtml('
You do not normally need to run these tasks, as pruning is run automatically 56 | whenever a versioned DataObject is published.
57 |60 | Prune all 61 | - Prune all published versioned DataObjects according to your policies. 62 | This is normally not required as pruning is done automatically when any 63 | versioned record is published. 64 |
65 |68 | Prune deleted files 69 | - Delete all versions belonging to deleted files. 70 |
71 |
74 |
76 | Reset all
77 |
78 | - This prunes ALL previous versions for published DataObjects, keeping only
79 | the latest single published version.
80 | This deletes all references to old pages, drafts, and previous
81 | pages with different URLSegments (redirects). Unpublished DataObjects,
82 | including those that have drafts are not modified.
83 |
87 | 89 | Delete archived DataObjects 90 | 91 | - Delete all archived DataObjects. 92 |
93 |