From 804757d391e48a72d2784606674a2b124b811ea4 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Wed, 24 Jul 2024 11:04:13 +1000 Subject: [PATCH 1/5] update composer.json for SS5 --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 301413e..95032ce 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,15 @@ ], "require": { - "silverstripe/framework": "~4.0" + "silverstripe/framework": "^5" }, "require-dev": { - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^9.6" }, "extra": { "expose": [ "client" ], - "installer-name": "datachange-tracker", "branch-alias": { "dev-master": "5.0.x-dev" } From 02efbeb34e690f93861140b0001a87f575974e93 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Wed, 24 Jul 2024 11:07:19 +1000 Subject: [PATCH 2/5] update composer.json for SS5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 95032ce..aacdeef 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "silverstripe/framework": "^5" + "silverstripe/framework": "^4 || ^5" }, "require-dev": { "phpunit/phpunit": "^9.6" From 6946a18b779133d344536934554b853a57df16b8 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Fri, 26 Jul 2024 09:34:05 +1000 Subject: [PATCH 3/5] cleanup code for SS5 and PHP 8.3 --- CHANGELOG.md | 8 +-- README.md | 15 +--- composer.json | 2 +- src/Extension/ChangeRecordable.php | 2 +- src/Extension/SignificantChangeRecordable.php | 9 +-- src/Extension/SiteTreeChangeRecordable.php | 8 +-- src/Job/CleanupDataChangeHistoryTask.php | 2 +- src/Job/PruneChangesBeforeJob.php | 2 +- src/Model/DataChangeRecord.php | 68 +++++-------------- src/Model/TrackedManyManyList.php | 6 +- src/Service/DataChangeTrackService.php | 6 +- tests/DataChangeCMSTest.php | 6 +- tests/DataChangeTest.php | 4 +- 13 files changed, 41 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20d6a43..707c5ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ # Changelog -All notable changes to this project will be documented in this file. +For more information on changes and releases, please visit [Releases](https://github.com/symbiote/silverstripe-datachange-tracker/releases). -This project adheres to [Semantic Versioning](http://semver.org/). - -## [5.0.0] - -* First SilverStripe 4 compatible version. +This project adheres to [Semantic Versioning](http://semver.org/) diff --git a/README.md b/README.md index c578f91..da77b03 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Total Downloads](https://poser.pugx.org/symbiote/silverstripe-datachange-tracker/downloads.svg)](https://packagist.org/packages/symbiote/silverstripe-datachange-tracker) [![License](https://poser.pugx.org/symbiote/silverstripe-datachange-tracker/license.svg)](https://github.com/symbiote/silverstripe-datachange-tracker/blob/master/LICENSE.md) -Compatible with SilverStripe 4 +Compatible with SilverStripe 4 and 5 ## Maintainers @@ -28,21 +28,10 @@ composer require symbiote/silverstripe-datachange-tracker:~5.0 ## Requirements -* SilverStripe 4 +* SilverStripe 4.12 || 5 ## Documentation * [Quick Start](docs/en/quick-start.md) * [License](LICENSE.md) * [Contributing](CONTRIBUTING.md) - -## Version details - -*3.2.0* - -* Added pruning of data via queuedjobs - -*3.0.0* - -* Removed static DataChangeRecord::track() method - diff --git a/composer.json b/composer.json index aacdeef..0362b68 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "silverstripe/framework": "^4 || ^5" + "silverstripe/framework": "^4.12 || ^5" }, "require-dev": { "phpunit/phpunit": "^9.6" diff --git a/src/Extension/ChangeRecordable.php b/src/Extension/ChangeRecordable.php index a8f6b01..3eacad2 100644 --- a/src/Extension/ChangeRecordable.php +++ b/src/Extension/ChangeRecordable.php @@ -22,7 +22,7 @@ class ChangeRecordable extends DataExtension */ public $dataChangeTrackService; - private static $ignored_fields = array(); + private static $ignored_fields = []; protected $isNewObject = false; diff --git a/src/Extension/SignificantChangeRecordable.php b/src/Extension/SignificantChangeRecordable.php index da46864..d452982 100644 --- a/src/Extension/SignificantChangeRecordable.php +++ b/src/Extension/SignificantChangeRecordable.php @@ -20,14 +20,11 @@ class SignificantChangeRecordable extends DataExtension { - private static $ignored_fields = array(); + private static $ignored_fields = []; - private static $significant_fields = array(); + private static $significant_fields = []; - private static $db = array( - 'LastSignificantChange' => 'DBDatetime', - 'ChangeDescription' => 'Text' - ); + private static $db = ['LastSignificantChange' => 'DBDatetime', 'ChangeDescription' => 'Text']; public function updateCMSFields(FieldList $fields) { diff --git a/src/Extension/SiteTreeChangeRecordable.php b/src/Extension/SiteTreeChangeRecordable.php index 62715e0..cf61d01 100644 --- a/src/Extension/SiteTreeChangeRecordable.php +++ b/src/Extension/SiteTreeChangeRecordable.php @@ -39,13 +39,9 @@ public function updateCMSFields(FieldList $fields) //create a gridfield out of them $gridFieldConfig = GridFieldConfig_RecordViewer::create(); $publishedGrid = new GridField('PublishStates', 'Published States', $dataChanges, $gridFieldConfig); - $dataColumns = $publishedGrid->getConfig()->getComponentByType('SilverStripe\Forms\GridField\GridFieldDataColumns'); + $dataColumns = $publishedGrid->getConfig()->getComponentByType(\SilverStripe\Forms\GridField\GridFieldDataColumns::class); $dataColumns->setDisplayFields( - array('ChangeType' => 'Change Type', - 'ObjectTitle' => 'Page Title', - 'ChangedBy.Title' => 'User', - 'Created' => 'Modification Date', - ) + ['ChangeType' => 'Change Type', 'ObjectTitle' => 'Page Title', 'ChangedBy.Title' => 'User', 'Created' => 'Modification Date'] ); //linking through to the datachanges modeladmin diff --git a/src/Job/CleanupDataChangeHistoryTask.php b/src/Job/CleanupDataChangeHistoryTask.php index 466dd80..dd61a7e 100644 --- a/src/Job/CleanupDataChangeHistoryTask.php +++ b/src/Job/CleanupDataChangeHistoryTask.php @@ -26,7 +26,7 @@ public function run($request) return; } - $since = strtotime($since); + $since = strtotime((string) $since); if (!$since) { echo "Please specify an 'older' param with a date older than which to prune (in strtotime friendly format)
\n"; return; diff --git a/src/Job/PruneChangesBeforeJob.php b/src/Job/PruneChangesBeforeJob.php index 3c0dbd9..50b2f7a 100644 --- a/src/Job/PruneChangesBeforeJob.php +++ b/src/Job/PruneChangesBeforeJob.php @@ -24,7 +24,7 @@ public function __construct($priorTo = null) { $ts = 0; if ($priorTo) { - $ts = strtotime($priorTo); + $ts = strtotime((string) $priorTo); } if ($ts <= 0) { $ts = time() - 90 * 86400; diff --git a/src/Model/DataChangeRecord.php b/src/Model/DataChangeRecord.php index a7b75d6..f790dcb 100644 --- a/src/Model/DataChangeRecord.php +++ b/src/Model/DataChangeRecord.php @@ -36,24 +36,9 @@ class DataChangeRecord extends DataObject 'GetVars' => 'Text', 'PostVars' => 'Text', ]; - private static $has_one = array( - 'ChangedBy' => 'SilverStripe\Security\Member', - 'ChangeRecord' => 'SilverStripe\ORM\DataObject', - ); - private static $summary_fields = array( - 'ChangeType' => 'Change Type', - 'ChangeRecordClass' => 'Record Class', - 'ChangeRecordID' => 'Record ID', - 'ObjectTitle' => 'Record Title', - 'ChangedBy.Title' => 'User', - 'Created' => 'Modification Date', - ); - private static $searchable_fields = array( - 'ChangeType', - 'ObjectTitle', - 'ChangeRecordClass', - 'ChangeRecordID', - ); + private static $has_one = ['ChangedBy' => \SilverStripe\Security\Member::class, 'ChangeRecord' => \SilverStripe\ORM\DataObject::class]; + private static $summary_fields = ['ChangeType' => 'Change Type', 'ChangeRecordClass' => 'Record Class', 'ChangeRecordID' => 'Record ID', 'ObjectTitle' => 'Record Title', 'ChangedBy.Title' => 'User', 'Created' => 'Modification Date']; + private static $searchable_fields = ['ChangeType', 'ObjectTitle', 'ChangeRecordClass', 'ChangeRecordID']; private static $default_sort = 'ID DESC'; /** @@ -62,8 +47,8 @@ class DataChangeRecord extends DataObject * @var boolean */ private static $save_request_vars = false; - private static $field_blacklist = array('Password'); - private static $request_vars_blacklist = array('url', 'SecurityID'); + private static $field_blacklist = ['Password']; + private static $request_vars_blacklist = ['url', 'SecurityID']; public function getCMSFields($params = null) { @@ -73,29 +58,12 @@ public function getCMSFields($params = null) ToggleCompositeField::create( 'Details', 'Details', - array( - ReadonlyField::create('ChangeType', 'Type of change'), - ReadonlyField::create('ChangeRecordClass', 'Record Class'), - ReadonlyField::create('ChangeRecordID', 'Record ID'), - ReadonlyField::create('ObjectTitle', 'Record Title'), - ReadonlyField::create('Created', 'Modification Date'), - ReadonlyField::create('Stage', 'Stage'), - ReadonlyField::create('User', 'User', $this->getMemberDetails()), - ReadonlyField::create('CurrentURL', 'URL'), - ReadonlyField::create('Referer', 'Referer'), - ReadonlyField::create('RemoteIP', 'Remote IP'), - ReadonlyField::create('Agent', 'Agent'), - ) + [ReadonlyField::create('ChangeType', 'Type of change'), ReadonlyField::create('ChangeRecordClass', 'Record Class'), ReadonlyField::create('ChangeRecordID', 'Record ID'), ReadonlyField::create('ObjectTitle', 'Record Title'), ReadonlyField::create('Created', 'Modification Date'), ReadonlyField::create('Stage', 'Stage'), ReadonlyField::create('User', 'User', $this->getMemberDetails()), ReadonlyField::create('CurrentURL', 'URL'), ReadonlyField::create('Referer', 'Referer'), ReadonlyField::create('RemoteIP', 'Remote IP'), ReadonlyField::create('Agent', 'Agent')] )->setStartClosed(false)->addExtraClass('datachange-field'), ToggleCompositeField::create( 'RawData', 'Raw Data', - array( - ReadonlyField::create('Before'), - ReadonlyField::create('After'), - ReadonlyField::create('GetVars'), - ReadonlyField::create('PostVars'), - ) + [ReadonlyField::create('Before'), ReadonlyField::create('After'), ReadonlyField::create('GetVars'), ReadonlyField::create('PostVars')] )->setStartClosed(false)->addExtraClass('datachange-field') ); @@ -106,11 +74,11 @@ public function getCMSFields($params = null) // The solr search service injector dependency causes issues with comparison, since it has public variables that are stored in an array. - $diff->ignoreFields(array('searchService')); + $diff->ignoreFields(['searchService']); $diffed = $diff->diffedData(); $diffText = ''; - $changedFields = array(); + $changedFields = []; foreach ($diffed->toMap() as $field => $prop) { if (is_object($prop)) { continue; @@ -137,7 +105,7 @@ public function getCMSFields($params = null) // Flags fields that cannot be rendered with 'forTemplate'. This prevents bugs where // WorkflowService (of AdvancedWorkflow Module) and BlockManager (of Sheadawson/blocks module) get put // into a field and break the page. - $fieldsToRemove = array(); + $fieldsToRemove = []; foreach ($fields->dataFields() as $field) { $value = $field->Value(); if ($value && is_object($value)) { @@ -145,7 +113,7 @@ public function getCMSFields($params = null) $value, 'forTemplate' )) { - $field->setValue('[Missing '.get_class($value).'::forTemplate]'); + $field->setValue('[Missing '.$value::class.'::forTemplate]'); } } } @@ -198,8 +166,8 @@ public function track(DataObject $changedObject, $type = 'Change') $this->ObjectTitle = $changedObject->Title; $this->Stage = Versioned::get_reading_mode(); - $before = array(); - $after = array(); + $before = []; + $after = []; if ($type != 'Change' && $type != 'New') { // If we are (un)publishing we want to store the entire object $before = ($type === 'Unpublish') ? $changedObject->toMap() : null; @@ -246,7 +214,7 @@ public function track(DataObject $changedObject, $type = 'Change') if (isset($_SERVER['SERVER_NAME'])) { $protocol = 'http'; $protocol = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? 'https://' : 'http://'; - $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '80'; + $port = $_SERVER['SERVER_PORT'] ?? '80'; $this->CurrentURL = $protocol.$_SERVER["SERVER_NAME"].":".$port.$_SERVER["REQUEST_URI"]; } elseif (Director::is_cli()) { @@ -255,9 +223,9 @@ public function track(DataObject $changedObject, $type = 'Change') $this->CurrentURL = 'Could not determine current URL'; } - $this->RemoteIP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : (Director::is_cli() ? 'CLI' : 'Unknown remote addr'); - $this->Referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; - $this->Agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; + $this->RemoteIP = $_SERVER['REMOTE_ADDR'] ?? (Director::is_cli() ? 'CLI' : 'Unknown remote addr'); + $this->Referer = $_SERVER['HTTP_REFERER'] ?? ''; + $this->Agent = $_SERVER['HTTP_USER_AGENT'] ?? ''; $this->write(); return $this; @@ -306,7 +274,7 @@ private function prepareForDataDifferencer($jsonData) // // So solve this, we simply only decode to a depth of 1. (rather than the 512 default) // - $resultJsonData = json_decode($jsonData, true, 1); + $resultJsonData = json_decode((string) $jsonData, true, 1); return $resultJsonData; } } diff --git a/src/Model/TrackedManyManyList.php b/src/Model/TrackedManyManyList.php index 2c8300e..3a49419 100644 --- a/src/Model/TrackedManyManyList.php +++ b/src/Model/TrackedManyManyList.php @@ -12,9 +12,9 @@ */ class TrackedManyManyList extends ManyManyList { - public $trackedRelationships = array(); + public $trackedRelationships = []; - public function add($item, $extraFields = array()) + public function add($item, $extraFields = []) { $this->recordManyManyChange(__FUNCTION__, $item); $result = parent::add($item, $extraFields); @@ -58,7 +58,7 @@ protected function recordManyManyChange($type, $item) $item = $class::get()->byID($item); } $join = $type === 'add' ? ' to ' : ' from '; - $type = ucfirst($type) . ' "' . $item->Title . '"' . $join . $relationName; + $type = ucfirst((string) $type) . ' "' . $item->Title . '"' . $join . $relationName; $onItem->RelatedItem = $item->ClassName . ' #' . $item->ID; singleton('DataChangeTrackService')->track($onItem, $type); } diff --git a/src/Service/DataChangeTrackService.php b/src/Service/DataChangeTrackService.php index d52e7f9..f146aa4 100644 --- a/src/Service/DataChangeTrackService.php +++ b/src/Service/DataChangeTrackService.php @@ -9,10 +9,10 @@ /** * @author Stephen McMahon */ -class DataChangeTrackService +class DataChangeTrackService implements \Stringable { - protected $dcr_cache = array(); + protected $dcr_cache = []; public $disabled = false; @@ -34,7 +34,7 @@ public function resetChangeCache() { $this->dcr_cache = []; } - public function __toString() + public function __toString(): string { return ''; } diff --git a/tests/DataChangeCMSTest.php b/tests/DataChangeCMSTest.php index f1abf2d..04ba617 100644 --- a/tests/DataChangeCMSTest.php +++ b/tests/DataChangeCMSTest.php @@ -66,13 +66,11 @@ public function testCMSFieldsWithJSONData() $body = $response->getBody(); $this->assertTrue( true, - strpos($body, 'Get Vars') !== false, - 'Cannot find \'Get Vars\' field to prove that we\'re actually on the editing DataChangeRecord page.' + str_contains($body, 'Get Vars') ); $this->assertTrue( true, - strpos($body, 'Post Vars') !== false, - 'Cannot find \'Post Vars\' field to prove that we\'re actually on the editing DataChangeRecord page.' + str_contains($body, 'Post Vars') ); } } diff --git a/tests/DataChangeTest.php b/tests/DataChangeTest.php index c686257..86580f2 100644 --- a/tests/DataChangeTest.php +++ b/tests/DataChangeTest.php @@ -79,7 +79,7 @@ public function testManyManyChanges_TableWithNoUnderscores() Injector::inst()->load($newInjectorConfig); // We want to check that $obj->Kids() is returning the injected TrackedManyManyList, not ManyManyList - $this->assertEquals(TrackedManyManyList::class, get_class($obj->Kids())); + $this->assertEquals(TrackedManyManyList::class, $obj->Kids()::class); // We want to make sure the join table looks like how we expect. $this->assertEquals('TestTrackedObject_Kids', $obj->Kids()->getJoinTable()); @@ -137,7 +137,7 @@ public function testAManyManyChanges_TableWithUnderscores() Injector::inst()->load($newInjectorConfig); // We want to check that $obj->Kids() is returning the injected TrackedManyManyList, not ManyManyList - $this->assertEquals(TrackedManyManyList::class, get_class($obj->Kids())); + $this->assertEquals(TrackedManyManyList::class, $obj->Kids()::class); // We want to make sure the join table looks like how we expect. $this->assertEquals('Symbiote_DataChange_Tests_TestTrackedUnderscoreObject_Kids', $obj->Kids()->getJoinTable()); From f38178f3c7aa828c49ddc08ca0a4e0f475f2e93b Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Fri, 26 Jul 2024 09:50:19 +1000 Subject: [PATCH 4/5] fix test errors, cleanup code --- src/Extension/SignificantChangeRecordable.php | 5 +- src/Extension/SiteTreeChangeRecordable.php | 9 ++- src/Model/DataChangeRecord.php | 55 +++++++++++++++---- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/Extension/SignificantChangeRecordable.php b/src/Extension/SignificantChangeRecordable.php index d452982..5d65efc 100644 --- a/src/Extension/SignificantChangeRecordable.php +++ b/src/Extension/SignificantChangeRecordable.php @@ -24,7 +24,10 @@ class SignificantChangeRecordable extends DataExtension private static $significant_fields = []; - private static $db = ['LastSignificantChange' => 'DBDatetime', 'ChangeDescription' => 'Text']; + private static $db = [ + 'LastSignificantChange' => 'DBDatetime', + 'ChangeDescription' => 'Text' + ]; public function updateCMSFields(FieldList $fields) { diff --git a/src/Extension/SiteTreeChangeRecordable.php b/src/Extension/SiteTreeChangeRecordable.php index cf61d01..c26740e 100644 --- a/src/Extension/SiteTreeChangeRecordable.php +++ b/src/Extension/SiteTreeChangeRecordable.php @@ -40,9 +40,12 @@ public function updateCMSFields(FieldList $fields) $gridFieldConfig = GridFieldConfig_RecordViewer::create(); $publishedGrid = new GridField('PublishStates', 'Published States', $dataChanges, $gridFieldConfig); $dataColumns = $publishedGrid->getConfig()->getComponentByType(\SilverStripe\Forms\GridField\GridFieldDataColumns::class); - $dataColumns->setDisplayFields( - ['ChangeType' => 'Change Type', 'ObjectTitle' => 'Page Title', 'ChangedBy.Title' => 'User', 'Created' => 'Modification Date'] - ); + $dataColumns->setDisplayFields([ + 'ChangeType' => 'Change Type', + 'ObjectTitle' => 'Page Title', + 'ChangedBy.Title' => 'User', + 'Created' => 'Modification Date' + ]); //linking through to the datachanges modeladmin diff --git a/src/Model/DataChangeRecord.php b/src/Model/DataChangeRecord.php index f790dcb..4c11e52 100644 --- a/src/Model/DataChangeRecord.php +++ b/src/Model/DataChangeRecord.php @@ -3,6 +3,7 @@ namespace Symbiote\DataChange\Model; use SilverStripe\ORM\DataObject; +use SilverStripe\Security\Security; use SilverStripe\View\Requirements; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\ToggleCompositeField; @@ -36,9 +37,24 @@ class DataChangeRecord extends DataObject 'GetVars' => 'Text', 'PostVars' => 'Text', ]; - private static $has_one = ['ChangedBy' => \SilverStripe\Security\Member::class, 'ChangeRecord' => \SilverStripe\ORM\DataObject::class]; - private static $summary_fields = ['ChangeType' => 'Change Type', 'ChangeRecordClass' => 'Record Class', 'ChangeRecordID' => 'Record ID', 'ObjectTitle' => 'Record Title', 'ChangedBy.Title' => 'User', 'Created' => 'Modification Date']; - private static $searchable_fields = ['ChangeType', 'ObjectTitle', 'ChangeRecordClass', 'ChangeRecordID']; + private static $has_one = [ + 'ChangedBy' => Member::class, + 'ChangeRecord' => DataObject::class + ]; + private static $summary_fields = [ + 'ChangeType' => 'Change Type', + 'ChangeRecordClass' => 'Record Class', + 'ChangeRecordID' => 'Record ID', + 'ObjectTitle' => 'Record Title', + 'ChangedBy.Title' => 'User', + 'Created' => 'Modification Date' + ]; + private static $searchable_fields = [ + 'ChangeType', + 'ObjectTitle', + 'ChangeRecordClass', + 'ChangeRecordID' + ]; private static $default_sort = 'ID DESC'; /** @@ -58,12 +74,29 @@ public function getCMSFields($params = null) ToggleCompositeField::create( 'Details', 'Details', - [ReadonlyField::create('ChangeType', 'Type of change'), ReadonlyField::create('ChangeRecordClass', 'Record Class'), ReadonlyField::create('ChangeRecordID', 'Record ID'), ReadonlyField::create('ObjectTitle', 'Record Title'), ReadonlyField::create('Created', 'Modification Date'), ReadonlyField::create('Stage', 'Stage'), ReadonlyField::create('User', 'User', $this->getMemberDetails()), ReadonlyField::create('CurrentURL', 'URL'), ReadonlyField::create('Referer', 'Referer'), ReadonlyField::create('RemoteIP', 'Remote IP'), ReadonlyField::create('Agent', 'Agent')] + [ + ReadonlyField::create('ChangeType', 'Type of change'), + ReadonlyField::create('ChangeRecordClass', 'Record Class'), + ReadonlyField::create('ChangeRecordID', 'Record ID'), + ReadonlyField::create('ObjectTitle', 'Record Title'), + ReadonlyField::create('Created', 'Modification Date'), + ReadonlyField::create('Stage', 'Stage'), + ReadonlyField::create('User', 'User', $this->getMemberDetails()), + ReadonlyField::create('CurrentURL', 'URL'), + ReadonlyField::create('Referer', 'Referer'), + ReadonlyField::create('RemoteIP', 'Remote IP'), + ReadonlyField::create('Agent', 'Agent') + ] )->setStartClosed(false)->addExtraClass('datachange-field'), ToggleCompositeField::create( 'RawData', 'Raw Data', - [ReadonlyField::create('Before'), ReadonlyField::create('After'), ReadonlyField::create('GetVars'), ReadonlyField::create('PostVars')] + [ + ReadonlyField::create('Before'), + ReadonlyField::create('After'), + ReadonlyField::create('GetVars'), + ReadonlyField::create('PostVars') + ] )->setStartClosed(false)->addExtraClass('datachange-field') ); @@ -95,10 +128,11 @@ public function getCMSFields($params = null) } $fields->insertBefore( + 'RawData', ToggleCompositeField::create('FieldChanges', 'Changed Fields', $changedFields) ->setStartClosed(false) - ->addExtraClass('datachange-field'), - 'RawData' + ->addExtraClass('datachange-field') + ); } @@ -205,10 +239,9 @@ public function track(DataObject $changedObject, $type = 'Change') $this->PostVars = isset($_POST) ? json_encode($_POST) : null; } - $this->ChangedByID = Member::currentUserID(); - - if (Member::currentUserID() && Member::currentUser()) { - $this->CurrentEmail = Member::currentUser()->Email; + if ($member = Security::getCurrentUser()) { + $this->ChangedByID = $member->ID; + $this->CurrentEmail = $member->Email; } if (isset($_SERVER['SERVER_NAME'])) { From 483db329c5c66a7e8b80cf09dfdbb8bc4535afa6 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Thu, 22 Aug 2024 20:27:39 +1000 Subject: [PATCH 5/5] run phpcbf --- src/Extension/ChangeRecordable.php | 3 ++- src/Job/PruneChangesBeforeJob.php | 1 - src/Model/DataChangeRecord.php | 9 ++++----- src/Service/DataChangeTrackService.php | 3 ++- tests/DataChangeCMSTest.php | 2 +- tests/TestTextJSONFieldObject.php | 3 ++- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Extension/ChangeRecordable.php b/src/Extension/ChangeRecordable.php index 3eacad2..be70c4f 100644 --- a/src/Extension/ChangeRecordable.php +++ b/src/Extension/ChangeRecordable.php @@ -80,7 +80,8 @@ public function onBeforeVersionedPublish($from, $to) * * @return \SilverStripe\ORM\DataList */ - public function getDataChangesList() { + public function getDataChangesList() + { return DataChangeRecord::get()->filter([ 'ChangeRecordID' => $this->owner->ID, 'ChangeRecordClass' => $this->owner->ClassName diff --git a/src/Job/PruneChangesBeforeJob.php b/src/Job/PruneChangesBeforeJob.php index 50b2f7a..87987bf 100644 --- a/src/Job/PruneChangesBeforeJob.php +++ b/src/Job/PruneChangesBeforeJob.php @@ -69,4 +69,3 @@ public function process() Injector::inst()->get(QueuedJobService::class)->queueJob($job, $next); } } - diff --git a/src/Model/DataChangeRecord.php b/src/Model/DataChangeRecord.php index 4c11e52..4ce0caf 100644 --- a/src/Model/DataChangeRecord.php +++ b/src/Model/DataChangeRecord.php @@ -120,7 +120,7 @@ public function getCMSFields($params = null) $prop = json_encode($prop); } $changedFields[] = $readOnly = \SilverStripe\Forms\ReadonlyField::create( - 'ChangedField'.$field, + 'ChangedField' . $field, $field, $prop ); @@ -132,7 +132,6 @@ public function getCMSFields($params = null) ToggleCompositeField::create('FieldChanges', 'Changed Fields', $changedFields) ->setStartClosed(false) ->addExtraClass('datachange-field') - ); } @@ -147,7 +146,7 @@ public function getCMSFields($params = null) $value, 'forTemplate' )) { - $field->setValue('[Missing '.$value::class.'::forTemplate]'); + $field->setValue('[Missing ' . $value::class . '::forTemplate]'); } } } @@ -249,7 +248,7 @@ public function track(DataObject $changedObject, $type = 'Change') $protocol = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? 'https://' : 'http://'; $port = $_SERVER['SERVER_PORT'] ?? '80'; - $this->CurrentURL = $protocol.$_SERVER["SERVER_NAME"].":".$port.$_SERVER["REQUEST_URI"]; + $this->CurrentURL = $protocol . $_SERVER["SERVER_NAME"] . ":" . $port . $_SERVER["REQUEST_URI"]; } elseif (Director::is_cli()) { $this->CurrentURL = 'CLI'; } else { @@ -277,7 +276,7 @@ public function canDelete($member = null) * */ public function getTitle() { - return $this->ChangeRecordClass.' #'.$this->ChangeRecordID; + return $this->ChangeRecordClass . ' #' . $this->ChangeRecordID; } /** diff --git a/src/Service/DataChangeTrackService.php b/src/Service/DataChangeTrackService.php index f146aa4..2ab323d 100644 --- a/src/Service/DataChangeTrackService.php +++ b/src/Service/DataChangeTrackService.php @@ -30,7 +30,8 @@ public function track(DataObject $object, $type = 'Change') $this->dcr_cache["{$object->ID}-{$object->Classname}"]->track($object, $type); } - public function resetChangeCache() { + public function resetChangeCache() + { $this->dcr_cache = []; } diff --git a/tests/DataChangeCMSTest.php b/tests/DataChangeCMSTest.php index 04ba617..9d4bf21 100644 --- a/tests/DataChangeCMSTest.php +++ b/tests/DataChangeCMSTest.php @@ -50,7 +50,7 @@ public function testCMSFieldsWithJSONData() // View in the CMS. $this->logInWithPermission('ADMIN'); $dataChangeTrackEditID = $dataChangeTrackRecordIds[0]; - $editLink = 'admin/datachanges/Symbiote-DataChange-Model-DataChangeRecord/EditForm/field/Symbiote-DataChange-Model-DataChangeRecord/item/'.$dataChangeTrackEditID.'/edit'; + $editLink = 'admin/datachanges/Symbiote-DataChange-Model-DataChangeRecord/EditForm/field/Symbiote-DataChange-Model-DataChangeRecord/item/' . $dataChangeTrackEditID . '/edit'; // NOTE(Jake): 2018-06-25 // diff --git a/tests/TestTextJSONFieldObject.php b/tests/TestTextJSONFieldObject.php index 9176dfa..6f7b8b6 100644 --- a/tests/TestTextJSONFieldObject.php +++ b/tests/TestTextJSONFieldObject.php @@ -25,7 +25,8 @@ class TestTextJSONFieldObject extends DataObject implements TestOnly * * This getter pattern was used in at least 1 internal Symbiote project. */ - public function getTextFieldWithJSON() { + public function getTextFieldWithJSON() + { $value = $this->getField('TextFieldWithJSON'); if (is_string($value)) { $value = json_decode($value, true);