'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))();
);
}
- $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);
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;
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);
}
}
}
foreach ($this->comments as $comment) {
if (!$comment->isDisabled) {
- $this->objectType->getProcessor()->updateCounter($comment->objectID, -1);
+ $this->commentManager->updateCounter($comment->objectID, -1);
}
}
}
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;
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
'isDisabled' => 0
]);
}
- $this->objectType->getProcessor()->updateCounter($this->comment->objectID, 1);
+ $this->commentManager->updateCounter($this->comment->objectID, 1);
$this->fireActivityEvent();
$this->fireNotificationEvent();
'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 {
);
}
- $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);
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;
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);
}
}
}
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);
}
}
}
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;
final class PublishResponse
{
private readonly ObjectType $objectType;
+ private readonly ICommentManager $commentManager;
private readonly Comment $comment;
public function __construct(
) {
$this->comment = $response->getComment();
$this->objectType = CommentHandler::getInstance()->getObjectType($this->comment->objectTypeID);
+ $this->commentManager = CommentHandler::getInstance()->getCommentManagerByID($this->comment->objectTypeID);
}
public function __invoke(): void
// 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();
throw new UserInputException('objectTypeID');
}
- if (!$objectType->getProcessor()->canAdd($parameters->objectID)) {
+ $commentManager = CommentHandler::getInstance()->getCommentManagerByID($parameters->objectTypeID);
+ if (!$commentManager->canAdd($parameters->objectID)) {
throw new PermissionDeniedException();
}
}
}
- $isDisabled = !$objectType->getProcessor()->canAddWithoutApproval($parameters->objectID);
+ $isDisabled = !$commentManager->canAddWithoutApproval($parameters->objectID);
$htmlInputProcessor = $this->validateMessage($parameters->message);
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;
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();
}
}
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;
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();
}
}
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;
/**
$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();
}
}
$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);
}
}
}
- $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();
}
}
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;
}
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
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,
]);
}
}
throw new UserInputException('objectTypeID');
}
- if (!$objectType->getProcessor()->isAccessible($parameters->objectID)) {
+ $commentManager = CommentHandler::getInstance()->getCommentManagerByID($parameters->objectTypeID);
+ if (!$commentManager->isAccessible($parameters->objectID)) {
throw new PermissionDeniedException();
}
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
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();
}
}
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;
$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) {
}
}
- $isDisabled = !$objectType->getProcessor()->canAddWithoutApproval($comment->objectID);
+ $isDisabled = !$commentManager->canAddWithoutApproval($comment->objectID);
$htmlInputProcessor = $this->validateMessage($parameters->message, true);
]);
}
- 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();
}
}
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;
/**
$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();
}
}
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;
$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([
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();
}
}
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,
]);
}
}
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;
{
$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();