Apply suggestions from code review
authorMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 16:38:10 +0000 (18:38 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 16:38:10 +0000 (18:38 +0200)
17 files changed:
wcfsetup/install/files/lib/system/comment/command/CreateComment.class.php
wcfsetup/install/files/lib/system/comment/command/DeleteComments.class.php
wcfsetup/install/files/lib/system/comment/command/PublishComment.class.php
wcfsetup/install/files/lib/system/comment/response/command/CreateResponse.class.php
wcfsetup/install/files/lib/system/comment/response/command/DeleteResponses.class.php
wcfsetup/install/files/lib/system/comment/response/command/PublishResponse.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/CreateComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/DeleteComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/EditComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/EnableComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/RenderComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/RenderComments.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/UpdateComment.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/responses/CreateResponse.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/responses/EnableResponse.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/responses/RenderResponse.class.php
wcfsetup/install/files/lib/system/endpoint/controller/core/comments/responses/RenderResponses.class.php

index 2fb16d59ac895f5ab3db60e8d27debc8a5849541..a9f450c33084973582622874aa2e49d89f368605 100644 (file)
@@ -49,8 +49,16 @@ final class CreateComment
                 'isDisabled' => $this->isDisabled ? 1 : 0,
             ]
         ]);
-        /** @var Comment $comment */
         $comment = $action->executeAction()['returnValues'];
+        \assert($comment instanceof Comment);
+
+        $this->htmlInputProcessor->setObjectID($comment->getObjectID());
+        if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor)) {
+            (new CommentEditor($comment))->update([
+                'hasEmbeddedObjects' => 1,
+            ]);
+            $comment = new Comment($comment->getObjectID());
+        }
 
         if (!$comment->isDisabled) {
             (new PublishComment($comment))();
@@ -61,14 +69,6 @@ final class CreateComment
             );
         }
 
-        $this->htmlInputProcessor->setObjectID($comment->getObjectID());
-        if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor)) {
-            (new CommentEditor($comment))->update([
-                'hasEmbeddedObjects' => 1,
-            ]);
-            $comment = new Comment($comment->getObjectID());
-        }
-
         $event = new CommentCreated($comment);
         EventHandler::getInstance()->fire($event);
 
index 70674ced91f73692961d5144d16b271d43c8774c..bb68b50aeecca22811c1a840330294327e5a85f4 100644 (file)
@@ -6,8 +6,9 @@ use wcf\data\comment\Comment;
 use wcf\data\comment\CommentAction;
 use wcf\data\comment\response\CommentResponseList;
 use wcf\data\object\type\ObjectType;
-use wcf\data\object\type\ObjectTypeCache;
 use wcf\event\comment\CommentsDeleted;
+use wcf\system\comment\CommentHandler;
+use wcf\system\comment\manager\ICommentManager;
 use wcf\system\comment\response\command\DeleteResponses;
 use wcf\system\event\EventHandler;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
@@ -30,18 +31,18 @@ use wcf\system\user\notification\UserNotificationHandler;
 final class DeleteComments
 {
     private readonly ObjectType $objectType;
+    private readonly ICommentManager $commentManager;
     private readonly array $commentIDs;
 
     public function __construct(
         private readonly array $comments,
         private readonly bool $updateCounters = true,
     ) {
-        $this->commentIDs = \array_map(fn (Comment $comment): int => $comment->commentID, $this->comments);
+        $this->commentIDs = \array_column($this->comments, 'commentID');
         foreach ($this->comments as $comment) {
             if (!isset($this->objectType)) {
-                $this->objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
-            } else if ($this->objectType->objectTypeID !== $comment->objectTypeID) {
-                throw new \InvalidArgumentException('Given comments do not belong to the same object type.');
+                $this->objectType = CommentHandler::getInstance()->getObjectType($comment->objectTypeID);
+                $this->commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
             }
         }
     }
@@ -131,7 +132,7 @@ final class DeleteComments
 
         foreach ($this->comments as $comment) {
             if (!$comment->isDisabled) {
-                $this->objectType->getProcessor()->updateCounter($comment->objectID, -1);
+                $this->commentManager->updateCounter($comment->objectID, -1);
             }
         }
     }
