Automatically delete old SiteTree page versions from Silverstripe

Overview

Version truncator for Silverstripe

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).

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).

Features

  • 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 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.

Requirements

  • Silverstripe 4+

Installation

composer require axllent/silverstripe-version-truncator

Configuration

Configuration is optional (see Default config), however you can create a YML file (eg: app/_config/version-truncator.yml):

MyCustomObject:
  keep_versions: 5
  keep_drafts: 5

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, eg:

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).

Comments
  • Enhancement: Task to run over entire database

    Enhancement: Task to run over entire database

    A task to run over the complete database would be a nice feature to have. We have a lot of databases with a large number (over 1000) pages and cleaning those up with a single click would save a lot of time!

    opened by peavers 16
  • Enhancement: truncate every class implementing Versioned

    Enhancement: truncate every class implementing Versioned

    Hi, and thanks for the module, much cleaner db before deploying website ! Would it be possible to extend this module to safely truncate versions of not only SiteTree but also every class implementing Versioned ?

    enhancement 
    opened by DrMartinGonzo 9
  • Preserve URL History and add Build Tasks

    Preserve URL History and add Build Tasks

    Fixes #3 and adds tasks for truncating on all pages at once and removing deleted pages.

    Certainly some things that could be cleaned up but hopefully a good starting point.

    Note that the way I've excluded 'protected' records currently will mess with the $version_limit as they're removed before the offset is applied, meaning you'll get at least one more record than you want left behind. Might be better to leave the DB query how you had it, then scrub the array of records to delete against a whitelist to remove any protected records.

    opened by jonom 7
  • Enhancement: Preserve URL history for automatic 301 redirects

    Enhancement: Preserve URL history for automatic 301 redirects

    Apologies if this module already does this as I haven't had time to test - but looking at the code I suspect it doesn't.

    If you change the URLSegment of a page for example from 'about-us' to 'about', SilverStripe is normally able to automatically redirect users who try to access site.com/about-us to site.com/about. It does this by searching through previously published versions of pages for the old URLSegment, and if it finds it it redirects you to the URL of the current published version of the page.

    If the old versions aren't there any more, naturally this functionality will be lost.

    I propose a new configuration option preserve_url_history: true which if enabled (probably should be by default) ensures that at least one version record is left in the table for each unique URLSegment a page had.

    opened by jonom 3
  • Code style suggestion: use ClassName::class instead of full namespaced classname string

    Code style suggestion: use ClassName::class instead of full namespaced classname string

    Thanks for this module! I noticed you're using the full namespaced class path to get Config values:

    Config::inst()->get('Axllent\VersionTruncator\VersionTruncator', 'keep_drafts');
    

    Not aware if there's unforeseen downsides to this, but it might be more convenient to use the ::class property instead? (shorter, easier to refactor, plus most of the time you're already in the same namespace in case of related classes)

    Config::inst()->get(VersionTruncator::class, 'keep_versions');
    

    Or, shorter yet;

    VersionTruncator::config()->keep_versions;
    
    opened by micschk 1
  • Changing PublisherID check to WasPublished

    Changing PublisherID check to WasPublished

    In the SilverStripe 3 branch one of the SQL select where clauses is "PublisherID" > 0. I believe this is meant to check "WasPublished" > 0.

    I believe these two queries are first meant to fetch the latest x published versions and then the latest y draft version. If that is correct the queries should be targetting WasPublished > 0 and WasPublished = 1 instead of PublisherID.

    opened by 3Dgoo 1
  • Added standard Scrutinizer config

    Added standard Scrutinizer config

    Hello!

    I'm helpful robot. I noticed you don't have a Scrutinizer config file. This one adds many code quality checks. If you are unsure of how to connect your repository to Scrutinizer, read the guide I wrote for you humans.

    Have a nice day! [brrrrb, click]

    opened by helpfulrobot 1
  • Adopt semantic versioning releases

    Adopt semantic versioning releases

    See semver and SilverStripe supported module definition

    Tagging releases is important to allow people to track your project without having to hook onto dev-master, which can be unstable and have unexpected consequences.

    By adopting semver and an expected version numbering system devs can safely lock onto the correct versions on your software for their projects.

    opened by dhensby 1
  • Converted to PSR-2

    Converted to PSR-2

    Hello!

    I'm helpful robot. I noticed there were some deviations from PSR-2 in your code. The core committer team recently decided to transition SilverStripe Framework and CMS to PSR-2, and the supported module standard recommends following PSR-2. I've gone ahead and converted files in code and tests to PSR-2. If this sounds like something you'd like to merge then go right ahead! Feel free to ask questions or make suggestions for how I can help you more. I've been programmed with a wide range of responses.

    Have a nice day! [gzzzzrrrkt]

    opened by helpfulrobot 0
  • Does not work with SilverShop module

    Does not work with SilverShop module

    This module does not work in combination with the SilverShop module. https://github.com/silvershop

    The class SilverShop\Model\Variation\Variation is a bit weird. It is versioned but is does not have a _Live table.

    See file: https://github.com/silvershop/silvershop-core/blob/master/src/Model/Variation/Variation.php

    This causes issues:

    ERROR: Uncaught Exception SilverStripe\ORM\Connect\DatabaseException: "Couldn't run query:  SELECT "Version" FROM "SilverShop_Variation_Live" WHERE "ID" = ?  Table 'mydatabase.SilverShop_Variation_Live' doesn't exist"
    

    Is there a way to exclude a model from truncation?

    opened by RVXD 4
