Source of file UpdateNoteExtension.php
Size: 2,664 Bytes - Last Modified: 2021-12-23T10:47:23+00:00
/var/www/docs.ssmods.com/process/src/code/model/UpdateNoteExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | <?php class UpdateNoteExtension extends DataExtension { private static $has_many = array( 'UpdateNotes' => 'UpdateNote' ); private static $seconds_grace = 600; private static $latest_limit = 600; private static $_run_once_only = array(); /** * Event handler called after writing to the database. */ public function onAfterWrite() { parent::onAfterWrite(); $id = $this->owner->ID; $class = $this->owner->ClassName; $userID = Member::currentUserID(); $filter = array( 'UpdateNoteRecordID' => $id, 'UpdateNoteRecordClass' => $class, 'UpdatedByID' => $userID ); $key = implode('_', $filter); if (! isset(self::$_run_once_only[$key])) { self::$_run_once_only[$key] = true; $now = SS_Datetime::now()->Rfc2822(); $gracePointInTime = strtotime($now) - Config::inst()->get('UpdateNoteExtension', 'seconds_grace'); $log = DataObject::get_one( 'UpdateNote', $filter, $cacheDataObjectGetOne = false, array('Created' => 'DESC') ); if ($log) { $editPointInTime = strtotime($log->Created); debug::log(Date('l jS \of F Y h:i:s A', $editPointInTime).'...'.Date('l jS \of F Y h:i:s A', $gracePointInTime)); if ($editPointInTime < $gracePointInTime) { $log = null; } } if ($log && $log->exists()) { //already exists ... } else { $log = UpdateNote::create($filter); } $log->write(); } } /** * Update Fields * @return FieldList */ public function updateCMSFields(FieldList $fields) { $owner = $this->owner; $name = Injector::inst()->get('UpdateNote')->i18n_plural_name(); $fields->addFieldToTab( 'Root.'.$name, GridField::create( 'UpdateNotes', $name, $this->owner->UpdateNotes(), GridFieldConfig_RecordEditor::create() ) ); return $fields; } /** * Event handler called before deleting from the database. */ public function onBeforeDelete() { foreach ($this->owner->UpdateNotes() as $note) { $note->delete(); } } public function LatestUpdateNotes() { return $this->owner->UpdateNotes() ->limit(Config::inst()->get('xx', 'latest_limit')); } } |