Source of file CleanupDataChangeHistoryTask.php
Size: 1,749 Bytes - Last Modified: 2021-12-23T10:25:23+00:00
/var/www/docs.ssmods.com/process/src/src/Job/CleanupDataChangeHistoryTask.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php namespace Symbiote\DataChange\Job; use Symbiote\DataChange\DataChangeRecord; use SilverStripe\Dev\BuildTask; use SilverStripe\ORM\Queries\SQLDelete; /** * * * @author <marcus@symbiote.com.au> * @license BSD License http://www.silverstripe.org/bsd-license */ class CleanupDataChangeHistoryTask extends BuildTask { public function run($request) { $confirm = $request->getVar('run') ? true : false; $force = $request->getVar('force') ? true : false; $since = $request->getVar('older'); if (!$since) { echo "Please specify an 'older' param with a date older than which to prune (in strtotime friendly format)<br/>\n"; return; } $since = strtotime($since); if (!$since) { echo "Please specify an 'older' param with a date older than which to prune (in strtotime friendly format)<br/>\n"; return; } if ($since > strtotime('-3 months') && !$force) { echo "To cleanup data more recent than 3 months, please supply the 'force' parameter as well as the run parameter, swapping to dry run <br/>\n"; $confirm = false; } $since = date('Y-m-d H:i:s', $since); $items = DataChangeRecord::get()->filter('Created:LessThan', $since); $max = $items->max('ID'); echo "Pruning records older than $since (ID $max)<br/>\n"; if ($confirm && $max) { $query = new SQLDelete('DataChangeRecord', '"ID" < \'' . $max . '\''); $query->execute(); } else { echo "Dry run performed, please supply the run=1 parameter to actually execute the deletion!<br/>\n"; } } } |