public function track(DataObject $object, $type = 'Change') { if (!isset($this->dcr_cache["{$object->ID}-{$object->Classname}"])) { $this->dcr_cache["{$object->ID}-{$object->Classname}"] = DataChangeRecord::create(); } $this->dcr_cache["{$object->ID}-{$object->Classname}"]->track($object, $type); }
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 SQLQuery('*', 'DataChangeRecord', '"ID" < \'' . $max . '\''); $query->setDelete(true); $query->execute(); } else { echo "Dry run performed, please supply the run=1 parameter to actually execute the deletion!<br/>\n"; } }
public function process() { $items = DataChangeRecord::get()->filter('Created:LessThan', $this->pruneBefore); $max = $items->max('ID'); $query = new SQLDelete('DataChangeRecord', '"ID" < \'' . $max . '\''); $query->execute(); $job = new PruneChangesBeforeJob($this->priorTo); $next = date('Y-m-d 03:00:00', strtotime('tomorrow')); $this->currentStep = $this->totalSteps; $this->isComplete = true; singleton(QueuedJobService)->queueJob($job, $next); }
public function updateCMSFields(FieldList $fields) { //Get all data changes relating to this page filter them by publish/unpublish $dataChanges = DataChangeRecord::get()->filter('ClassID', $this->owner->ID)->exclude('ChangeType', 'Change'); //create a gridfield out of them $gridFieldConfig = GridFieldConfig_RecordViewer::create(); $publishedGrid = new GridField('PublishStates', 'Published States', $dataChanges, $gridFieldConfig); $dataColumns = $publishedGrid->getConfig()->getComponentByType('GridFieldDataColumns'); $dataColumns->setDisplayFields(array('ChangeType' => 'Change Type', 'ObjectTitle' => 'Page Title', 'ChangedBy.Title' => 'User', 'Created' => 'Modification Date')); //linking through to the datachanges modeladmin $fields->addFieldsToTab('Root.PublishedState', $publishedGrid); return $fields; }
public function run($request) { if ($request->getVar('run')) { // load all items and convert 'before' and 'after' to json if their serialize returns a value $records = DataChangeRecord::get(); foreach ($records as $record) { $before = @unserialize($record->Before); $after = @unserialize($record->After); if ($before || $after) { $record->Before = json_encode($before); $record->After = json_encode($after); $record->write(); echo "Updated {$record->Title} (#{$record->ID})<br/>\n"; } } } }