From 2027bf2686ee077fb2ad65f7a91f920c96b3fd85 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 26 Jan 2016 12:40:05 +0100 Subject: [PATCH] utilize elementMap for parsing DateTime string input argument for REPORT method --- apps/dav/lib/comments/commentsplugin.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/comments/commentsplugin.php b/apps/dav/lib/comments/commentsplugin.php index 2f9b7bab59f..15f4aae3ae2 100644 --- a/apps/dav/lib/comments/commentsplugin.php +++ b/apps/dav/lib/comments/commentsplugin.php @@ -34,6 +34,7 @@ use Sabre\DAV\Xml\Element\Response; use Sabre\DAV\Xml\Response\MultiStatus; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; +use Sabre\Xml\Reader; use Sabre\Xml\Writer; /** @@ -45,7 +46,7 @@ class CommentsPlugin extends ServerPlugin { const REPORT_PARAM_LIMIT = '{http://owncloud.org/ns}limit'; const REPORT_PARAM_OFFSET = '{http://owncloud.org/ns}offset'; - const REPORT_PARAM_TIMESTAMP = '{http://owncloud.org/ns}datetime'; + const REPORT_PARAM_DATETIME = '{http://owncloud.org/ns}datetime'; /** @var ICommentsManager */ protected $commentsManager; @@ -90,6 +91,11 @@ class CommentsPlugin extends ServerPlugin { $writer->write($value->format('Y-m-d H:m:i')); }; + $this->server->xml->elementMap[self::REPORT_PARAM_DATETIME] = function(Reader $reader) { + $element = $reader->parseInnerTree(); + return empty($element) ? null : new \DateTime($element); + }; + $this->server->on('report', [$this, 'onReport']); $this->server->on('method:POST', [$this, 'httpPost']); } @@ -143,7 +149,7 @@ class CommentsPlugin extends ServerPlugin { $acceptableParameters = [ $this::REPORT_PARAM_LIMIT, $this::REPORT_PARAM_OFFSET, - $this::REPORT_PARAM_TIMESTAMP + $this::REPORT_PARAM_DATETIME ]; $ns = '{' . $this::NS_OWNCLOUD . '}'; foreach($report as $parameter) { @@ -153,10 +159,6 @@ class CommentsPlugin extends ServerPlugin { $args[str_replace($ns, '', $parameter['name'])] = $parameter['value']; } - if(!is_null($args['datetime'])) { - $args['datetime'] = new \DateTime($args['datetime']); - } - $results = $node->findChildren($args['limit'], $args['offset'], $args['datetime']); $responses = []; -- 2.39.5