index f16264250c2006c5fdd08e51feb03968584b4f0b..0b1b856162fa3f461f946afc6725a0760563e761 100644 (file)
@@ -5,8 +5,9 @@ namespace wcf\system\comment\command;
 use wcf\data\comment\Comment;
 use wcf\data\comment\CommentEditor;
 use wcf\data\object\type\ObjectType;
-use wcf\data\object\type\ObjectTypeCache;
 use wcf\event\comment\CommentPublished;
+use wcf\system\comment\CommentHandler;
+use wcf\system\comment\manager\ICommentManager;
 use wcf\system\event\EventHandler;
 use wcf\system\user\activity\event\UserActivityEventHandler;
 use wcf\system\user\notification\object\CommentUserNotificationObject;
@@ -25,11 +26,13 @@ use wcf\system\user\notification\UserNotificationHandler;
 final class PublishComment
 {
     private readonly ObjectType $objectType;
+    private readonly ICommentManager $commentManager;
 
     public function __construct(
         private readonly Comment $comment,
     ) {
-        $this->objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID);
+        $this->objectType = CommentHandler::getInstance()->getObjectType($this->comment->objectTypeID);
+        $this->commentManager = CommentHandler::getInstance()->getCommentManagerByID($this->comment->objectTypeID);
     }
 
     public function __invoke(): void
@@ -39,7 +42,7 @@ final class PublishComment
                 'isDisabled' => 0
             ]);
         }
-        $this->objectType->getProcessor()->updateCounter($this->comment->objectID, 1);
+        $this->commentManager->updateCounter($this->comment->objectID, 1);
 
         $this->fireActivityEvent();
         $this->fireNotificationEvent();
index 5dcd77313e81647d0f8644f36a2225950f0234ec..4ac427abacf810c60de08346ce3a987f8fc7319d 100644 (file)
@@ -46,11 +46,19 @@ final class CreateResponse
                 'isDisabled' => $this->isDisabled ? 1 : 0,
             ]
         ]);
-        /** @var CommentResponse $response */
         $response = $action->executeAction()['returnValues'];
+        \assert($response instanceof CommentResponse);
 
         $this->updateResponseData($response);
 
+        $this->htmlInputProcessor->setObjectID($response->getObjectID());
+        if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor)) {
+            (new CommentResponseEditor($response))->update([
+                'hasEmbeddedObjects' => 1,
+            ]);
+            $response = new CommentResponse($response->getObjectID());
+        }
+
         if (!$response->isDisabled) {
             (new PublishResponse($response))();
         } else {
@@ -60,14 +68,6 @@ final class CreateResponse
             );
         }
 
-        $this->htmlInputProcessor->setObjectID($response->getObjectID());
-        if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor)) {
-            (new CommentResponseEditor($response))->update([
-                'hasEmbeddedObjects' => 1,
-            ]);
-            $response = new CommentResponse($response->getObjectID());
-        }
-
         $event = new ResponseCreated($response);
         EventHandler::getInstance()->fire($event);
 
index bf9016aa6aeb5eba0068616358df6e4a5637c0cd..e801cd84ba491ae5a69c4c9dacfb093484cc37b6 100644 (file)
@@ -7,8 +7,9 @@ use wcf\data\comment\CommentList;
 use wcf\data\comment\response\CommentResponse;
 use wcf\data\comment\response\CommentResponseAction;
 use wcf\data\object\type\ObjectType;
-use wcf\data\object\type\ObjectTypeCache;
 use wcf\event\comment\response\ResponsesDeleted;
+use wcf\system\comment\CommentHandler;
+use wcf\system\comment\manager\ICommentManager;
 use wcf\system\event\EventHandler;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\moderation\queue\ModerationQueueManager;
