Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
*/
public function __construct(array $vars= [],
ISecureRandom $secureRandom = null,
IConfig $config,
IConfig $config = null,
CsrfTokenManager $csrfTokenManager = null,
$stream = 'php://input') {
$this->inputStream = $stream;
Expand Down
17 changes: 12 additions & 5 deletions lib/public/AppFramework/Http/OCSResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
*/

namespace OCP\AppFramework\Http;

use OCP\AppFramework\Http;
use OC\OCS\Result;

/**
* A renderer for OCS responses
Expand All @@ -44,26 +43,30 @@ class OCSResponse extends Response {
private $message;
private $itemscount;
private $itemsperpage;
private $isV2;

/**
* generates the xml or json response for the API call from an multidimenional data array.
*
* @param string $format
* @param int $statuscode
* @param string $message
* @param array $data
* @param int|string $itemscount
* @param int|string $itemsperpage
* @param bool $isV2
* @since 8.1.0
*/
public function __construct($format, $statuscode, $message,
$data=[], $itemscount='',
$itemsperpage='') {
$itemsperpage='', $isV2 = false) {
$this->format = $format;
$this->statuscode = $statuscode;
$this->message = $message;
$this->data = $data;
$this->itemscount = $itemscount;
$this->itemsperpage = $itemsperpage;
$this->isV2 = $isV2;

// set the correct header based on the format parameter
if ($format === 'json') {
Expand All @@ -82,11 +85,15 @@ public function __construct($format, $statuscode, $message,
* @since 8.1.0
*/
public function render() {
$r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
$r = new Result($this->data, $this->statuscode, $this->message);
$r->setTotalItems($this->itemscount);
$r->setItemsPerPage($this->itemsperpage);
$meta = $r->getMeta();
if ($this->isV2 && $this->statuscode === 200) {
$meta['status'] = 'ok';
}

return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
return \OC_API::renderResult($this->format, $meta, $r->getData());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/public/AppFramework/OCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ private function buildOCSResponse($format, $data) {
$params[$key] = $value;
}

$isV2 = substr($this->request->getScriptName(), -11) === '/ocs/v2.php';

$resp = new OCSResponse(
$format, $params['statuscode'],
$params['message'], $params['data'],
$params['itemscount'], $params['itemsperpage']
$params['itemscount'], $params['itemsperpage'], $isV2
);
if (isset($data['headers'])) {
foreach ($data['headers'] as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/AppFramework/Controller/OCSControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function testStatusCodeMapping() {
$this->createMock(ISecureRandom::class),
$configMock
));
$expected = '{"ocs":{"meta":{"status":"failure","statuscode":200,"message":"OK",' .
$expected = '{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK",' .
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
$params = [
'data' => [
Expand Down