From 90d3ad6086ac444af4354b97482066f1130a3791 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Wed, 10 Mar 2010 12:22:16 +0200 Subject: [PATCH] Clean up of CMIS webservice code --- webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php | 30 +++++++++++++++--------------- webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php | 26 ++++++++++++++------------ webservice/classes/atompub/KT_atom_service.inc.php | 2 +- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php b/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php index 8ab006c..b74991e 100644 --- a/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php +++ b/webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php @@ -147,7 +147,6 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { if (!empty($this->params[1]) && (($this->params[1] == 'children') || ($this->params[1] == 'descendants'))) { - print_r($this->params);exit; $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt()); $feed = $this->getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $this->params[1]); } @@ -340,7 +339,6 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { */ private function getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $feedType = 'children') { - print_r($this->params);exit; if ($feedType == 'children') { try { $entries = $NavigationService->getChildren($repositoryId, $folderId, false, false); @@ -555,10 +553,10 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent); // NOTE not sure about the text type, will need testing, most content will be base64 $cmisContent = (isset($content['cmisra:base64']) - ? $content['cmisra:base64'] - : ((isset($content['cmisra:text'])) - ? $content['cmisra:text'] - : null)); + ? $content['cmisra:base64'] + : ((isset($content['cmisra:text'])) + ? $content['cmisra:text'] + : null)); // if we haven't found it now, the hack begins - retrieve the EXISTING content and submit this as the contentStream // this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly @@ -576,12 +574,11 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { // we assume minor version updates only $major = false; $checkinComment = ''; - $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment); - - if ($response['status_code'] == 1) { - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']); - // Expose the responseFeed - $this->responseFeed = $feed; + try { + $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment); + } + catch (Exception $e) { + $this->responseFeed = KT_cmis_atom_service_helper::getErrorFeed($this, $this->getStatusCode($e), $e->getMessage()); return null; } @@ -670,9 +667,12 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { // check for existing object id as property of submitted object data if (empty($cmisObjectProperties['cmis:objectId'])) { - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout'); - // Expose the responseFeed - $this->responseFeed = $feed; + // not sure this is the best way to deal with this (new InvalidArgumentException) rather than actually throwing an exception + // in the helper code, but I don't feel that throwing an exception is necessary or always wanted; + // alternative is to send the name of the Exception but not an instance, and do an is_a check on the other side, + // but since it will only be needed to this and similar calls, it seems wasteful to do that for every other case + $this->responseFeed = KT_cmis_atom_service_helper::getErrorFeed($this, $this->getStatusCode(new InvalidArgumentException()), + 'No object was specified for checkout'); return null; } diff --git a/webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php b/webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php index e46381f..3c5a19c 100644 --- a/webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php +++ b/webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php @@ -474,9 +474,18 @@ class KT_cmis_atom_service_helper { static public function getErrorFeed(&$service, $status, $message) { - // this seems to cause problems as it sets an http header, and if that header is - // "404 Not Found" we get html output instead of atompub -// $service->setStatus($status); + // TODO determine whether the client needs to see the AtomPub response or if a 404 header is enough. + // reason: when this status header is set and the status is 404 Not Found then the AtomPub response does not + // appear to be seen by browser based clients (I am not sure of non-browser clients) + // NOTE just added a check and only send back the header containing 404, no text, and this works, we get a 404 header + // plus a readable AtomPub response + if (!strstr($status, '404')) { + $service->setStatus($status); + } + else { + $service->setStatus('404'); + } + $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); $feed->newField('title', 'Error: ' . $status, $feed); @@ -507,7 +516,7 @@ class KT_cmis_atom_service_helper { $numObjects = $numQ; $start = 0; $type = CMIS_FOLDER; - + while($start < $numObjects) { $name = $path[$numQ - $numObjects + $start]; @@ -529,7 +538,7 @@ class KT_cmis_atom_service_helper { $objectId = $object->get_folderid(); $lastFolderId = $objectId; } - + ++$start; } @@ -716,10 +725,6 @@ class KT_cmis_atom_service_helper { } $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); - - // hack for removing one level of access - $contentStream = $contentStream['results']; - return $contentStream; } /** @@ -755,9 +760,6 @@ class KT_cmis_atom_service_helper { $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); - // hack for removing one level of access - $contentStream = $contentStream['results']; - // headers specific to output $service->setEtag($eTag); $service->setHeader('Last-Modified', $response['properties']['lastModificationDate']['value']); diff --git a/webservice/classes/atompub/KT_atom_service.inc.php b/webservice/classes/atompub/KT_atom_service.inc.php index fbac5d7..3c0e4f7 100644 --- a/webservice/classes/atompub/KT_atom_service.inc.php +++ b/webservice/classes/atompub/KT_atom_service.inc.php @@ -151,7 +151,7 @@ class KT_atom_service{ // TODO why is this setting an http header for an atompub response? this causes problems with a "404 Not Found" status message public function setStatus($status=NULL){ - header("HTTP/1.1 ".$status); + header("HTTP/1.1 ".$status.""); } public function setEtag($etagValue=NULL){ -- libgit2 0.21.4