Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created March 2, 2012 04:31
Show Gist options
  • Save codejoust/1955682 to your computer and use it in GitHub Desktop.
Save codejoust/1955682 to your computer and use it in GitHub Desktop.
Silverstripe Database Cleanup Script
<?php
class Director { public function set_dev_servers($arg){} };
class SSViewer { public function set_theme($arg){} };
include_once('../public_html/mpt/_config.php');
$sql = "DELETE FROM SiteTree_versions
WHERE CONCAT_WS('_', RecordID, Version) NOT IN
(SELECT CONCAT_WS('_', id, Version) AS combined_id FROM SiteTree)
AND LastEdited > DATE_SUB(curdate(), INTERVAL 3 WEEK);";
echo('Starting weekly history cleanup');
$mydb = new mysqli($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database']);
if ($mydb->connect_errno){
die('failed to connect to mysql server.');
}
if (!$mydb->query($sql)){
die('failed to delete additional records ('.$mydb->errno.') ' . $mydb->error);
}
echo('cleanup success :).');
echo('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment