aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Comments/CommentsPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Comments/CommentsPlugin.php')
-rw-r--r--apps/dav/lib/Comments/CommentsPlugin.php62
1 files changed, 20 insertions, 42 deletions
diff --git a/apps/dav/lib/Comments/CommentsPlugin.php b/apps/dav/lib/Comments/CommentsPlugin.php
index 5937a2b9afc..2ab7d6ee018 100644
--- a/apps/dav/lib/Comments/CommentsPlugin.php
+++ b/apps/dav/lib/Comments/CommentsPlugin.php
@@ -1,33 +1,16 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\DAV\Comments;
+use OCP\AppFramework\Http;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
+use OCP\Comments\MessageTooLongException;
use OCP\IUserSession;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\NotFound;
@@ -53,24 +36,19 @@ class CommentsPlugin extends ServerPlugin {
public const REPORT_PARAM_OFFSET = '{http://owncloud.org/ns}offset';
public const REPORT_PARAM_TIMESTAMP = '{http://owncloud.org/ns}datetime';
- /** @var ICommentsManager */
- protected $commentsManager;
-
/** @var \Sabre\DAV\Server $server */
private $server;
- /** @var \OCP\IUserSession */
- protected $userSession;
-
/**
* Comments plugin
*
* @param ICommentsManager $commentsManager
* @param IUserSession $userSession
*/
- public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) {
- $this->commentsManager = $commentsManager;
- $this->userSession = $userSession;
+ public function __construct(
+ protected ICommentsManager $commentsManager,
+ protected IUserSession $userSession,
+ ) {
}
/**
@@ -86,13 +64,13 @@ class CommentsPlugin extends ServerPlugin {
*/
public function initialize(Server $server) {
$this->server = $server;
- if (strpos($this->server->getRequestUri(), 'comments/') !== 0) {
+ if (!str_starts_with($this->server->getRequestUri(), 'comments/')) {
return;
}
$this->server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
- $this->server->xml->classMap['DateTime'] = function (Writer $writer, \DateTime $value) {
+ $this->server->xml->classMap['DateTime'] = function (Writer $writer, \DateTime $value): void {
$writer->write(\Sabre\HTTP\toDate($value));
};
@@ -131,7 +109,7 @@ class CommentsPlugin extends ServerPlugin {
$response->setHeader('Content-Location', $url);
// created
- $response->setStatus(201);
+ $response->setStatus(Http::STATUS_CREATED);
return false;
}
@@ -177,7 +155,7 @@ class CommentsPlugin extends ServerPlugin {
}
if (!is_null($args['datetime'])) {
- $args['datetime'] = new \DateTime($args['datetime']);
+ $args['datetime'] = new \DateTime((string)$args['datetime']);
}
$results = $node->findChildren($args['limit'], $args['offset'], $args['datetime']);
@@ -190,7 +168,7 @@ class CommentsPlugin extends ServerPlugin {
$responses[] = new Response(
$this->server->getBaseUri() . $nodePath,
[200 => $resultSet[0][200]],
- 200
+ '200'
);
}
}
@@ -200,7 +178,7 @@ class CommentsPlugin extends ServerPlugin {
new MultiStatus($responses)
);
- $this->server->httpResponse->setStatus(207);
+ $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS);
$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
$this->server->httpResponse->setBody($xml);
@@ -221,7 +199,7 @@ class CommentsPlugin extends ServerPlugin {
*/
private function createComment($objectType, $objectId, $data, $contentType = 'application/json') {
if (explode(';', $contentType)[0] === 'application/json') {
- $data = json_decode($data, true);
+ $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} else {
throw new UnsupportedMediaType();
}
@@ -235,7 +213,7 @@ class CommentsPlugin extends ServerPlugin {
}
}
if (is_null($actorId)) {
- throw new BadRequest('Invalid actor "' . $actorType .'"');
+ throw new BadRequest('Invalid actor "' . $actorType . '"');
}
try {
@@ -246,9 +224,9 @@ class CommentsPlugin extends ServerPlugin {
return $comment;
} catch (\InvalidArgumentException $e) {
throw new BadRequest('Invalid input values', 0, $e);
- } catch (\OCP\Comments\MessageTooLongException $e) {
+ } catch (MessageTooLongException $e) {
$msg = 'Message exceeds allowed character limit of ';
- throw new BadRequest($msg . \OCP\Comments\IComment::MAX_MESSAGE_LENGTH, 0, $e);
+ throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e);
}
}
}