@@ -30,16 +31,19 @@ use wcf\system\user\notification\UserNotificationHandler;
 final class DeleteResponses
 {
     private readonly ObjectType $objectType;
+    private readonly ICommentManager $commentManager;
+
     private readonly array $responseIDs;
 
     public function __construct(
         private readonly array $responses,
         private readonly bool $updateCounters = true,
     ) {
-        $this->responseIDs = \array_map(fn (CommentResponse $response): int => $response->responseID, $this->responses);
+        $this->responseIDs = \array_column($this->responses, 'responseID');
         foreach ($this->responses as $response) {
             if (!isset($this->objectType)) {
-                $this->objectType = ObjectTypeCache::getInstance()->getObjectType($response->getComment()->objectTypeID);
+                $this->objectType = CommentHandler::getInstance()->getObjectType($response->getComment()->objectTypeID);
+                $this->commentManager = CommentHandler::getInstance()->getCommentManagerByID($response->getComment()->objectTypeID);
             }
         }
     }
@@ -133,7 +137,7 @@ final class DeleteResponses
 
         foreach ($this->responses as $response) {
             if (!$response->isDisabled) {
-                $this->objectType->getProcessor()->updateCounter($comments[$response->commentID]->objectID, -1);
+                $this->commentManager->updateCounter($comments[$response->commentID]->objectID, -1);
             }
         }
     }
index bcd4fe7af81222f7bc9ea31472ceee3c69653141..459370ec6a7c600a4f72298685f74f12047f155e 100644 (file)
@@ -9,6 +9,7 @@ use wcf\data\comment\response\CommentResponseEditor;
 use wcf\data\object\type\ObjectType;
 use wcf\event\comment\response\ResponsePublished;
 use wcf\system\comment\CommentHandler;
+use wcf\system\comment\manager\ICommentManager;
 use wcf\system\event\EventHandler;
 use wcf\system\user\activity\event\UserActivityEventHandler;
 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
@@ -27,6 +28,7 @@ use wcf\system\user\notification\UserNotificationHandler;
 final class PublishResponse
 {
     private readonly ObjectType $objectType;
+    private readonly ICommentManager $commentManager;
     private readonly Comment $comment;
 
     public function __construct(
@@ -34,6 +36,7 @@ final class PublishResponse
     ) {
         $this->comment = $response->getComment();
         $this->objectType = CommentHandler::getInstance()->getObjectType($this->comment->objectTypeID);
+        $this->commentManager = CommentHandler::getInstance()->getCommentManagerByID($this->comment->objectTypeID);
     }
 
     public function __invoke(): void
@@ -49,7 +52,7 @@ final class PublishResponse
         // do not prepend the response id as the approved response can appear anywhere
         $commentEditor->updateResponseIDs();
 
-        $this->objectType->getProcessor()->updateCounter($this->comment->objectID, 1);
+        $this->commentManager->updateCounter($this->comment->objectID, 1);
 
         $this->fireActivityEvent();
         $this->fireNotificationEvent();
index 1465a022998398a16106735f0cf68b75c60f2509..01bc7a54b08b96abbfa1abe345b49f9a22e99803 100644 (file)
@@ -46,7 +46,8 @@ final class CreateComment implements IController
             throw new UserInputException('objectTypeID');
         }
 
-        if (!$objectType->getProcessor()->canAdd($parameters->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($parameters->objectTypeID);
+        if (!$commentManager->canAdd($parameters->objectID)) {
             throw new PermissionDeniedException();
         }
 
@@ -58,7 +59,7 @@ final class CreateComment implements IController
             }
         }
 
-        $isDisabled = !$objectType->getProcessor()->canAddWithoutApproval($parameters->objectID);
+        $isDisabled = !$commentManager->canAddWithoutApproval($parameters->objectID);
 
         $htmlInputProcessor = $this->validateMessage($parameters->message);
 
index 047f13bd795db4a456a224de93347db23604f6a6..9a67a580a2937fe5e1b2f8a7cd30730001306896 100644 (file)
@@ -6,8 +6,8 @@ use Laminas\Diactoros\Response\JsonResponse;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use wcf\data\comment\Comment;
-use wcf\data\object\type\ObjectTypeCache;
 use wcf\http\Helper;
+use wcf\system\comment\CommentHandler;
 use wcf\system\endpoint\DeleteRequest;
 use wcf\system\endpoint\IController;
 use wcf\system\exception\PermissionDeniedException;
