Skip to content

Commit

Permalink
Properly set the status text in the ocs response for v2 calls - fixes o…
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Aug 2, 2017
1 parent 3aefba6 commit 6d2217b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit 6d2217b

Please sign in to comment.