Releases(3.0.0)
Owner
Ralph Slooten
PHP/Silverstripe/Go developer, Linux sysadmin
Ralph Slooten
Silverstripe-masquerade - SilverStripe module to allow users to "masquerade" as other users

SilverStripe Masquerade Module About This module is designed to allow an Administrator to "login" as another "Member" without changing their password

Daniel Hensby 14 Apr 14, 2022
Silverstripe-debugbar/ - SilverStripe DebugBar module

SilverStripe DebugBar module Requirements SilverStripe ^4.0 maximebf/php-debugbar jdorn/sql-formatter Installation You can install the debug bar with

Thomas Portelange 52 Dec 21, 2022
Silverstripe-fulltextsearch - Adds external full text search engine support to SilverStripe

FullTextSearch module Adds support for fulltext search engines like Sphinx and Solr to SilverStripe CMS. Compatible with PHP 7.2 Important notes when

Silverstripe CMS 42 Dec 30, 2022
Silverstripe-searchable - Adds to the default Silverstripe search by adding a custom results controller and allowing properly adding custom data objects and custom fields for searching

SilverStripe Searchable Module UPDATE - Full Text Search This module now uses Full Text Support for MySQL/MariaDB databases in version 3.* Adds more c

ilateral 13 Apr 14, 2022
Silverstripe-ideannotator - Generate docblocks for DataObjects, Page, PageControllers and (Data)Extensions

silverstripe-ideannotator This module generates @property, @method and @mixin tags for DataObjects, PageControllers and (Data)Extensions, so ide's lik

SilverLeague 44 Dec 21, 2022
Alerts users in the SilverStripe CMS when multiple people are editing the same page.

Multi-User Editing Alert Alerts users in the SilverStripe CMS when multiple people are editing the same page. Maintainer Contact Julian Seidenberg <ju

Silverstripe CMS 15 Dec 17, 2021
Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Strategery 123 Nov 20, 2021
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022
Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀

Polonium Polonium is a world class old school ✍️ blog website made with Php and Tailwind ?? to write dump articles about... Yeah I know, you should pr

Youness Idbakkasse 2 Jan 10, 2022
CaraCracha - a captive portal project made for ISPs on my old city

CaraCracha - a captive portal project made for ISPs on my old city, Sobradinho, state of Bahia, Brazil. I found its code recently and hope it could be useful for someone.

Laudivan Freire de Almeida 2 Mar 9, 2022
Friendly open source CMS forged on Codeigniter 3. FI v1.x uses the old lite theme and all modules.

ForgeIgniter v1.x - CI-3.x Friendly open source CMS forged on Codeigniter 3 This version is now discontinued, please check version 2 or 3 for updates.

ForgeIgniter 1 Jan 28, 2022
A WordPress package to nudge users to upgrade their software versions (starting with PHP)

whip A WordPress package to nudge users to upgrade their software versions (starting with PHP) Requirements The following versions of PHP are supporte

Yoast 71 Oct 18, 2022
Checks prefer-lowest installation for actually defined min versions in composer.json

Composer Prefer Lowest Validator This validator will strictly compare the specified minimum versions of your composer.json with the ones actually used

Mark Scherer 17 Aug 7, 2022
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 312 Dec 26, 2022
Algolia Search integration for Magento 1 - compatible with versions from 1.6.x to 1.9.x

Algolia Search for Magento 1.6+ End of Support ?? The Algolia Magento 1 extension has reached End of Life regarding support and maintenance. We do not

Algolia 163 Dec 20, 2022
Algolia Search integration for Magento 2 - compatible with versions from 2.3.x to 2.4.x

Algolia Search for Magento 2 ?? Need help? Check out our Technical Troubleshooting Guide. For feedback, bug reporting, or unresolved issues with the e

Algolia 147 Dec 20, 2022
A tool that can be used to verify BC breaks between two versions of a PHP library.

Roave Backward Compatibility Check A tool that can be used to verify BC breaks between two versions of a PHP library. Pre-requisites/assumptions Your

Roave, LLC 530 Dec 27, 2022
This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Symfony 2.2k Dec 29, 2022
Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.

PhpDeprecationDetector PhpDeprecationDetector - analyzer of PHP code to search usages of deprecated functionality in newer interpreter versions - depr

Sergey 312 Dec 26, 2022