@@ -37,8 +37,8 @@ final class DeleteComment implements IController
 
     private function assertCommentIsDeletable(Comment $comment): void
     {
-        $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
-        if (!$objectType->getProcessor()->canDeleteComment($comment)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canDeleteComment($comment)) {
             throw new PermissionDeniedException();
         }
     }
index ab1dcbe73fda6f26c5a0c54edfd1d111435de922..aed6aa21e3614f81cf87d5cb05c32980eb40d883 100644 (file)
@@ -9,7 +9,6 @@ use wcf\data\comment\Comment;
 use wcf\http\Helper;
 use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\comment\CommentHandler;
-use wcf\system\comment\manager\ICommentManager;
 use wcf\system\endpoint\GetRequest;
 use wcf\system\endpoint\IController;
 use wcf\system\exception\PermissionDeniedException;
@@ -53,9 +52,8 @@ final class EditComment implements IController
 
     private function assertCommentIsEditable(Comment $comment): void
     {
-        $processor = CommentHandler::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
-        \assert($processor instanceof ICommentManager);
-        if (!$processor->canEditComment($comment)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canEditComment($comment)) {
             throw new PermissionDeniedException();
         }
     }
index b189f5370e0879a0e3bb51e84591a06244c93121..93d49567ce04e2d875490c7d852a803ba0304cc1 100644 (file)
@@ -8,10 +8,8 @@ use Psr\Http\Message\ServerRequestInterface;
 use wcf\data\comment\Comment;
 use wcf\http\Helper;
 use wcf\system\comment\CommentHandler;
-use wcf\system\comment\manager\ICommentManager;
 use wcf\system\endpoint\IController;
 use wcf\system\endpoint\PostRequest;
