From b771bb624afc8c8deaa368883a6044e331f1a2e0 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 29 Nov 2022 09:35:55 +1300 Subject: [PATCH] API Stop using deprecated API --- src/Controllers/CommentingController.php | 3 ++- src/Forms/CommentForm.php | 4 ++-- src/Model/Comment.php | 16 +++++++++++----- src/Model/Comment/SecurityToken.php | 3 ++- templates/CommentsInterface.ss | 2 +- templates/Includes/CommentReplies.ss | 2 +- tests/CommentingControllerTest.php | 11 ++++++----- tests/CommentsExtensionTest.php | 5 +++-- tests/CommentsGridFieldActionTest.php | 4 ++++ tests/Stubs/CommentableItem.php | 4 +++- 10 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Controllers/CommentingController.php b/src/Controllers/CommentingController.php index a0023a5..500e687 100644 --- a/src/Controllers/CommentingController.php +++ b/src/Controllers/CommentingController.php @@ -19,6 +19,7 @@ use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\PaginatedList; use SilverStripe\Security\Security; +use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware; /** * @package comments @@ -499,7 +500,7 @@ class CommentingController extends Controller public function redirectBack() { // Don't cache the redirect back ever - HTTP::set_cache_age(0); + HTTPCacheControlMiddleware::singleton()->setMaxAge(0); $url = null; diff --git a/src/Forms/CommentForm.php b/src/Forms/CommentForm.php index 5c046a1..837f258 100644 --- a/src/Forms/CommentForm.php +++ b/src/Forms/CommentForm.php @@ -77,9 +77,9 @@ class CommentForm extends Form // limited HTML is allowed. Populated by JS/Ajax. if ($usePreview) { $fields->insertAfter( + 'Comment', ReadonlyField::create('PreviewComment', _t('CommentInterface.PREVIEWLABEL', 'Preview')) - ->setAttribute('style', 'display: none'), // enable through JS - 'Comment' + ->setAttribute('style', 'display: none') // enable through JS ); } diff --git a/src/Model/Comment.php b/src/Model/Comment.php index 26594cb..61f4a51 100755 --- a/src/Model/Comment.php +++ b/src/Model/Comment.php @@ -28,6 +28,7 @@ use SilverStripe\ORM\PaginatedList; use SilverStripe\ORM\SS_List; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; +use SilverStripe\Security\Security; /** * Represents a single comment object. @@ -265,7 +266,12 @@ class Comment extends DataObject */ public function getParent() { - Deprecation::notice('4.0.0', 'Use $this->Parent() instead'); + // this is wrapped in withNoReplacement() because it's called by ViewableData::__get() + // which looks for a `"get$property"` method, which itself is called by + // AssetControllExtension::findAssets() + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.0.0', 'Use $this->Parent() instead'); + }); return $this->BaseClass && $this->ParentID ? DataObject::get_by_id($this->BaseClass, $this->ParentID, true) : null; @@ -428,7 +434,7 @@ class Comment extends DataObject protected function getMember($member = null) { if (!$member) { - $member = Member::currentUser(); + $member = Security::getCurrentUser(); } if (is_numeric($member)) { @@ -477,7 +483,7 @@ class Comment extends DataObject protected function actionLink($action, $member = null) { if (!$member) { - $member = Member::currentUser(); + $member = Security::getCurrentUser(); } if (!$member) { return false; @@ -650,9 +656,9 @@ class Comment extends DataObject // Show member name if given if (($author = $this->Author()) && $author->exists()) { $fields->insertAfter( + 'Name', TextField::create('AuthorMember', $this->fieldLabel('Author'), $author->Title) - ->performReadonlyTransformation(), - 'Name' + ->performReadonlyTransformation() ); } diff --git a/src/Model/Comment/SecurityToken.php b/src/Model/Comment/SecurityToken.php index e511ab4..132addc 100644 --- a/src/Model/Comment/SecurityToken.php +++ b/src/Model/Comment/SecurityToken.php @@ -5,6 +5,7 @@ namespace SilverStripe\Comments\Model\Comment; use SilverStripe\Control\Controller; use SilverStripe\Security\Member; use SilverStripe\Security\RandomGenerator; +use SilverStripe\Security\Security; /** * Provides the ability to generate cryptographically secure tokens for comment moderation @@ -87,7 +88,7 @@ class SecurityToken */ public function checkRequest($request) { - $member = Member::currentUser(); + $member = Security::getCurrentUser(); if (!$member) { return false; } diff --git a/templates/CommentsInterface.ss b/templates/CommentsInterface.ss index b37f7d6..71ff1a3 100755 --- a/templates/CommentsInterface.ss +++ b/templates/CommentsInterface.ss @@ -25,7 +25,7 @@ <% if $PagedComments %>