Created
March 2, 2012 04:31
-
-
Save codejoust/1955682 to your computer and use it in GitHub Desktop.
Silverstripe Database Cleanup Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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