-use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
 
 /**
@@ -32,20 +30,17 @@ final class EnableComment implements IController
 
         $this->assertCommentCanBeEnabled($comment);
 
-        (new \wcf\system\comment\command\PublishComment($comment))();
+        if (!$comment->isDisabled) {
+            (new \wcf\system\comment\command\PublishComment($comment))();
+        }
 
         return new JsonResponse([]);
     }
 
     private function assertCommentCanBeEnabled(Comment $comment): void
     {
-        if (!$comment->isDisabled) {
-            throw new IllegalLinkException();
-        }
-
-        $processor = CommentHandler::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
-        \assert($processor instanceof ICommentManager);
-        if (!$processor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
index 3644c8862e29c8f3e888a3e88a401e537fe2736e..89c46984d95cd0a1bbcede530ffaf99c733006b9 100644 (file)
@@ -40,16 +40,16 @@ final class RenderComment implements IController
             $request->getQueryParams(),
             <<<'EOT'
                 array {
-                    responseID: null|positive-int,
-                    messageOnly: null|bool,
-                    objectTypeID: null|positive-int,
+                    responseID?: positive-int,
+                    messageOnly?: bool,
+                    objectTypeID?: positive-int,
                 }
                 EOT,
         );
 
-        $this->assertCommentIsAccessible($comment, $parameters['objectTypeID']);
+        $this->assertCommentIsAccessible($comment, $parameters['objectTypeID'] ?? null);
         $response = null;
-        if ($parameters['responseID']) {
+        if (isset($parameters['responseID'])) {
             $response = Helper::fetchObjectFromRequestParameter($parameters['responseID'], CommentResponse::class);
             $this->assertResponseIsAccessible($comment, $response);
         }
@@ -70,24 +70,23 @@ final class RenderComment implements IController
             }
         }
 
-        $commentProcessor = $objectType->getProcessor();
-        if (!$commentProcessor->isAccessible($comment->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->isAccessible($comment->objectID)) {
             throw new PermissionDeniedException();
         }
-        if ($comment->isDisabled && !$commentProcessor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        if ($comment->isDisabled && !$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
 
     private function assertResponseIsAccessible(Comment $comment, CommentResponse $response): void
     {
-        $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
-        $commentProcessor = $objectType->getProcessor();
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
 
         if ($response->commentID != $comment->commentID) {
             throw new PermissionDeniedException();
         }
-        if ($response->isDisabled && !$commentProcessor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        if ($response->isDisabled && !$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
@@ -129,16 +128,16 @@ final class RenderComment implements IController
             return $returnValue;
         }
 
-        $commentProcessor = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
 
         $structuredComment = new StructuredComment($comment);
-        $structuredComment->setIsDeletable($commentProcessor->canDeleteComment($comment));
-        $structuredComment->setIsEditable($commentProcessor->canEditComment($comment));
+        $structuredComment->setIsDeletable($commentManager->canDeleteComment($comment));
+        $structuredComment->setIsEditable($commentManager->canEditComment($comment));
 
         if ($response !== null) {
             // check if response is not visible
-            /** @var CommentResponse $visibleResponse */
             foreach ($comment as $visibleResponse) {
+                \assert($visibleResponse instanceof CommentResponse);
                 if ($visibleResponse->responseID == $response->responseID) {
                     $response = null;
                     break;
@@ -154,15 +153,15 @@ final class RenderComment implements IController
         }
 
         WCF::getTPL()->assign([
-            'commentCanAdd' => $commentProcessor->canAdd(
+            'commentCanAdd' => $commentManager->canAdd(
                 $comment->objectID
             ),
-            'commentCanModerate' => $commentProcessor->canModerate(
+            'commentCanModerate' => $commentManager->canModerate(
                 $comment->objectTypeID,
                 $comment->objectID
             ),
             'commentList' => [$structuredComment],
-            'commentManager' => $commentProcessor,
+            'commentManager' => $commentManager,
         ]);
 
         // load like data
@@ -213,19 +212,19 @@ final class RenderComment implements IController
             return $response->getFormattedMessage();
         }
 
-        $commentProcessor = ObjectTypeCache::getInstance()->getObjectType($response->getComment()->objectTypeID)->getProcessor();
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($response->getComment()->objectTypeID);
 
         $structedResponse = new StructuredCommentResponse($response);
-        $structedResponse->setIsDeletable($commentProcessor->canDeleteResponse($response));
-        $structedResponse->setIsEditable($commentProcessor->canEditResponse($response));
+        $structedResponse->setIsDeletable($commentManager->canDeleteResponse($response));
+        $structedResponse->setIsEditable($commentManager->canEditResponse($response));
 
         return WCF::getTPL()->fetch('commentResponseList', 'wcf', [
             'responseList' => [$structedResponse],
-            'commentCanModerate' => $commentProcessor->canModerate(
+            'commentCanModerate' => $commentManager->canModerate(
                 $response->getComment()->objectTypeID,
                 $response->getComment()->objectID
             ),
-            'commentManager' => $commentProcessor,
+            'commentManager' => $commentManager,
         ]);
     }
 }
index f63b13b9af5f9f91d96c2a4d866ae74365a8f137..dfef4c0d4e7c16dca3c8ab045dc1da134a3b8e76 100644 (file)
@@ -34,7 +34,8 @@ final class RenderComments implements IController
             throw new UserInputException('objectTypeID');
         }
 
-        if (!$objectType->getProcessor()->isAccessible($parameters->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($parameters->objectTypeID);
+        if (!$commentManager->isAccessible($parameters->objectID)) {
             throw new PermissionDeniedException();
         }
 
@@ -61,7 +62,7 @@ final class RenderComments implements IController
     private function getCommentList(int $objectTypeID, int $objectID, int $lastCommentTime): StructuredCommentList
     {
         $commentList = CommentHandler::getInstance()->getCommentList(
-            CommentHandler::getInstance()->getObjectType($objectTypeID)->getProcessor(),
+            CommentHandler::getInstance()->getCommentManagerByID($objectTypeID),
             $objectTypeID,
             $objectID,
             false
index 418d77f5ea890f170918c821454f6dd28cac81f0..1e1be86810b068ed3dae26b2b6b622832abeb52e 100644 (file)
@@ -61,9 +61,8 @@ final class UpdateComment implements IController
 
     private function assertCommentIsEditable(Comment $comment): void
     {
-        $processor = CommentHandler::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
-        \assert($processor instanceof ICommentManager);
-        if (!$processor->canEditComment($comment)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canEditComment($comment)) {
             throw new PermissionDeniedException();
         }
     }
index 487657c7c2b521325a201399a646fa490aafbff6..b2b318626544b842e602596e2722894810f57f81 100644 (file)
@@ -6,11 +6,9 @@ use Laminas\Diactoros\Response\JsonResponse;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use wcf\data\comment\Comment;
-use wcf\data\object\type\ObjectType;
 use wcf\event\message\MessageSpamChecking;
 use wcf\http\Helper;
 use wcf\system\comment\CommentHandler;
-use wcf\system\comment\manager\ICommentManager;
 use wcf\system\endpoint\controller\core\comments\TCommentMessageValidator;
 use wcf\system\endpoint\IController;
 use wcf\system\endpoint\PostRequest;
@@ -46,9 +44,9 @@ final class CreateResponse implements IController
 
         $parameters = Helper::mapApiParameters($request, CreateResponseParameters::class);
         $comment = Helper::fetchObjectFromRequestParameter($parameters->commentID, Comment::class);
-        $objectType = CommentHandler::getInstance()->getObjectType($comment->objectTypeID);
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
 
-        $this->assertResponseIsPossible($objectType, $comment);
+        $this->assertResponseIsPossible($comment);
 
         $username = '';
         if (!WCF::getUser()->userID) {
@@ -58,7 +56,7 @@ final class CreateResponse implements IController
             }
         }
 
-        $isDisabled = !$objectType->getProcessor()->canAddWithoutApproval($comment->objectID);
+        $isDisabled = !$commentManager->canAddWithoutApproval($comment->objectID);
 
         $htmlInputProcessor = $this->validateMessage($parameters->message, true);
 
@@ -87,15 +85,14 @@ final class CreateResponse implements IController
         ]);
     }
 
-    private function assertResponseIsPossible(ObjectType $objectType, Comment $comment): void
+    private function assertResponseIsPossible(Comment $comment): void
     {
-        $processor = $objectType->getProcessor();
-        assert($processor instanceof ICommentManager);
-        if (!$processor->canAdd($comment->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canAdd($comment->objectID)) {
             throw new PermissionDeniedException();
         }
 
-        if ($comment->isDisabled && !$processor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        if ($comment->isDisabled && !$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
index 8b7b8b16aaa18c1968e9e750990cd2dac2f70885..3ac3676dfc94a3d2447ab2d9c433bfdb37901e4f 100644 (file)
@@ -8,10 +8,8 @@ use Psr\Http\Message\ServerRequestInterface;
 use wcf\data\comment\response\CommentResponse;
 use wcf\http\Helper;
 use wcf\system\comment\CommentHandler;
-use wcf\system\comment\manager\ICommentManager;
 use wcf\system\endpoint\IController;
 use wcf\system\endpoint\PostRequest;
-use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
 
 /**
@@ -32,21 +30,18 @@ final class EnableResponse implements IController
 
         $this->assertResponseCanBeEnabled($response);
 
-        (new \wcf\system\comment\response\command\PublishResponse($response))();
+        if (!$response->isDisabled) {
+            (new \wcf\system\comment\response\command\PublishResponse($response))();
+        }
 
         return new JsonResponse([]);
     }
 
     private function assertResponseCanBeEnabled(CommentResponse $response): void
     {
-        if (!$response->isDisabled) {
-            throw new IllegalLinkException();
-        }
-
         $comment = $response->getComment();
-        $processor = CommentHandler::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
-        \assert($processor instanceof ICommentManager);
-        if (!$processor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
index 714d58cfa7c3133a7bd653c8a7f051aa1f4f4859..c6abf16a315cd73ac4239480ff8b38b4bbd1777f 100644 (file)
@@ -7,7 +7,6 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use wcf\data\comment\response\CommentResponse;
 use wcf\data\comment\response\StructuredCommentResponse;
-use wcf\data\object\type\ObjectTypeCache;
 use wcf\http\Helper;
 use wcf\system\comment\CommentHandler;
 use wcf\system\endpoint\GetRequest;
@@ -36,13 +35,13 @@ final class RenderResponse implements IController
             $request->getQueryParams(),
             <<<'EOT'
                 array {
-                    messageOnly: null|bool,
-                    objectTypeID: null|positive-int,
+                    messageOnly?: bool,
+                    objectTypeID?: positive-int,
                 }
                 EOT,
         );
 
-        $this->assertResponseIsAccessible($response, $parameters['objectTypeID']);
+        $this->assertResponseIsAccessible($response, $parameters['objectTypeID'] ?? null);
         $this->markNotificationsAsRead($response);
 
         return new JsonResponse([
@@ -53,21 +52,21 @@ final class RenderResponse implements IController
     private function assertResponseIsAccessible(CommentResponse $response, ?int $objectTypeID = null): void
     {
         $comment = $response->getComment();
-        $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
+        $objectType = CommentHandler::getInstance()->getObjectType($comment->objectTypeID);
         if ($objectTypeID !== null) {
             if ($objectType->objectTypeID !== $objectTypeID) {
                 throw new IllegalLinkException();
             }
         }
-        $commentProcessor = $objectType->getProcessor();
 
-        if (!$commentProcessor->isAccessible($comment->objectID)) {
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
+        if (!$commentManager->isAccessible($comment->objectID)) {
             throw new PermissionDeniedException();
         }
         if ($response->commentID != $comment->commentID) {
             throw new PermissionDeniedException();
         }
-        if ($response->isDisabled && !$commentProcessor->canModerate($comment->objectTypeID, $comment->objectID)) {
+        if ($response->isDisabled && !$commentManager->canModerate($comment->objectTypeID, $comment->objectID)) {
             throw new PermissionDeniedException();
         }
     }
@@ -94,19 +93,19 @@ final class RenderResponse implements IController
             return $response->getFormattedMessage();
         }
 
-        $commentProcessor = ObjectTypeCache::getInstance()->getObjectType($response->getComment()->objectTypeID)->getProcessor();
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($response->getComment()->objectTypeID);
 
         $structedResponse = new StructuredCommentResponse($response);
-        $structedResponse->setIsDeletable($commentProcessor->canDeleteResponse($response));
-        $structedResponse->setIsEditable($commentProcessor->canEditResponse($response));
+        $structedResponse->setIsDeletable($commentManager->canDeleteResponse($response));
+        $structedResponse->setIsEditable($commentManager->canEditResponse($response));
 
         return WCF::getTPL()->fetch('commentResponseList', 'wcf', [
             'responseList' => [$structedResponse],
-            'commentCanModerate' => $commentProcessor->canModerate(
+            'commentCanModerate' => $commentManager->canModerate(
                 $response->getComment()->objectTypeID,
                 $response->getComment()->objectID
             ),
-            'commentManager' => $commentProcessor,
+            'commentManager' => $commentManager,
         ]);
     }
 }
index b269a11d848d576516055d5ad3afb72a473f355d..791f6d4fba72b9cec8996c9ca72ffc2958cd2072 100644 (file)
@@ -9,7 +9,6 @@ use wcf\data\comment\Comment;
 use wcf\data\comment\response\StructuredCommentResponseList;
 use wcf\http\Helper;
 use wcf\system\comment\CommentHandler;
-use wcf\system\comment\manager\ICommentManager;
 use wcf\system\endpoint\GetRequest;
 use wcf\system\endpoint\IController;
 use wcf\system\exception\PermissionDeniedException;
@@ -31,8 +30,7 @@ final class RenderResponses implements IController
     {
         $parameters = Helper::mapApiParameters($request, RenderReponsesParameters::class);
         $comment = Helper::fetchObjectFromRequestParameter($parameters->commentID, Comment::class);
-        $commentManager = CommentHandler::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
-        assert($commentManager instanceof ICommentManager);
+        $commentManager = CommentHandler::getInstance()->getCommentManagerByID($comment->objectTypeID);
 
         if (!$commentManager->isAccessible($comment->objectID)) {
             throw new PermissionDeniedException();