Commit 712f1028b28666565c909c426d6930604b7cb512
1 parent
515bed4a
Add basic URI templates and service support
Story ID:2713417. CMIS working with PHP client Committed by: Paul Barrett
Showing
5 changed files
with
341 additions
and
246 deletions
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
| @@ -42,6 +42,45 @@ include_once 'KT_cmis_atom_service_helper.inc.php'; | @@ -42,6 +42,45 @@ include_once 'KT_cmis_atom_service_helper.inc.php'; | ||
| 42 | // FIXME ContentStreamAllowed tag is empty (at least sometimes) | 42 | // FIXME ContentStreamAllowed tag is empty (at least sometimes) |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | + * AtomPub Service: object by id | ||
| 46 | + */ | ||
| 47 | +class KT_cmis_atom_service_objectbyid extends KT_cmis_atom_service { | ||
| 48 | + | ||
| 49 | + public function GET_action() | ||
| 50 | + { | ||
| 51 | + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | ||
| 52 | + $objectId = $this->params[0]; | ||
| 53 | + $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | ||
| 54 | + | ||
| 55 | + $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $objectId); | ||
| 56 | + | ||
| 57 | + // Expose the responseFeed | ||
| 58 | + $this->responseFeed = $feed; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +/** | ||
| 64 | + * AtomPub Service: object by path | ||
| 65 | + * Fetches an object using the path to the object instead of the object id | ||
| 66 | + */ | ||
| 67 | +class KT_cmis_atom_service_objectbypath extends KT_cmis_atom_service { | ||
| 68 | + | ||
| 69 | + public function GET_action() | ||
| 70 | + { | ||
| 71 | + $ktapi =& KT_cmis_atom_service_helper::getKt(); | ||
| 72 | + $objectId = KT_cmis_atom_service_helper::getObjectId(explode('/', urldecode($this->params[0])), $ktapi, false); | ||
| 73 | + $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | ||
| 74 | + | ||
| 75 | + $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $objectId); | ||
| 76 | + | ||
| 77 | + // Expose the responseFeed | ||
| 78 | + $this->responseFeed = $feed; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +/** | ||
| 45 | * AtomPub Service: folder | 84 | * AtomPub Service: folder |
| 46 | */ | 85 | */ |
| 47 | class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | 86 | class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| @@ -53,7 +92,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -53,7 +92,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 53 | public function GET_action() | 92 | public function GET_action() |
| 54 | { | 93 | { |
| 55 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 94 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 56 | - | 95 | + |
| 57 | // TODO implement full path/node separation as with Alfresco - i.e. path requests come in on path/ and node requests come in on node/ | 96 | // TODO implement full path/node separation as with Alfresco - i.e. path requests come in on path/ and node requests come in on node/ |
| 58 | // path request e.g.: path/Root Folder/DroppedDocuments | 97 | // path request e.g.: path/Root Folder/DroppedDocuments |
| 59 | // node request e.g.: node/F1/children | 98 | // node request e.g.: node/F1/children |
| @@ -67,14 +106,14 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -67,14 +106,14 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 67 | else if ($this->params[0] == 'path') | 106 | else if ($this->params[0] == 'path') |
| 68 | { | 107 | { |
| 69 | $ktapi =& KT_cmis_atom_service_helper::getKt(); | 108 | $ktapi =& KT_cmis_atom_service_helper::getKt(); |
| 70 | - $folderId = KT_cmis_atom_service_helper::getFolderId($this->params, $ktapi); | 109 | + $folderId = KT_cmis_atom_service_helper::getObjectId($this->params, $ktapi); |
| 71 | } | 110 | } |
| 72 | else if (($this->params[1] == 'children') || ($this->params[1] == 'descendants')) | 111 | else if (($this->params[1] == 'children') || ($this->params[1] == 'descendants')) |
| 73 | { | 112 | { |
| 74 | $folderId = $this->params[0]; | 113 | $folderId = $this->params[0]; |
| 75 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 114 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 76 | $response = $ObjectService->getProperties($repositoryId, $folderId, false, false); | 115 | $response = $ObjectService->getProperties($repositoryId, $folderId, false, false); |
| 77 | - | 116 | + |
| 78 | if ($response['status_code'] == 1) { | 117 | if ($response['status_code'] == 1) { |
| 79 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response['message']); | 118 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, KT_cmis_atom_service::STATUS_SERVER_ERROR, $response['message']); |
| 80 | $this->responseFeed = $feed; | 119 | $this->responseFeed = $feed; |
| @@ -83,7 +122,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -83,7 +122,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 83 | else { | 122 | else { |
| 84 | $response = $response['results']; | 123 | $response = $response['results']; |
| 85 | } | 124 | } |
| 86 | - | 125 | + |
| 87 | $folderName = $response['properties']['name']['value']; | 126 | $folderName = $response['properties']['name']['value']; |
| 88 | } | 127 | } |
| 89 | // NOTE parent changes to parents in later specification | 128 | // NOTE parent changes to parents in later specification |
| @@ -103,7 +142,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -103,7 +142,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 103 | else { | 142 | else { |
| 104 | $response = $response['results']; | 143 | $response = $response['results']; |
| 105 | } | 144 | } |
| 106 | - | 145 | + |
| 107 | // we know that a folder will only have one parent, so we can assume element 0 | 146 | // we know that a folder will only have one parent, so we can assume element 0 |
| 108 | $folderId = $response['properties']['objectId']['value']; | 147 | $folderId = $response['properties']['objectId']['value']; |
| 109 | $folderName = $response['properties']['name']['value']; | 148 | $folderName = $response['properties']['name']['value']; |
| @@ -132,14 +171,14 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -132,14 +171,14 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 132 | * This includes creation/moving of both folders and documents. | 171 | * This includes creation/moving of both folders and documents. |
| 133 | */ | 172 | */ |
| 134 | public function POST_action() | 173 | public function POST_action() |
| 135 | - { | 174 | + { |
| 136 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 175 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 137 | 176 | ||
| 138 | // set default action, objectId and typeId | 177 | // set default action, objectId and typeId |
| 139 | - $action = 'create'; | 178 | + $action = 'create'; |
| 140 | $objectId = null; | 179 | $objectId = null; |
| 141 | $typeId = null; | 180 | $typeId = null; |
| 142 | - | 181 | + |
| 143 | $folderId = $this->params[0]; | 182 | $folderId = $this->params[0]; |
| 144 | $title = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'title'); | 183 | $title = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'title'); |
| 145 | $summary = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'summary'); | 184 | $summary = KT_cmis_atom_service_helper::getAtomValues($this->rawContent, 'summary'); |
| @@ -151,41 +190,41 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -151,41 +190,41 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 151 | // /folder/<folderId>/<sourceFolderId>/<objectId> | 190 | // /folder/<folderId>/<sourceFolderId>/<objectId> |
| 152 | // also possible that there will be an existing ObjectId property, try to cater for both until we know how it really works | 191 | // also possible that there will be an existing ObjectId property, try to cater for both until we know how it really works |
| 153 | // NOTE this also applies to the source folder id, see above | 192 | // NOTE this also applies to the source folder id, see above |
| 154 | - | 193 | + |
| 155 | // check for existing object id as parameter in url | 194 | // check for existing object id as parameter in url |
| 156 | // if sourceFolderId parameter is submitted (expected as parameter 3, or params[2]) then this is a move | 195 | // if sourceFolderId parameter is submitted (expected as parameter 3, or params[2]) then this is a move |
| 157 | if (isset($this->params[2])) { | 196 | if (isset($this->params[2])) { |
| 158 | $action = 'move'; | 197 | $action = 'move'; |
| 159 | $sourceFolderId = $this->params[2]; | 198 | $sourceFolderId = $this->params[2]; |
| 160 | } | 199 | } |
| 161 | - | 200 | + |
| 162 | // get object properties - todo send through original properties array and not modified version | 201 | // get object properties - todo send through original properties array and not modified version |
| 163 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); | 202 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); |
| 164 | $properties = array('name' => $title, 'summary' => $summary, 'objectTypeId' => $cmisObjectProperties['cmis:objectTypeId']); | 203 | $properties = array('name' => $title, 'summary' => $summary, 'objectTypeId' => $cmisObjectProperties['cmis:objectTypeId']); |
| 165 | - | 204 | + |
| 166 | // check for existing object id as property of submitted object data | 205 | // check for existing object id as property of submitted object data |
| 167 | if (!empty($cmisObjectProperties['cmis:objectId'])) { | 206 | if (!empty($cmisObjectProperties['cmis:objectId'])) { |
| 168 | $objectId = $cmisObjectProperties['cmis:objectId']; | 207 | $objectId = $cmisObjectProperties['cmis:objectId']; |
| 169 | } | 208 | } |
| 170 | - | 209 | + |
| 171 | // TODO there may be more to do for the checking of an existing object. | 210 | // TODO there may be more to do for the checking of an existing object. |
| 172 | // e.g. verifying that it does indeed exist, and throwing an exception if it does not: | 211 | // e.g. verifying that it does indeed exist, and throwing an exception if it does not: |
| 173 | // "If the objected property is present but not valid an exception will be thrown" (from CMIS specification) | 212 | // "If the objected property is present but not valid an exception will be thrown" (from CMIS specification) |
| 174 | // NOTE this exception should be thrown in the service API code and not here. | 213 | // NOTE this exception should be thrown in the service API code and not here. |
| 175 | - | 214 | + |
| 176 | // determine type if object is being moved | 215 | // determine type if object is being moved |
| 177 | if (!is_null($objectId)) { | 216 | if (!is_null($objectId)) { |
| 178 | CMISUtil::decodeObjectId($objectId, $typeId); | 217 | CMISUtil::decodeObjectId($objectId, $typeId); |
| 179 | } | 218 | } |
| 180 | - | 219 | + |
| 181 | // check for content stream | 220 | // check for content stream |
| 182 | $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent); | 221 | $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent); |
| 183 | // NOTE not sure about the text type, will need testing, most content will be base64 | 222 | // NOTE not sure about the text type, will need testing, most content will be base64 |
| 184 | - $cmisContent = (isset($content['cmisra:base64']) | ||
| 185 | - ? $content['cmisra:base64'] | ||
| 186 | - : ((isset($content['cmisra:text'])) | ||
| 187 | - ? $content['cmisra:text'] | ||
| 188 | - : null)); | 223 | + $cmisContent = (isset($content['cmisra:base64']) |
| 224 | + ? $content['cmisra:base64'] | ||
| 225 | + : ((isset($content['cmisra:text'])) | ||
| 226 | + ? $content['cmisra:text'] | ||
| 227 | + : null)); | ||
| 189 | 228 | ||
| 190 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 229 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 191 | 230 | ||
| @@ -220,20 +259,20 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -220,20 +259,20 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 220 | else if ($action == 'move') | 259 | else if ($action == 'move') |
| 221 | { | 260 | { |
| 222 | $response = $ObjectService->moveObject($repositoryId, $objectId, $folderId, $sourceFolderId); | 261 | $response = $ObjectService->moveObject($repositoryId, $objectId, $folderId, $sourceFolderId); |
| 223 | - | 262 | + |
| 224 | if ($response['status_code'] == 0) { | 263 | if ($response['status_code'] == 0) { |
| 225 | $success = true; | 264 | $success = true; |
| 226 | } | 265 | } |
| 227 | else { | 266 | else { |
| 228 | $error = $response['message']; | 267 | $error = $response['message']; |
| 229 | } | 268 | } |
| 230 | - | 269 | + |
| 231 | // same object as before | 270 | // same object as before |
| 232 | $newObjectId = $objectId; | 271 | $newObjectId = $objectId; |
| 233 | // FIXME why set this? it does not appear to get used | 272 | // FIXME why set this? it does not appear to get used |
| 234 | $typeId = ucwords($cmisObjectProperties['cmis:objectTypeId']); | 273 | $typeId = ucwords($cmisObjectProperties['cmis:objectTypeId']); |
| 235 | } | 274 | } |
| 236 | - | 275 | + |
| 237 | if ($success) | 276 | if ($success) |
| 238 | { | 277 | { |
| 239 | $this->setStatus(($action == 'create') ? self::STATUS_CREATED : self::STATUS_UPDATED); | 278 | $this->setStatus(($action == 'create') ? self::STATUS_CREATED : self::STATUS_UPDATED); |
| @@ -246,7 +285,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -246,7 +285,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 246 | // Expose the responseFeed | 285 | // Expose the responseFeed |
| 247 | $this->responseFeed = $feed; | 286 | $this->responseFeed = $feed; |
| 248 | } | 287 | } |
| 249 | - | 288 | + |
| 250 | /** | 289 | /** |
| 251 | * Deals with DELETE actions for folders. | 290 | * Deals with DELETE actions for folders. |
| 252 | * This includes deleting a single folder (with no content) and deleting an entire folder tree | 291 | * This includes deleting a single folder (with no content) and deleting an entire folder tree |
| @@ -259,9 +298,9 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -259,9 +298,9 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 259 | // we COULD call deleteObject but when we delete a folder we expect to be trying to delete | 298 | // we COULD call deleteObject but when we delete a folder we expect to be trying to delete |
| 260 | // the folder and all content. | 299 | // the folder and all content. |
| 261 | // TODO determine whether client is requesting deleteObject or deleteTree | 300 | // TODO determine whether client is requesting deleteObject or deleteTree |
| 262 | - | 301 | + |
| 263 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 302 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 264 | - | 303 | + |
| 265 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 304 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 266 | 305 | ||
| 267 | // attempt delete - last parameter sets $deleteAllVersions true | 306 | // attempt delete - last parameter sets $deleteAllVersions true |
| @@ -277,17 +316,17 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -277,17 +316,17 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 277 | else { | 316 | else { |
| 278 | $response = $response['results']; | 317 | $response = $response['results']; |
| 279 | } | 318 | } |
| 280 | - | 319 | + |
| 281 | // list of failed objects? | 320 | // list of failed objects? |
| 282 | if (is_array($response)) | 321 | if (is_array($response)) |
| 283 | { | 322 | { |
| 284 | $this->setStatus(self::STATUS_SERVER_ERROR); | 323 | $this->setStatus(self::STATUS_SERVER_ERROR); |
| 285 | - | 324 | + |
| 286 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); | 325 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); |
| 287 | $feed->newField('title', 'Error: Failed to delete all objects in tree: ' . self::STATUS_SERVER_ERROR, $feed); | 326 | $feed->newField('title', 'Error: Failed to delete all objects in tree: ' . self::STATUS_SERVER_ERROR, $feed); |
| 288 | - | 327 | + |
| 289 | foreach($response as $failed) | 328 | foreach($response as $failed) |
| 290 | - { | 329 | + { |
| 291 | $entry = $feed->newEntry(); | 330 | $entry = $feed->newEntry(); |
| 292 | $objectElement = $feed->newElement('cmisra:object'); | 331 | $objectElement = $feed->newElement('cmisra:object'); |
| 293 | $propertiesElement = $feed->newElement('cmis:properties'); | 332 | $propertiesElement = $feed->newElement('cmis:properties'); |
| @@ -298,11 +337,11 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -298,11 +337,11 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 298 | $objectElement->appendChild($propertiesElement); | 337 | $objectElement->appendChild($propertiesElement); |
| 299 | $entry->appendChild($objectElement); | 338 | $entry->appendChild($objectElement); |
| 300 | } | 339 | } |
| 301 | - | 340 | + |
| 302 | $this->responseFeed = $feed; | 341 | $this->responseFeed = $feed; |
| 303 | return null; | 342 | return null; |
| 304 | } | 343 | } |
| 305 | - | 344 | + |
| 306 | // success | 345 | // success |
| 307 | $this->setStatus(self::STATUS_NO_CONTENT); | 346 | $this->setStatus(self::STATUS_NO_CONTENT); |
| 308 | } | 347 | } |
| @@ -325,7 +364,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -325,7 +364,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 325 | // TODO how will client request depth? for now we assume as part of the url - will probably be covered by URI templates | 364 | // TODO how will client request depth? for now we assume as part of the url - will probably be covered by URI templates |
| 326 | if (isset($this->params[2])) { | 365 | if (isset($this->params[2])) { |
| 327 | $entries = $NavigationService->getDescendants($repositoryId, $folderId, $this->params[2]); | 366 | $entries = $NavigationService->getDescendants($repositoryId, $folderId, $this->params[2]); |
| 328 | - | 367 | + |
| 329 | } | 368 | } |
| 330 | else { | 369 | else { |
| 331 | $entries = $NavigationService->getDescendants($repositoryId, $folderId); | 370 | $entries = $NavigationService->getDescendants($repositoryId, $folderId); |
| @@ -334,22 +373,22 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -334,22 +373,22 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 334 | else { | 373 | else { |
| 335 | // error, we shouldn't be here, if we are then the wrong service/function was called | 374 | // error, we shouldn't be here, if we are then the wrong service/function was called |
| 336 | } | 375 | } |
| 337 | - | 376 | + |
| 338 | // hack, for removing one level of access | 377 | // hack, for removing one level of access |
| 339 | $entries = $entries['results']; | 378 | $entries = $entries['results']; |
| 340 | 379 | ||
| 341 | // $baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL | 380 | // $baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL |
| 342 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); | 381 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); |
| 343 | $workspace = $feed->getWorkspace(); | 382 | $workspace = $feed->getWorkspace(); |
| 344 | - | 383 | + |
| 345 | $feed->newField('title', $folderName . ' ' . ucwords($feedType), $feed); | 384 | $feed->newField('title', $folderName . ' ' . ucwords($feedType), $feed); |
| 346 | - | 385 | + |
| 347 | // TODO dynamic? | 386 | // TODO dynamic? |
| 348 | $feedElement = $feed->newField('author'); | 387 | $feedElement = $feed->newField('author'); |
| 349 | $element = $feed->newField('name', 'System', $feedElement); | 388 | $element = $feed->newField('name', 'System', $feedElement); |
| 350 | $feed->appendChild($feedElement); | 389 | $feed->appendChild($feedElement); |
| 351 | - | ||
| 352 | - // id | 390 | + |
| 391 | + // id | ||
| 353 | $feed->newField('id', 'urn:uuid:' . $folderId . '-' . $feedType, $feed); | 392 | $feed->newField('id', 'urn:uuid:' . $folderId . '-' . $feedType, $feed); |
| 354 | 393 | ||
| 355 | // TODO get actual most recent update time, only use current if no other available | 394 | // TODO get actual most recent update time, only use current if no other available |
| @@ -359,7 +398,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | @@ -359,7 +398,7 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { | ||
| 359 | $link->appendChild($feed->newAttr('rel', 'self')); | 398 | $link->appendChild($feed->newAttr('rel', 'self')); |
| 360 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' . $folderId . '/' . $feedType)); | 399 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' . $folderId . '/' . $feedType)); |
| 361 | $feed->appendChild($link); | 400 | $feed->appendChild($link); |
| 362 | - | 401 | + |
| 363 | $link = $feed->newElement('link'); | 402 | $link = $feed->newElement('link'); |
| 364 | $link->appendChild($feed->newAttr('rel', 'service')); | 403 | $link->appendChild($feed->newAttr('rel', 'service')); |
| 365 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'servicedocument')); | 404 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . 'servicedocument')); |
| @@ -392,11 +431,11 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | @@ -392,11 +431,11 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | ||
| 392 | public function GET_action() | 431 | public function GET_action() |
| 393 | { | 432 | { |
| 394 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 433 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 395 | - | 434 | + |
| 396 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 435 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 397 | 436 | ||
| 398 | $objectId = $this->params[0]; | 437 | $objectId = $this->params[0]; |
| 399 | - | 438 | + |
| 400 | // TODO this is "parents" in later versions of the specification | 439 | // TODO this is "parents" in later versions of the specification |
| 401 | // update accordingly when updating to newer specification | 440 | // update accordingly when updating to newer specification |
| 402 | if ($this->params[1] == 'parent') | 441 | if ($this->params[1] == 'parent') |
| @@ -412,7 +451,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | @@ -412,7 +451,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | ||
| 412 | else { | 451 | else { |
| 413 | $response = $response['results']; | 452 | $response = $response['results']; |
| 414 | } | 453 | } |
| 415 | - | 454 | + |
| 416 | // for now a document will only have one parent as KnowledgeTree does not support multi-filing | 455 | // for now a document will only have one parent as KnowledgeTree does not support multi-filing |
| 417 | // TODO update this code if/when multi-filing support is added | 456 | // TODO update this code if/when multi-filing support is added |
| 418 | $objectId = $response[0]['properties']['objectId']['value']; | 457 | $objectId = $response[0]['properties']['objectId']['value']; |
| @@ -430,7 +469,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | @@ -430,7 +469,7 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | ||
| 430 | // Expose the responseFeed | 469 | // Expose the responseFeed |
| 431 | $this->responseFeed = $feed; | 470 | $this->responseFeed = $feed; |
| 432 | } | 471 | } |
| 433 | - | 472 | + |
| 434 | /** | 473 | /** |
| 435 | * Deals with DELETE actions for documents. | 474 | * Deals with DELETE actions for documents. |
| 436 | * This includes deletion of a specific version of a document (latest version) via deleteObject | 475 | * This includes deletion of a specific version of a document (latest version) via deleteObject |
| @@ -439,12 +478,12 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | @@ -439,12 +478,12 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | ||
| 439 | * @return 204 on success, 500 on error | 478 | * @return 204 on success, 500 on error |
| 440 | */ | 479 | */ |
| 441 | public function DELETE_action() | 480 | public function DELETE_action() |
| 442 | - { | 481 | + { |
| 443 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 482 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 444 | - | 483 | + |
| 445 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); | 484 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); |
| 446 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 485 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 447 | - | 486 | + |
| 448 | // attempt delete | 487 | // attempt delete |
| 449 | $response = $ObjectService->deleteObject($repositoryId, $this->params[0]); | 488 | $response = $ObjectService->deleteObject($repositoryId, $this->params[0]); |
| 450 | 489 | ||
| @@ -454,15 +493,15 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | @@ -454,15 +493,15 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { | ||
| 454 | $this->responseFeed = $feed; | 493 | $this->responseFeed = $feed; |
| 455 | return null; | 494 | return null; |
| 456 | } | 495 | } |
| 457 | - | 496 | + |
| 458 | // success | 497 | // success |
| 459 | - $this->setStatus(self::STATUS_NO_CONTENT); | 498 | + $this->setStatus(self::STATUS_NO_CONTENT); |
| 460 | } | 499 | } |
| 461 | - | 500 | + |
| 462 | } | 501 | } |
| 463 | 502 | ||
| 464 | class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | 503 | class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { |
| 465 | - | 504 | + |
| 466 | protected $serviceType = 'PWC'; | 505 | protected $serviceType = 'PWC'; |
| 467 | 506 | ||
| 468 | /** | 507 | /** |
| @@ -472,7 +511,7 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | @@ -472,7 +511,7 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | ||
| 472 | public function GET_action() | 511 | public function GET_action() |
| 473 | { | 512 | { |
| 474 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 513 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 475 | - | 514 | + |
| 476 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 515 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 477 | 516 | ||
| 478 | // determine whether we want the Private Working Copy entry feed or the actual physical Private Working Copy content. | 517 | // determine whether we want the Private Working Copy entry feed or the actual physical Private Working Copy content. |
| @@ -488,7 +527,7 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | @@ -488,7 +527,7 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | ||
| 488 | // Expose the responseFeed | 527 | // Expose the responseFeed |
| 489 | $this->responseFeed = $feed; | 528 | $this->responseFeed = $feed; |
| 490 | } | 529 | } |
| 491 | - | 530 | + |
| 492 | /** | 531 | /** |
| 493 | * Deals with DELETE actions for Private Working Copies. | 532 | * Deals with DELETE actions for Private Working Copies. |
| 494 | * This includes deletion of a specific version of a document (latest version) via deleteObject | 533 | * This includes deletion of a specific version of a document (latest version) via deleteObject |
| @@ -499,79 +538,79 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | @@ -499,79 +538,79 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { | ||
| 499 | public function DELETE_action() | 538 | public function DELETE_action() |
| 500 | { | 539 | { |
| 501 | // call the cancel checkout function | 540 | // call the cancel checkout function |
| 502 | - | ||
| 503 | - $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 541 | + |
| 542 | + $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | ||
| 504 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); | 543 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); |
| 505 | - | 544 | + |
| 506 | $response = $VersioningService->cancelCheckout($repositoryId, $this->params[0]); | 545 | $response = $VersioningService->cancelCheckout($repositoryId, $this->params[0]); |
| 507 | 546 | ||
| 508 | if ($response['status_code'] == 1) { | 547 | if ($response['status_code'] == 1) { |
| 509 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']); | 548 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']); |
| 510 | - // Expose the responseFeed | 549 | + // Expose the responseFeed |
| 511 | $this->responseFeed = $feed; | 550 | $this->responseFeed = $feed; |
| 512 | return null; | 551 | return null; |
| 513 | } | 552 | } |
| 514 | - | 553 | + |
| 515 | $this->setStatus(self::STATUS_NO_CONTENT); | 554 | $this->setStatus(self::STATUS_NO_CONTENT); |
| 516 | $this->responseFeed = null; | 555 | $this->responseFeed = null; |
| 517 | } | 556 | } |
| 518 | - | 557 | + |
| 519 | public function PUT_action() | 558 | public function PUT_action() |
| 520 | { | 559 | { |
| 521 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 560 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 522 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); | 561 | $VersioningService = new KTVersioningService(KT_cmis_atom_service_helper::getKt()); |
| 523 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 562 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 524 | - | 563 | + |
| 525 | // get object properties | 564 | // get object properties |
| 526 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); | 565 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); |
| 527 | 566 | ||
| 528 | // check for content stream | 567 | // check for content stream |
| 529 | $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent); | 568 | $content = KT_cmis_atom_service_helper::getCmisContent($this->rawContent); |
| 530 | // NOTE not sure about the text type, will need testing, most content will be base64 | 569 | // NOTE not sure about the text type, will need testing, most content will be base64 |
| 531 | - $cmisContent = (isset($content['cmisra:base64']) | ||
| 532 | - ? $content['cmisra:base64'] | ||
| 533 | - : ((isset($content['cmisra:text'])) | ||
| 534 | - ? $content['cmisra:text'] | ||
| 535 | - : null)); | 570 | + $cmisContent = (isset($content['cmisra:base64']) |
| 571 | + ? $content['cmisra:base64'] | ||
| 572 | + : ((isset($content['cmisra:text'])) | ||
| 573 | + ? $content['cmisra:text'] | ||
| 574 | + : null)); | ||
| 536 | 575 | ||
| 537 | // if we haven't found it now, the hack begins - retrieve the EXISTING content and submit this as the contentStream | 576 | // if we haven't found it now, the hack begins - retrieve the EXISTING content and submit this as the contentStream |
| 538 | - // this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly | 577 | + // this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly |
| 539 | // other CMIS clients are the same, does not send a content stream on checkin nor does it offer the user a method to choose one) | 578 | // other CMIS clients are the same, does not send a content stream on checkin nor does it offer the user a method to choose one) |
| 540 | // NOTE that if the content is INTENDED to be empty this and all the above checks will FAIL! | 579 | // NOTE that if the content is INTENDED to be empty this and all the above checks will FAIL! |
| 541 | // FIXME this is horrible, terrible, ugly and bad! | 580 | // FIXME this is horrible, terrible, ugly and bad! |
| 542 | if (empty($cmisContent)) { | 581 | if (empty($cmisContent)) { |
| 543 | $cmisContent = base64_encode(KT_cmis_atom_service_helper::getContentStream($this, $ObjectService, $repositoryId)); | 582 | $cmisContent = base64_encode(KT_cmis_atom_service_helper::getContentStream($this, $ObjectService, $repositoryId)); |
| 544 | } | 583 | } |
| 545 | - | 584 | + |
| 546 | // and if we don't have the content stream by now, we give up...but leave the error to be generated by the underlying KnowledgeTree code | 585 | // and if we don't have the content stream by now, we give up...but leave the error to be generated by the underlying KnowledgeTree code |
| 547 | // checkin function call | 586 | // checkin function call |
| 548 | - // TODO dynamically detect version change type - leaving this for now as the CMIS clients tested do not appear to | 587 | + // TODO dynamically detect version change type - leaving this for now as the CMIS clients tested do not appear to |
| 549 | // offer the choice to the user - perhaps it will turn out that this will come from somewhere else but for now | 588 | // offer the choice to the user - perhaps it will turn out that this will come from somewhere else but for now |
| 550 | // we assume minor version updates only | 589 | // we assume minor version updates only |
| 551 | $major = false; | 590 | $major = false; |
| 552 | $checkinComment = ''; | 591 | $checkinComment = ''; |
| 553 | $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment); | 592 | $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $cmisObjectProperties, $cmisContent, $checkinComment); |
| 554 | - | 593 | + |
| 555 | if ($response['status_code'] == 1) { | 594 | if ($response['status_code'] == 1) { |
| 556 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']); | 595 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response['message']); |
| 557 | // Expose the responseFeed | 596 | // Expose the responseFeed |
| 558 | $this->responseFeed = $feed; | 597 | $this->responseFeed = $feed; |
| 559 | return null; | 598 | return null; |
| 560 | } | 599 | } |
| 561 | - | 600 | + |
| 562 | $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]); | 601 | $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]); |
| 563 | 602 | ||
| 564 | // Expose the responseFeed | 603 | // Expose the responseFeed |
| 565 | $this->responseFeed = $feed; | 604 | $this->responseFeed = $feed; |
| 566 | } | 605 | } |
| 567 | - | 606 | + |
| 568 | } | 607 | } |
| 569 | 608 | ||
| 570 | /** | 609 | /** |
| 571 | * AtomPub Service: checkedout | 610 | * AtomPub Service: checkedout |
| 572 | */ | 611 | */ |
| 573 | class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | 612 | class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { |
| 574 | - | 613 | + |
| 575 | /** | 614 | /** |
| 576 | * Deals with GET actions for checkedout documents. | 615 | * Deals with GET actions for checkedout documents. |
| 577 | */ | 616 | */ |
| @@ -581,31 +620,31 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | @@ -581,31 +620,31 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | ||
| 581 | $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt()); | 620 | $NavigationService = new KTNavigationService(KT_cmis_atom_service_helper::getKt()); |
| 582 | 621 | ||
| 583 | $checkedout = $NavigationService->getCheckedOutDocs($repositoryId); | 622 | $checkedout = $NavigationService->getCheckedOutDocs($repositoryId); |
| 584 | - | 623 | + |
| 585 | // hack, for removing one level of access | 624 | // hack, for removing one level of access |
| 586 | $checkedout = $checkedout['results']; | 625 | $checkedout = $checkedout['results']; |
| 587 | 626 | ||
| 588 | //Create a new response feed | 627 | //Create a new response feed |
| 589 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); | 628 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); |
| 590 | $workspace = $feed->getWorkspace(); | 629 | $workspace = $feed->getWorkspace(); |
| 591 | - | 630 | + |
| 592 | $feed->newField('title', 'Checked out Documents', $feed); | 631 | $feed->newField('title', 'Checked out Documents', $feed); |
| 593 | - | 632 | + |
| 594 | // TODO dynamic? | 633 | // TODO dynamic? |
| 595 | $feedElement = $feed->newField('author'); | 634 | $feedElement = $feed->newField('author'); |
| 596 | $element = $feed->newField('name', 'admin', $feedElement); | 635 | $element = $feed->newField('name', 'admin', $feedElement); |
| 597 | $feed->appendChild($feedElement); | 636 | $feed->appendChild($feedElement); |
| 598 | - | 637 | + |
| 599 | $feed->appendChild($feed->newElement('id', 'urn:uuid:checkedout')); | 638 | $feed->appendChild($feed->newElement('id', 'urn:uuid:checkedout')); |
| 600 | 639 | ||
| 601 | // TODO get actual most recent update time, only use current if no other available | 640 | // TODO get actual most recent update time, only use current if no other available |
| 602 | $feed->appendChild($feed->newElement('updated', KT_cmis_atom_service_helper::formatDatestamp())); | 641 | $feed->appendChild($feed->newElement('updated', KT_cmis_atom_service_helper::formatDatestamp())); |
| 603 | - | 642 | + |
| 604 | $link = $feed->newElement('link'); | 643 | $link = $feed->newElement('link'); |
| 605 | $link->appendChild($feed->newAttr('rel', 'self')); | 644 | $link->appendChild($feed->newAttr('rel', 'self')); |
| 606 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout')); | 645 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout')); |
| 607 | $feed->appendChild($link); | 646 | $feed->appendChild($link); |
| 608 | - | 647 | + |
| 609 | $link = $feed->newElement('link'); | 648 | $link = $feed->newElement('link'); |
| 610 | $link->appendChild($feed->newAttr('rel','first')); | 649 | $link->appendChild($feed->newAttr('rel','first')); |
| 611 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0')); | 650 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/checkedout/pageNo=1&pageSize=0')); |
| @@ -628,7 +667,7 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | @@ -628,7 +667,7 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | ||
| 628 | // Expose the responseFeed | 667 | // Expose the responseFeed |
| 629 | $this->responseFeed = $feed; | 668 | $this->responseFeed = $feed; |
| 630 | } | 669 | } |
| 631 | - | 670 | + |
| 632 | public function POST_action() | 671 | public function POST_action() |
| 633 | { | 672 | { |
| 634 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 673 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| @@ -636,7 +675,7 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | @@ -636,7 +675,7 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | ||
| 636 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); | 675 | $ObjectService = new KTObjectService(KT_cmis_atom_service_helper::getKt()); |
| 637 | 676 | ||
| 638 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); | 677 | $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisObjectProperties($this->rawContent); |
| 639 | - | 678 | + |
| 640 | // check for existing object id as property of submitted object data | 679 | // check for existing object id as property of submitted object data |
| 641 | if (empty($cmisObjectProperties['cmis:objectId'])) | 680 | if (empty($cmisObjectProperties['cmis:objectId'])) |
| 642 | { | 681 | { |
| @@ -645,16 +684,16 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | @@ -645,16 +684,16 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { | ||
| 645 | $this->responseFeed = $feed; | 684 | $this->responseFeed = $feed; |
| 646 | return null; | 685 | return null; |
| 647 | } | 686 | } |
| 648 | - | 687 | + |
| 649 | $response = $VersioningService->checkOut($repositoryId, $cmisObjectProperties['cmis:objectId']); | 688 | $response = $VersioningService->checkOut($repositoryId, $cmisObjectProperties['cmis:objectId']); |
| 650 | - | 689 | + |
| 651 | if ($response['status_code'] == 1) { | 690 | if ($response['status_code'] == 1) { |
| 652 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout'); | 691 | $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, 'No object was specified for checkout'); |
| 653 | // Expose the responseFeed | 692 | // Expose the responseFeed |
| 654 | $this->responseFeed = $feed; | 693 | $this->responseFeed = $feed; |
| 655 | return null; | 694 | return null; |
| 656 | } | 695 | } |
| 657 | - | 696 | + |
| 658 | $this->setStatus(self::STATUS_CREATED); | 697 | $this->setStatus(self::STATUS_CREATED); |
| 659 | $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $cmisObjectProperties['cmis:objectId'], 'POST'); | 698 | $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $cmisObjectProperties['cmis:objectId'], 'POST'); |
| 660 | 699 | ||
| @@ -675,17 +714,17 @@ class KT_cmis_atom_service_types extends KT_cmis_atom_service { | @@ -675,17 +714,17 @@ class KT_cmis_atom_service_types extends KT_cmis_atom_service { | ||
| 675 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); | 714 | $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); |
| 676 | 715 | ||
| 677 | $types = $RepositoryService->getTypes($repositoryId); | 716 | $types = $RepositoryService->getTypes($repositoryId); |
| 678 | - | 717 | + |
| 679 | // hack for removing one level of access | 718 | // hack for removing one level of access |
| 680 | $types = $types['results']; | 719 | $types = $types['results']; |
| 681 | - | 720 | + |
| 682 | $type = ((empty($this->params[0])) ? 'all' : $this->params[0]); | 721 | $type = ((empty($this->params[0])) ? 'all' : $this->params[0]); |
| 683 | $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types); | 722 | $feed = KT_cmis_atom_service_helper::getTypeFeed($type, $types); |
| 684 | 723 | ||
| 685 | // Expose the responseFeed | 724 | // Expose the responseFeed |
| 686 | $this->responseFeed = $feed; | 725 | $this->responseFeed = $feed; |
| 687 | } | 726 | } |
| 688 | - | 727 | + |
| 689 | } | 728 | } |
| 690 | 729 | ||
| 691 | /** | 730 | /** |
webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php
| @@ -7,7 +7,7 @@ class KT_cmis_atom_service_helper { | @@ -7,7 +7,7 @@ class KT_cmis_atom_service_helper { | ||
| 7 | 7 | ||
| 8 | public static $ktapi = null; | 8 | public static $ktapi = null; |
| 9 | public static $repositoryId = null; | 9 | public static $repositoryId = null; |
| 10 | - | 10 | + |
| 11 | /** | 11 | /** |
| 12 | * Helper function to set internal repository id | 12 | * Helper function to set internal repository id |
| 13 | * | 13 | * |
| @@ -18,16 +18,16 @@ class KT_cmis_atom_service_helper { | @@ -18,16 +18,16 @@ class KT_cmis_atom_service_helper { | ||
| 18 | if (is_null($RepositoryService)) { | 18 | if (is_null($RepositoryService)) { |
| 19 | $RepositoryService = new KTRepositoryService(); | 19 | $RepositoryService = new KTRepositoryService(); |
| 20 | } | 20 | } |
| 21 | - | 21 | + |
| 22 | $repositories = $RepositoryService->getRepositories(); | 22 | $repositories = $RepositoryService->getRepositories(); |
| 23 | - | 23 | + |
| 24 | // hack for removing one level of access | 24 | // hack for removing one level of access |
| 25 | $repositories = $repositories['results']; | 25 | $repositories = $repositories['results']; |
| 26 | - | 26 | + |
| 27 | // TODO handle multiple repositories | 27 | // TODO handle multiple repositories |
| 28 | - self::$repositoryId = $repositories[0]['repositoryId']; | 28 | + self::$repositoryId = $repositories[0]['repositoryId']; |
| 29 | } | 29 | } |
| 30 | - | 30 | + |
| 31 | /** | 31 | /** |
| 32 | * Helper function to fetch internal repository id | 32 | * Helper function to fetch internal repository id |
| 33 | * | 33 | * |
| @@ -40,11 +40,11 @@ class KT_cmis_atom_service_helper { | @@ -40,11 +40,11 @@ class KT_cmis_atom_service_helper { | ||
| 40 | * @return string | 40 | * @return string |
| 41 | */ | 41 | */ |
| 42 | static public function getRepositoryId(&$RepositoryService = null, $set = true) | 42 | static public function getRepositoryId(&$RepositoryService = null, $set = true) |
| 43 | - { | 43 | + { |
| 44 | if (empty(self::$repositoryId) || $set) { | 44 | if (empty(self::$repositoryId) || $set) { |
| 45 | self::setRepositoryId($RepositoryService); | 45 | self::setRepositoryId($RepositoryService); |
| 46 | } | 46 | } |
| 47 | - | 47 | + |
| 48 | return self::$repositoryId; | 48 | return self::$repositoryId; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| @@ -60,7 +60,7 @@ class KT_cmis_atom_service_helper { | @@ -60,7 +60,7 @@ class KT_cmis_atom_service_helper { | ||
| 60 | static public function getObjectFeed(&$service, $ObjectService, $repositoryId, $objectId, $method = 'GET') | 60 | static public function getObjectFeed(&$service, $ObjectService, $repositoryId, $objectId, $method = 'GET') |
| 61 | { | 61 | { |
| 62 | self::$repositoryId = $repositoryId; | 62 | self::$repositoryId = $repositoryId; |
| 63 | - | 63 | + |
| 64 | $serviceType = $service->getServiceType(); | 64 | $serviceType = $service->getServiceType(); |
| 65 | $response = $ObjectService->getProperties($repositoryId, $objectId, false, false); | 65 | $response = $ObjectService->getProperties($repositoryId, $objectId, false, false); |
| 66 | 66 | ||
| @@ -70,7 +70,7 @@ class KT_cmis_atom_service_helper { | @@ -70,7 +70,7 @@ class KT_cmis_atom_service_helper { | ||
| 70 | 70 | ||
| 71 | $cmisEntry = $response['results']; | 71 | $cmisEntry = $response['results']; |
| 72 | $response = null; | 72 | $response = null; |
| 73 | - | 73 | + |
| 74 | // POST/PWC responses only send back an entry, not a feed | 74 | // POST/PWC responses only send back an entry, not a feed |
| 75 | if (($serviceType == 'PWC') || ($method == 'POST')) { | 75 | if (($serviceType == 'PWC') || ($method == 'POST')) { |
| 76 | if ($method == 'POST') { | 76 | if ($method == 'POST') { |
| @@ -88,10 +88,10 @@ class KT_cmis_atom_service_helper { | @@ -88,10 +88,10 @@ class KT_cmis_atom_service_helper { | ||
| 88 | 88 | ||
| 89 | if ($serviceType == 'PWC') $pwc = true; else $pwc = false; | 89 | if ($serviceType == 'PWC') $pwc = true; else $pwc = false; |
| 90 | KT_cmis_atom_service_helper::createObjectEntry($response, $cmisEntry, $cmisEntry['properties']['parentId']['value'], $pwc, $method); | 90 | KT_cmis_atom_service_helper::createObjectEntry($response, $cmisEntry, $cmisEntry['properties']['parentId']['value'], $pwc, $method); |
| 91 | - | 91 | + |
| 92 | return $response; | 92 | return $response; |
| 93 | } | 93 | } |
| 94 | - | 94 | + |
| 95 | static public function createObjectFeed(&$feed, $entries, $folderName) | 95 | static public function createObjectFeed(&$feed, $entries, $folderName) |
| 96 | { | 96 | { |
| 97 | foreach($entries as $cmisEntry) { | 97 | foreach($entries as $cmisEntry) { |
| @@ -109,10 +109,10 @@ class KT_cmis_atom_service_helper { | @@ -109,10 +109,10 @@ class KT_cmis_atom_service_helper { | ||
| 109 | * @param $method The request method used (POST/GET/...) | 109 | * @param $method The request method used (POST/GET/...) |
| 110 | */ | 110 | */ |
| 111 | static public function createObjectEntry(&$feed, $cmisEntry, $parent, $pwc = false, $method = 'GET') | 111 | static public function createObjectEntry(&$feed, $cmisEntry, $parent, $pwc = false, $method = 'GET') |
| 112 | - { | 112 | + { |
| 113 | $workspace = $feed->getWorkspace(); | 113 | $workspace = $feed->getWorkspace(); |
| 114 | 114 | ||
| 115 | - // create entry | 115 | + // create entry |
| 116 | $entry = $feed->newEntry(); | 116 | $entry = $feed->newEntry(); |
| 117 | 117 | ||
| 118 | // When request is a POST we will be returning only an object entry, not a full feed, and so this belongs here | 118 | // When request is a POST we will be returning only an object entry, not a full feed, and so this belongs here |
| @@ -124,10 +124,10 @@ class KT_cmis_atom_service_helper { | @@ -124,10 +124,10 @@ class KT_cmis_atom_service_helper { | ||
| 124 | $entry->appendChild($feed->newAttr('xmlns:cmis', 'http://docs.oasis-open.org/ns/cmis/core/200908/')); | 124 | $entry->appendChild($feed->newAttr('xmlns:cmis', 'http://docs.oasis-open.org/ns/cmis/core/200908/')); |
| 125 | $entry->appendChild($feed->newAttr('xmlns:cmisra', 'http://docs.oasis-open.org/ns/cmis/restatom/200908/')); | 125 | $entry->appendChild($feed->newAttr('xmlns:cmisra', 'http://docs.oasis-open.org/ns/cmis/restatom/200908/')); |
| 126 | } | 126 | } |
| 127 | - | 127 | + |
| 128 | self::createObjectEntryContent($entry, $feed, $workspace, $cmisEntry, $parent, $pwc, $method); | 128 | self::createObjectEntryContent($entry, $feed, $workspace, $cmisEntry, $parent, $pwc, $method); |
| 129 | } | 129 | } |
| 130 | - | 130 | + |
| 131 | /** | 131 | /** |
| 132 | * Creates an AtomPub child feed for a CMIS entry and adds it to the supplied entry | 132 | * Creates an AtomPub child feed for a CMIS entry and adds it to the supplied entry |
| 133 | * | 133 | * |
| @@ -152,15 +152,15 @@ class KT_cmis_atom_service_helper { | @@ -152,15 +152,15 @@ class KT_cmis_atom_service_helper { | ||
| 152 | // which does not directly support nesting - attempting to create a new feed and append it within the outer | 152 | // which does not directly support nesting - attempting to create a new feed and append it within the outer |
| 153 | // feed resulted in an empty cmisra:children node, so this approach was substituted | 153 | // feed resulted in an empty cmisra:children node, so this approach was substituted |
| 154 | static public function createChildObjectEntry(&$childrenFeed, $cmisEntry, $workspace, $feed, $folderNam) | 154 | static public function createChildObjectEntry(&$childrenFeed, $cmisEntry, $workspace, $feed, $folderNam) |
| 155 | - { | 155 | + { |
| 156 | $type = strtolower($cmisEntry['properties']['objectTypeId']['value']); | 156 | $type = strtolower($cmisEntry['properties']['objectTypeId']['value']); |
| 157 | - | 157 | + |
| 158 | // create entry | 158 | // create entry |
| 159 | $entry = $feed->newElement('entry'); | 159 | $entry = $feed->newElement('entry'); |
| 160 | self::createObjectEntryContent($entry, $feed, $workspace, $cmisEntry);//, $parent, $pwc, $method); | 160 | self::createObjectEntryContent($entry, $feed, $workspace, $cmisEntry);//, $parent, $pwc, $method); |
| 161 | $childrenFeed->appendChild($entry); | 161 | $childrenFeed->appendChild($entry); |
| 162 | } | 162 | } |
| 163 | - | 163 | + |
| 164 | /** | 164 | /** |
| 165 | * Creates the actual object entry: this is shared between other functions which require this content | 165 | * Creates the actual object entry: this is shared between other functions which require this content |
| 166 | * | 166 | * |
| @@ -174,59 +174,59 @@ class KT_cmis_atom_service_helper { | @@ -174,59 +174,59 @@ class KT_cmis_atom_service_helper { | ||
| 174 | static public function createObjectEntryContent($entry, &$feed, $workspace, $cmisEntry, $parent = '', $pwc = false, $method = 'GET') | 174 | static public function createObjectEntryContent($entry, &$feed, $workspace, $cmisEntry, $parent = '', $pwc = false, $method = 'GET') |
| 175 | { | 175 | { |
| 176 | $type = $cmisEntry['properties']['objectTypeId']['value']; | 176 | $type = $cmisEntry['properties']['objectTypeId']['value']; |
| 177 | - | 177 | + |
| 178 | // TODO dynamic actual creator name | 178 | // TODO dynamic actual creator name |
| 179 | $responseElement = $feed->newField('author'); | 179 | $responseElement = $feed->newField('author'); |
| 180 | $element = $feed->newField('name', 'admin', $responseElement); | 180 | $element = $feed->newField('name', 'admin', $responseElement); |
| 181 | $entry->appendChild($responseElement); | 181 | $entry->appendChild($responseElement); |
| 182 | - | 182 | + |
| 183 | $typeString = str_replace('cmis:', '', $type); | 183 | $typeString = str_replace('cmis:', '', $type); |
| 184 | - | 184 | + |
| 185 | if (!empty($cmisEntry['properties']['contentStreamLength']['value'])) | 185 | if (!empty($cmisEntry['properties']['contentStreamLength']['value'])) |
| 186 | { | 186 | { |
| 187 | $field = $feed->newElement('content'); | 187 | $field = $feed->newElement('content'); |
| 188 | $field->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); | 188 | $field->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); |
| 189 | - $field->appendChild($feed->newAttr('src', CMIS_APP_BASE_URI . $workspace . '/' . $typeString | ||
| 190 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 191 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 189 | + $field->appendChild($feed->newAttr('src', CMIS_APP_BASE_URI . $workspace . '/' . $typeString |
| 190 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 191 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 192 | $entry->appendChild($field); | 192 | $entry->appendChild($field); |
| 193 | } | 193 | } |
| 194 | - | ||
| 195 | - // content & id tags | 194 | + |
| 195 | + // content & id tags | ||
| 196 | $id = $cmisEntry['properties']['objectId']['value']; | 196 | $id = $cmisEntry['properties']['objectId']['value']; |
| 197 | $feed->newField('id', 'urn:uuid:' . $id, $entry); | 197 | $feed->newField('id', 'urn:uuid:' . $id, $entry); |
| 198 | 198 | ||
| 199 | // links | 199 | // links |
| 200 | $link = $feed->newElement('link'); | 200 | $link = $feed->newElement('link'); |
| 201 | $link->appendChild($feed->newAttr('rel', 'self')); | 201 | $link->appendChild($feed->newAttr('rel', 'self')); |
| 202 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' | ||
| 203 | - . (!$pwc ? $typeString : 'pwc') . '/' | ||
| 204 | - . $cmisEntry['properties']['objectId']['value'])); | 202 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' |
| 203 | + . (!$pwc ? $typeString : 'pwc') . '/' | ||
| 204 | + . $cmisEntry['properties']['objectId']['value'])); | ||
| 205 | $entry->appendChild($link); | 205 | $entry->appendChild($link); |
| 206 | 206 | ||
| 207 | $link = $feed->newElement('link'); | 207 | $link = $feed->newElement('link'); |
| 208 | $link->appendChild($feed->newAttr('rel', 'edit')); | 208 | $link->appendChild($feed->newAttr('rel', 'edit')); |
| 209 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString | ||
| 210 | - . '/' . $cmisEntry['properties']['objectId']['value'])); | 209 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString |
| 210 | + . '/' . $cmisEntry['properties']['objectId']['value'])); | ||
| 211 | $entry->appendChild($link); | 211 | $entry->appendChild($link); |
| 212 | - | ||
| 213 | - if ((strtolower($cmisEntry['properties']['objectTypeId']['value']) == 'cmis:document') | ||
| 214 | - && (!empty($cmisEntry['properties']['contentStreamLength']['value']))) | 212 | + |
| 213 | + if ((strtolower($cmisEntry['properties']['objectTypeId']['value']) == 'cmis:document') | ||
| 214 | + && (!empty($cmisEntry['properties']['contentStreamLength']['value']))) | ||
| 215 | { | 215 | { |
| 216 | $link = $feed->newElement('link'); | 216 | $link = $feed->newElement('link'); |
| 217 | $link->appendChild($feed->newAttr('rel', 'edit-media')); | 217 | $link->appendChild($feed->newAttr('rel', 'edit-media')); |
| 218 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); | 218 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); |
| 219 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString | ||
| 220 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 221 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 219 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString |
| 220 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 221 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 222 | $entry->appendChild($link); | 222 | $entry->appendChild($link); |
| 223 | 223 | ||
| 224 | $link = $feed->newElement('link'); | 224 | $link = $feed->newElement('link'); |
| 225 | $link->appendChild($feed->newAttr('rel', 'enclosure')); | 225 | $link->appendChild($feed->newAttr('rel', 'enclosure')); |
| 226 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); | 226 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); |
| 227 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString | ||
| 228 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 229 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 227 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString |
| 228 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 229 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 230 | $entry->appendChild($link); | 230 | $entry->appendChild($link); |
| 231 | } | 231 | } |
| 232 | 232 | ||
| @@ -235,7 +235,7 @@ class KT_cmis_atom_service_helper { | @@ -235,7 +235,7 @@ class KT_cmis_atom_service_helper { | ||
| 235 | $link = $feed->newElement('link'); | 235 | $link = $feed->newElement('link'); |
| 236 | $link->appendChild($feed->newAttr('rel', 'http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions')); | 236 | $link->appendChild($feed->newAttr('rel', 'http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions')); |
| 237 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString . '/' | 237 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString . '/' |
| 238 | - . $cmisEntry['properties']['objectId']['value'] . '/allowableactions')); | 238 | + . $cmisEntry['properties']['objectId']['value'] . '/allowableactions')); |
| 239 | $entry->appendChild($link); | 239 | $entry->appendChild($link); |
| 240 | 240 | ||
| 241 | // according to spec this MUST be present, but spec says that links for function which are not supported | 241 | // according to spec this MUST be present, but spec says that links for function which are not supported |
| @@ -243,12 +243,12 @@ class KT_cmis_atom_service_helper { | @@ -243,12 +243,12 @@ class KT_cmis_atom_service_helper { | ||
| 243 | $link = $feed->newElement('link'); | 243 | $link = $feed->newElement('link'); |
| 244 | $link->appendChild($feed->newAttr('rel', 'http://docs.oasis-open.org/ns/cmis/link/200908/relationships')); | 244 | $link->appendChild($feed->newAttr('rel', 'http://docs.oasis-open.org/ns/cmis/link/200908/relationships')); |
| 245 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString . '/' | 245 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $typeString . '/' |
| 246 | - . $cmisEntry['properties']['objectId']['value'] . '/rels')); | 246 | + . $cmisEntry['properties']['objectId']['value'] . '/rels')); |
| 247 | $entry->appendChild($link); | 247 | $entry->appendChild($link); |
| 248 | - | 248 | + |
| 249 | // if there is no parent or parent is 0, do not add the parent link | 249 | // if there is no parent or parent is 0, do not add the parent link |
| 250 | // also if this is specifically the root folder, do not add the parent link | 250 | // also if this is specifically the root folder, do not add the parent link |
| 251 | -// if (!empty($cmisEntry['properties']['parentId']['value']) && !CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['objectId']['value'])) | 251 | + // if (!empty($cmisEntry['properties']['parentId']['value']) && !CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['objectId']['value'])) |
| 252 | 252 | ||
| 253 | if (!CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['objectId']['value'], self::$ktapi)) | 253 | if (!CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['objectId']['value'], self::$ktapi)) |
| 254 | { | 254 | { |
| @@ -256,7 +256,7 @@ class KT_cmis_atom_service_helper { | @@ -256,7 +256,7 @@ class KT_cmis_atom_service_helper { | ||
| 256 | $link = $feed->newElement('link'); | 256 | $link = $feed->newElement('link'); |
| 257 | $link->appendChild($feed->newAttr('rel', 'up')); | 257 | $link->appendChild($feed->newAttr('rel', 'up')); |
| 258 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' | 258 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' |
| 259 | - . $cmisEntry['properties']['parentId']['value'])); | 259 | + . $cmisEntry['properties']['parentId']['value'])); |
| 260 | $entry->appendChild($link); | 260 | $entry->appendChild($link); |
| 261 | } | 261 | } |
| 262 | 262 | ||
| @@ -266,18 +266,18 @@ class KT_cmis_atom_service_helper { | @@ -266,18 +266,18 @@ class KT_cmis_atom_service_helper { | ||
| 266 | $link = $feed->newElement('link'); | 266 | $link = $feed->newElement('link'); |
| 267 | $link->appendChild($feed->newAttr('rel', 'down')); | 267 | $link->appendChild($feed->newAttr('rel', 'down')); |
| 268 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' | 268 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' |
| 269 | - . $typeString | ||
| 270 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 271 | - . '/children')); | 269 | + . $typeString |
| 270 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 271 | + . '/children')); | ||
| 272 | $entry->appendChild($link); | 272 | $entry->appendChild($link); |
| 273 | $link = $feed->newElement('link'); | 273 | $link = $feed->newElement('link'); |
| 274 | $link->appendChild($feed->newAttr('rel', 'down')); | 274 | $link->appendChild($feed->newAttr('rel', 'down')); |
| 275 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' | 275 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' |
| 276 | - . $typeString | ||
| 277 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 278 | - . '/descendants')); | 276 | + . $typeString |
| 277 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 278 | + . '/descendants')); | ||
| 279 | $entry->appendChild($link); | 279 | $entry->appendChild($link); |
| 280 | - | 280 | + |
| 281 | // TODO add folder tree link when we have folder tree implemented | 281 | // TODO add folder tree link when we have folder tree implemented |
| 282 | // this will probably use (much) the same code as the folder children functionality | 282 | // this will probably use (much) the same code as the folder children functionality |
| 283 | } | 283 | } |
| @@ -290,9 +290,9 @@ class KT_cmis_atom_service_helper { | @@ -290,9 +290,9 @@ class KT_cmis_atom_service_helper { | ||
| 290 | $link = $feed->newElement('link'); | 290 | $link = $feed->newElement('link'); |
| 291 | $link->appendChild($feed->newAttr('rel', 'stream')); | 291 | $link->appendChild($feed->newAttr('rel', 'stream')); |
| 292 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); | 292 | $link->appendChild($feed->newAttr('type', $cmisEntry['properties']['contentStreamMimeType']['value'])); |
| 293 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type | ||
| 294 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 295 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 293 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type |
| 294 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 295 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 296 | $entry->appendChild($link); | 296 | $entry->appendChild($link); |
| 297 | } | 297 | } |
| 298 | 298 | ||
| @@ -303,24 +303,24 @@ class KT_cmis_atom_service_helper { | @@ -303,24 +303,24 @@ class KT_cmis_atom_service_helper { | ||
| 303 | { | 303 | { |
| 304 | $link = $feed->newElement('link'); | 304 | $link = $feed->newElement('link'); |
| 305 | $link->appendChild($feed->newAttr('rel', 'pwc')); | 305 | $link->appendChild($feed->newAttr('rel', 'pwc')); |
| 306 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type | ||
| 307 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 308 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 306 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type |
| 307 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 308 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 309 | $entry->appendChild($link); | 309 | $entry->appendChild($link); |
| 310 | $link = $feed->newElement('link'); | 310 | $link = $feed->newElement('link'); |
| 311 | $link->appendChild($feed->newAttr('rel', 'source')); | 311 | $link->appendChild($feed->newAttr('rel', 'source')); |
| 312 | - $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type | ||
| 313 | - . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 314 | - . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | 312 | + $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type |
| 313 | + . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 314 | + . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 315 | $entry->appendChild($link); | 315 | $entry->appendChild($link); |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | -// $link = $feed->newElement('link'); | ||
| 319 | -// $link->appendChild($feed->newAttr('rel', 'stream')); | ||
| 320 | -// $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type | ||
| 321 | -// . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 322 | -// . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 323 | - } | 318 | + // $link = $feed->newElement('link'); |
| 319 | + // $link->appendChild($feed->newAttr('rel', 'stream')); | ||
| 320 | + // $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type | ||
| 321 | + // . '/' . $cmisEntry['properties']['objectId']['value'] | ||
| 322 | + // . '/' . $cmisEntry['properties']['contentStreamFilename']['value'])); | ||
| 323 | + } | ||
| 324 | 324 | ||
| 325 | $link = $feed->newElement('link'); | 325 | $link = $feed->newElement('link'); |
| 326 | $link->appendChild($feed->newAttr('rel', 'describedby')); | 326 | $link->appendChild($feed->newAttr('rel', 'describedby')); |
| @@ -342,26 +342,26 @@ class KT_cmis_atom_service_helper { | @@ -342,26 +342,26 @@ class KT_cmis_atom_service_helper { | ||
| 342 | $objectElement = $feed->newElement('cmisra:object'); | 342 | $objectElement = $feed->newElement('cmisra:object'); |
| 343 | $objectElement->appendChild(self::createEntryPropertiesElement($feed, $cmisEntry['properties'])); | 343 | $objectElement->appendChild(self::createEntryPropertiesElement($feed, $cmisEntry['properties'])); |
| 344 | $entry->appendChild($objectElement); | 344 | $entry->appendChild($objectElement); |
| 345 | - | 345 | + |
| 346 | // TODO check determination of when to add app:edited tag | 346 | // TODO check determination of when to add app:edited tag |
| 347 | -// if ($method == 'POST') { | ||
| 348 | - $entry->appendChild($feed->newElement('app:edited', self::formatDatestamp())); | ||
| 349 | -// } | 347 | + // if ($method == 'POST') { |
| 348 | + $entry->appendChild($feed->newElement('app:edited', self::formatDatestamp())); | ||
| 349 | + // } | ||
| 350 | 350 | ||
| 351 | // TODO pathSegment entry | 351 | // TODO pathSegment entry |
| 352 | - | 352 | + |
| 353 | // deal with child objects | 353 | // deal with child objects |
| 354 | if (isset($cmisEntry['children'])) { | 354 | if (isset($cmisEntry['children'])) { |
| 355 | // add children node and fill with child entries | 355 | // add children node and fill with child entries |
| 356 | $childrenFeed = $feed->newElement('feed'); | 356 | $childrenFeed = $feed->newElement('feed'); |
| 357 | self::createObjectChildrenFeed($childrenFeed, $cmisEntry['children'], $workspace, $feed, '' /*folderName not passed through*/); | 357 | self::createObjectChildrenFeed($childrenFeed, $cmisEntry['children'], $workspace, $feed, '' /*folderName not passed through*/); |
| 358 | - | 358 | + |
| 359 | $childrenElement = $feed->newElement('cmisra:children'); | 359 | $childrenElement = $feed->newElement('cmisra:children'); |
| 360 | $childrenElement->appendChild($childrenFeed); | 360 | $childrenElement->appendChild($childrenFeed); |
| 361 | $entry->appendChild($childrenElement); | 361 | $entry->appendChild($childrenElement); |
| 362 | } | 362 | } |
| 363 | } | 363 | } |
| 364 | - | 364 | + |
| 365 | /** | 365 | /** |
| 366 | * Shared function for creating an object properties node | 366 | * Shared function for creating an object properties node |
| 367 | * | 367 | * |
| @@ -376,7 +376,7 @@ class KT_cmis_atom_service_helper { | @@ -376,7 +376,7 @@ class KT_cmis_atom_service_helper { | ||
| 376 | foreach($properties as $propertyName => $property) | 376 | foreach($properties as $propertyName => $property) |
| 377 | { | 377 | { |
| 378 | $propElement = $feed->newElement('cmis:' . $property['type']); | 378 | $propElement = $feed->newElement('cmis:' . $property['type']); |
| 379 | -// $propElement->appendChild($feed->newAttr('localName', 'rep-cmis:' . $propertyName)); | 379 | + // $propElement->appendChild($feed->newAttr('localName', 'rep-cmis:' . $propertyName)); |
| 380 | $propElement->appendChild($feed->newAttr('propertyDefinitionId', 'cmis:' . $propertyName)); | 380 | $propElement->appendChild($feed->newAttr('propertyDefinitionId', 'cmis:' . $propertyName)); |
| 381 | if (!empty($property['value'])) | 381 | if (!empty($property['value'])) |
| 382 | { | 382 | { |
| @@ -387,7 +387,7 @@ class KT_cmis_atom_service_helper { | @@ -387,7 +387,7 @@ class KT_cmis_atom_service_helper { | ||
| 387 | } | 387 | } |
| 388 | $propertiesElement->appendChild($propElement); | 388 | $propertiesElement->appendChild($propElement); |
| 389 | } | 389 | } |
| 390 | - | 390 | + |
| 391 | return $propertiesElement; | 391 | return $propertiesElement; |
| 392 | } | 392 | } |
| 393 | 393 | ||
| @@ -419,12 +419,12 @@ class KT_cmis_atom_service_helper { | @@ -419,12 +419,12 @@ class KT_cmis_atom_service_helper { | ||
| 419 | //Create a new response feed | 419 | //Create a new response feed |
| 420 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); | 420 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); |
| 421 | $workspace = $feed->getWorkspace(); | 421 | $workspace = $feed->getWorkspace(); |
| 422 | - | 422 | + |
| 423 | $feed->newField('title', $typesHeading, $feed); | 423 | $feed->newField('title', $typesHeading, $feed); |
| 424 | $feed->newField('id', 'urn:uuid:' . $typesString, $feed); | 424 | $feed->newField('id', 'urn:uuid:' . $typesString, $feed); |
| 425 | 425 | ||
| 426 | // TODO set page number correctly - to be done when we support paging the the API | 426 | // TODO set page number correctly - to be done when we support paging the the API |
| 427 | - | 427 | + |
| 428 | // author | 428 | // author |
| 429 | // TODO generate this dynamically (based on???)\ | 429 | // TODO generate this dynamically (based on???)\ |
| 430 | $feedElement = $feed->newField('author'); | 430 | $feedElement = $feed->newField('author'); |
| @@ -434,7 +434,7 @@ class KT_cmis_atom_service_helper { | @@ -434,7 +434,7 @@ class KT_cmis_atom_service_helper { | ||
| 434 | foreach($types as $type) | 434 | foreach($types as $type) |
| 435 | { | 435 | { |
| 436 | $entry = $feed->newEntry(); | 436 | $entry = $feed->newEntry(); |
| 437 | - | 437 | + |
| 438 | $feedElement = $feed->newField('author'); | 438 | $feedElement = $feed->newField('author'); |
| 439 | $element = $feed->newField('name', 'admin', $feedElement); | 439 | $element = $feed->newField('name', 'admin', $feedElement); |
| 440 | $entry->appendChild($feedElement); | 440 | $entry->appendChild($feedElement); |
| @@ -442,7 +442,7 @@ class KT_cmis_atom_service_helper { | @@ -442,7 +442,7 @@ class KT_cmis_atom_service_helper { | ||
| 442 | $entry->appendChild($feedElement); | 442 | $entry->appendChild($feedElement); |
| 443 | 443 | ||
| 444 | $feed->newField('id', 'urn:uuid:type-' . $type['baseId'], $feed); | 444 | $feed->newField('id', 'urn:uuid:type-' . $type['baseId'], $feed); |
| 445 | - | 445 | + |
| 446 | // links | 446 | // links |
| 447 | $link = $feed->newElement('link'); | 447 | $link = $feed->newElement('link'); |
| 448 | $link->appendChild($feed->newAttr('rel','self')); | 448 | $link->appendChild($feed->newAttr('rel','self')); |
| @@ -459,11 +459,11 @@ class KT_cmis_atom_service_helper { | @@ -459,11 +459,11 @@ class KT_cmis_atom_service_helper { | ||
| 459 | $link->appendChild($feed->newAttr('rel','repository')); | 459 | $link->appendChild($feed->newAttr('rel','repository')); |
| 460 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . '/servicedocument')); | 460 | $link->appendChild($feed->newAttr('href', CMIS_APP_BASE_URI . '/servicedocument')); |
| 461 | $entry->appendChild($link); | 461 | $entry->appendChild($link); |
| 462 | - | 462 | + |
| 463 | $entry->appendChild($feed->newElement('summary', 'Summary for ' . $type['baseId'] . ' type')); | 463 | $entry->appendChild($feed->newElement('summary', 'Summary for ' . $type['baseId'] . ' type')); |
| 464 | $entry->appendChild($feed->newElement('title', $type['baseId'])); | 464 | $entry->appendChild($feed->newElement('title', $type['baseId'])); |
| 465 | $entry->appendChild($feed->newElement('updated', self::formatDatestamp())); | 465 | $entry->appendChild($feed->newElement('updated', self::formatDatestamp())); |
| 466 | - | 466 | + |
| 467 | $objectElement = $feed->newElement('cmisra:type'); | 467 | $objectElement = $feed->newElement('cmisra:type'); |
| 468 | foreach($type as $property => $value) { | 468 | foreach($type as $property => $value) { |
| 469 | $feed->newField('cmis:' . $property, CMISUtil::boolToString($value), $objectElement); | 469 | $feed->newField('cmis:' . $property, CMISUtil::boolToString($value), $objectElement); |
| @@ -478,7 +478,7 @@ class KT_cmis_atom_service_helper { | @@ -478,7 +478,7 @@ class KT_cmis_atom_service_helper { | ||
| 478 | { | 478 | { |
| 479 | $service->setStatus($status); | 479 | $service->setStatus($status); |
| 480 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); | 480 | $feed = new KT_cmis_atom_responseFeed_GET(CMIS_APP_BASE_URI); |
| 481 | - | 481 | + |
| 482 | $feed->newField('title', 'Error: ' . $status, $feed); | 482 | $feed->newField('title', 'Error: ' . $status, $feed); |
| 483 | $entry = $feed->newEntry(); | 483 | $entry = $feed->newEntry(); |
| 484 | $feed->newField('error', $message, $entry); | 484 | $feed->newField('error', $message, $entry); |
| @@ -493,31 +493,49 @@ class KT_cmis_atom_service_helper { | @@ -493,31 +493,49 @@ class KT_cmis_atom_service_helper { | ||
| 493 | * @param object $ktapi KTAPI instance | 493 | * @param object $ktapi KTAPI instance |
| 494 | */ | 494 | */ |
| 495 | // TODO make this much more efficient than this method | 495 | // TODO make this much more efficient than this method |
| 496 | - static public function getFolderId($path, &$ktapi) | 496 | + static public function getObjectId($path, &$ktapi, $shift = true) |
| 497 | { | 497 | { |
| 498 | - // lose first item | ||
| 499 | - array_shift($path); | 498 | + // lose first item, if not specified to keep ($shift == false) |
| 499 | + // NOTE the shift was for the way info comes from the Drupal module, which may now have changed | ||
| 500 | + if ($shift) { | ||
| 501 | + array_shift($path); | ||
| 502 | + } | ||
| 500 | 503 | ||
| 504 | + // we always start at the root | ||
| 505 | + $lastFolderId = $objectId = 1; | ||
| 501 | $numQ = count($path); | 506 | $numQ = count($path); |
| 502 | - $numFolders = $numQ; | ||
| 503 | - $folderId = 1; | ||
| 504 | - | 507 | + $numObjects = $numQ; |
| 505 | $start = 0; | 508 | $start = 0; |
| 506 | - while($start < $numFolders) | 509 | + $type = FOLDER; |
| 510 | + | ||
| 511 | + while($start < $numObjects) | ||
| 507 | { | 512 | { |
| 508 | - $name = $path[$numQ-$numFolders+$start]; | ||
| 509 | - // fix for possible url encoding issue | 513 | + $name = $path[$numQ - $numObjects + $start]; |
| 514 | + // fix for possible url encoding issue - this was for the Drupal code and hopefully one day we can remove it | ||
| 510 | $name = str_replace('%2520', '%20', $name); | 515 | $name = str_replace('%2520', '%20', $name); |
| 511 | 516 | ||
| 512 | - $folderName = urldecode($name); | ||
| 513 | - $folder = $ktapi->get_folder_by_name($folderName, $folderId); | ||
| 514 | - $folderId = $folder->get_folderid(); | 517 | + $objectName = urldecode($name); |
| 518 | + // try to get a folder by that name | ||
| 519 | + $object = $ktapi->get_folder_by_name($objectName, $lastFolderId); | ||
| 520 | + if (PEAR::isError($object)) { | ||
| 521 | + // probably not a folder, so let's try for a document by that name | ||
| 522 | + $object = $ktapi->get_document_detail_by_name($lastFolderId, $objectName); | ||
| 523 | + $objectId = $object['results']['document_id']; | ||
| 524 | + // this must be the end (can't have sub-documents or sub-folders within a document | ||
| 525 | + $type = DOCUMENT; | ||
| 526 | + break; | ||
| 527 | + } | ||
| 528 | + else { | ||
| 529 | + $objectId = $object->get_folderid(); | ||
| 530 | + $lastFolderId = $objectId; | ||
| 531 | + } | ||
| 532 | + | ||
| 515 | ++$start; | 533 | ++$start; |
| 516 | } | 534 | } |
| 517 | - | ||
| 518 | - return CMISUtil::encodeObjectId(FOLDER, $folderId); | 535 | + |
| 536 | + return CMISUtil::encodeObjectId($type, $objectId); | ||
| 519 | } | 537 | } |
| 520 | - | 538 | + |
| 521 | static public function getCmisObjectProperties(&$xml) | 539 | static public function getCmisObjectProperties(&$xml) |
| 522 | { | 540 | { |
| 523 | $xmlReader = new XMLReader(); | 541 | $xmlReader = new XMLReader(); |
| @@ -551,10 +569,10 @@ class KT_cmis_atom_service_helper { | @@ -551,10 +569,10 @@ class KT_cmis_atom_service_helper { | ||
| 551 | } | 569 | } |
| 552 | } | 570 | } |
| 553 | } | 571 | } |
| 554 | - | 572 | + |
| 555 | return $cmisObjectPropertiesCollection; | 573 | return $cmisObjectPropertiesCollection; |
| 556 | } | 574 | } |
| 557 | - | 575 | + |
| 558 | static public function getCmisContent(&$xml) | 576 | static public function getCmisContent(&$xml) |
| 559 | { | 577 | { |
| 560 | $xmlReader = new XMLReader(); | 578 | $xmlReader = new XMLReader(); |
| @@ -577,14 +595,14 @@ class KT_cmis_atom_service_helper { | @@ -577,14 +595,14 @@ class KT_cmis_atom_service_helper { | ||
| 577 | $cmisObjectContent[$cmisContentProperty] = $xmlReader->value; | 595 | $cmisObjectContent[$cmisContentProperty] = $xmlReader->value; |
| 578 | } | 596 | } |
| 579 | } | 597 | } |
| 580 | - | 598 | + |
| 581 | return $cmisObjectContent; | 599 | return $cmisObjectContent; |
| 582 | } | 600 | } |
| 583 | - | 601 | + |
| 584 | static public function getAtomValues(&$xml, $tag) | 602 | static public function getAtomValues(&$xml, $tag) |
| 585 | { | 603 | { |
| 586 | $returnTag = null; | 604 | $returnTag = null; |
| 587 | - | 605 | + |
| 588 | $xmlReader = new XMLReader(); | 606 | $xmlReader = new XMLReader(); |
| 589 | $xmlReader->XML($xml); | 607 | $xmlReader->XML($xml); |
| 590 | $foundTag = false; | 608 | $foundTag = false; |
| @@ -603,14 +621,14 @@ class KT_cmis_atom_service_helper { | @@ -603,14 +621,14 @@ class KT_cmis_atom_service_helper { | ||
| 603 | } | 621 | } |
| 604 | } | 622 | } |
| 605 | } | 623 | } |
| 606 | - | 624 | + |
| 607 | return $returnTag; | 625 | return $returnTag; |
| 608 | } | 626 | } |
| 609 | 627 | ||
| 610 | static public function getCmisPropertiesOld($xmlArray) | 628 | static public function getCmisPropertiesOld($xmlArray) |
| 611 | { | 629 | { |
| 612 | $properties = array(); | 630 | $properties = array(); |
| 613 | - | 631 | + |
| 614 | // find cmisra:object tag | 632 | // find cmisra:object tag |
| 615 | $baseCmisObject = KT_cmis_atom_service_helper::findTag('cmisra:object', $xmlArray, null, false); | 633 | $baseCmisObject = KT_cmis_atom_service_helper::findTag('cmisra:object', $xmlArray, null, false); |
| 616 | if(count($baseCmisObject) <= 0) | 634 | if(count($baseCmisObject) <= 0) |
| @@ -618,7 +636,7 @@ class KT_cmis_atom_service_helper { | @@ -618,7 +636,7 @@ class KT_cmis_atom_service_helper { | ||
| 618 | $entryObject = KT_cmis_atom_service_helper::findTag('entry', $xmlArray, null, false); | 636 | $entryObject = KT_cmis_atom_service_helper::findTag('entry', $xmlArray, null, false); |
| 619 | $baseCmisObject = KT_cmis_atom_service_helper::findTag('cmisra:object', $entryObject['@children'], null, true); | 637 | $baseCmisObject = KT_cmis_atom_service_helper::findTag('cmisra:object', $entryObject['@children'], null, true); |
| 620 | } | 638 | } |
| 621 | - | 639 | + |
| 622 | if(count($baseCmisObject) > 0) | 640 | if(count($baseCmisObject) > 0) |
| 623 | { | 641 | { |
| 624 | foreach($baseCmisObject[0]['@children'] as $key => $childElement) | 642 | foreach($baseCmisObject[0]['@children'] as $key => $childElement) |
| @@ -629,8 +647,8 @@ class KT_cmis_atom_service_helper { | @@ -629,8 +647,8 @@ class KT_cmis_atom_service_helper { | ||
| 629 | { | 647 | { |
| 630 | foreach($cmisPropertyDefinition as $propertyType => $propertyDefinition) | 648 | foreach($cmisPropertyDefinition as $propertyType => $propertyDefinition) |
| 631 | { | 649 | { |
| 632 | - $properties[$propertyDefinition['@attributes']['cmis:name']] | ||
| 633 | - = $propertyDefinition['@children']['cmis:value'][0]['@value']; | 650 | + $properties[$propertyDefinition['@attributes']['cmis:name']] |
| 651 | + = $propertyDefinition['@children']['cmis:value'][0]['@value']; | ||
| 634 | } | 652 | } |
| 635 | } | 653 | } |
| 636 | } | 654 | } |
| @@ -643,9 +661,9 @@ class KT_cmis_atom_service_helper { | @@ -643,9 +661,9 @@ class KT_cmis_atom_service_helper { | ||
| 643 | static public function getAtomValuesOld($xmlArray, $tag) | 661 | static public function getAtomValuesOld($xmlArray, $tag) |
| 644 | { | 662 | { |
| 645 | if (!is_null($xmlArray['atom:'.$tag])) | 663 | if (!is_null($xmlArray['atom:'.$tag])) |
| 646 | - return $xmlArray['atom:'.$tag][0]['@value']; | 664 | + return $xmlArray['atom:'.$tag][0]['@value']; |
| 647 | else if (!is_null($xmlArray[$tag])) | 665 | else if (!is_null($xmlArray[$tag])) |
| 648 | - return $xmlArray[$tag][0]['@value']; | 666 | + return $xmlArray[$tag][0]['@value']; |
| 649 | 667 | ||
| 650 | return null; | 668 | return null; |
| 651 | } | 669 | } |
| @@ -655,23 +673,23 @@ class KT_cmis_atom_service_helper { | @@ -655,23 +673,23 @@ class KT_cmis_atom_service_helper { | ||
| 655 | * | 673 | * |
| 656 | * @return object | 674 | * @return object |
| 657 | */ | 675 | */ |
| 658 | - public static function getKt() | 676 | + public static function getKt() |
| 659 | { | 677 | { |
| 660 | - if(!isset(self::$ktapi)) | 678 | + if(!isset(self::$ktapi)) |
| 661 | { | 679 | { |
| 662 | - self::$ktapi = new KTAPI(); | ||
| 663 | - $active = self::$ktapi->get_active_session(session_id()); | ||
| 664 | - | ||
| 665 | - if (PEAR::isError($active)) | ||
| 666 | - { | ||
| 667 | - // invoke auth code, session must be restarted | ||
| 668 | - if(!KT_atom_HTTPauth::isLoggedIn()) { | ||
| 669 | - KT_atom_HTTPauth::login('KnowledgeTree DMS', 'You must authenticate to enter this realm'); | ||
| 670 | - } | ||
| 671 | - } | ||
| 672 | - } | ||
| 673 | - return self::$ktapi; | ||
| 674 | - } | 680 | + self::$ktapi = new KTAPI(); |
| 681 | + $active = self::$ktapi->get_active_session(session_id()); | ||
| 682 | + | ||
| 683 | + if (PEAR::isError($active)) | ||
| 684 | + { | ||
| 685 | + // invoke auth code, session must be restarted | ||
| 686 | + if(!KT_atom_HTTPauth::isLoggedIn()) { | ||
| 687 | + KT_atom_HTTPauth::login('KnowledgeTree DMS', 'You must authenticate to enter this realm'); | ||
| 688 | + } | ||
| 689 | + } | ||
| 690 | + } | ||
| 691 | + return self::$ktapi; | ||
| 692 | + } | ||
| 675 | 693 | ||
| 676 | // TODO adjust for time zones? | 694 | // TODO adjust for time zones? |
| 677 | static public function formatDatestamp($time = null) | 695 | static public function formatDatestamp($time = null) |
| @@ -679,7 +697,7 @@ class KT_cmis_atom_service_helper { | @@ -679,7 +697,7 @@ class KT_cmis_atom_service_helper { | ||
| 679 | if (is_null($time)) $time = time(); | 697 | if (is_null($time)) $time = time(); |
| 680 | return date('Y-m-d H:i:s', $time); | 698 | return date('Y-m-d H:i:s', $time); |
| 681 | } | 699 | } |
| 682 | - | 700 | + |
| 683 | /** | 701 | /** |
| 684 | * Fetches the document content stream for internal use | 702 | * Fetches the document content stream for internal use |
| 685 | * | 703 | * |
| @@ -693,12 +711,12 @@ class KT_cmis_atom_service_helper { | @@ -693,12 +711,12 @@ class KT_cmis_atom_service_helper { | ||
| 693 | if ($response['status_code'] == 1) { | 711 | if ($response['status_code'] == 1) { |
| 694 | return null; | 712 | return null; |
| 695 | } | 713 | } |
| 696 | - | 714 | + |
| 697 | $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); | 715 | $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); |
| 698 | - | 716 | + |
| 699 | // hack for removing one level of access | 717 | // hack for removing one level of access |
| 700 | $contentStream = $contentStream['results']; | 718 | $contentStream = $contentStream['results']; |
| 701 | - | 719 | + |
| 702 | return $contentStream; | 720 | return $contentStream; |
| 703 | } | 721 | } |
| 704 | /** | 722 | /** |
| @@ -719,41 +737,41 @@ class KT_cmis_atom_service_helper { | @@ -719,41 +737,41 @@ class KT_cmis_atom_service_helper { | ||
| 719 | else { | 737 | else { |
| 720 | $response = $response['results']; | 738 | $response = $response['results']; |
| 721 | } | 739 | } |
| 722 | - | 740 | + |
| 723 | // TODO also check If-Modified-Since? | 741 | // TODO also check If-Modified-Since? |
| 724 | -// $service->headers['If-Modified-Since'] => 2009-07-24 17:16:54 | 742 | + // $service->headers['If-Modified-Since'] => 2009-07-24 17:16:54 |
| 725 | 743 | ||
| 726 | $service->setContentDownload(true); | 744 | $service->setContentDownload(true); |
| 727 | $eTag = md5($response['properties']['lastModificationDate']['value'] . $response['properties']['contentStreamLength']['value']); | 745 | $eTag = md5($response['properties']['lastModificationDate']['value'] . $response['properties']['contentStreamLength']['value']); |
| 728 | - | 746 | + |
| 729 | if ($service->headers['If-None-Match'] == $eTag) | 747 | if ($service->headers['If-None-Match'] == $eTag) |
| 730 | { | 748 | { |
| 731 | $service->setStatus(KT_cmis_atom_service::STATUS_NOT_MODIFIED); | 749 | $service->setStatus(KT_cmis_atom_service::STATUS_NOT_MODIFIED); |
| 732 | $service->setContentDownload(false); | 750 | $service->setContentDownload(false); |
| 733 | return null; | 751 | return null; |
| 734 | } | 752 | } |
| 735 | - | 753 | + |
| 736 | $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); | 754 | $contentStream = $ObjectService->getContentStream($repositoryId, $service->params[0]); |
| 737 | - | 755 | + |
| 738 | // hack for removing one level of access | 756 | // hack for removing one level of access |
| 739 | $contentStream = $contentStream['results']; | 757 | $contentStream = $contentStream['results']; |
| 740 | - | 758 | + |
| 741 | // headers specific to output | 759 | // headers specific to output |
| 742 | $service->setEtag($eTag); | 760 | $service->setEtag($eTag); |
| 743 | $service->setHeader('Last-Modified', $response['properties']['lastModificationDate']['value']); | 761 | $service->setHeader('Last-Modified', $response['properties']['lastModificationDate']['value']); |
| 744 | 762 | ||
| 745 | if (!empty($response['properties']['contentStreamMimeType']['value'])) { | 763 | if (!empty($response['properties']['contentStreamMimeType']['value'])) { |
| 746 | - $service->setHeader('Content-type', $response['properties']['contentStreamMimeType']['value'] . ';charset=utf-8'); | 764 | + $service->setHeader('Content-type', $response['properties']['contentStreamMimeType']['value'] . ';charset=utf-8'); |
| 747 | } | 765 | } |
| 748 | else { | 766 | else { |
| 749 | - $service->setHeader('Content-type', 'text/plain;charset=utf-8'); | 767 | + $service->setHeader('Content-type', 'text/plain;charset=utf-8'); |
| 750 | } | 768 | } |
| 751 | - | 769 | + |
| 752 | $service->setHeader('Content-Disposition', 'attachment;filename="' . $response['properties']['contentStreamFilename']['value'] . '"'); | 770 | $service->setHeader('Content-Disposition', 'attachment;filename="' . $response['properties']['contentStreamFilename']['value'] . '"'); |
| 753 | - $service->setHeader('Content-Length', $response['properties']['contentStreamLength']['value']); | 771 | + $service->setHeader('Content-Length', $response['properties']['contentStreamLength']['value']); |
| 754 | $service->setOutput($contentStream); | 772 | $service->setOutput($contentStream); |
| 755 | } | 773 | } |
| 756 | - | 774 | + |
| 757 | //TODO: Add key information to be able to find the same tag in the original struct (MarkH) | 775 | //TODO: Add key information to be able to find the same tag in the original struct (MarkH) |
| 758 | static public function findTag($tagName=NULL,$xml=array(),$tagArray=NULL,$deep=false) | 776 | static public function findTag($tagName=NULL,$xml=array(),$tagArray=NULL,$deep=false) |
| 759 | { | 777 | { |
| @@ -773,11 +791,11 @@ class KT_cmis_atom_service_helper { | @@ -773,11 +791,11 @@ class KT_cmis_atom_service_helper { | ||
| 773 | //TODO: this is very ugly. Change it. (MarkH) | 791 | //TODO: this is very ugly. Change it. (MarkH) |
| 774 | return self::rebaseArray($tagArray); | 792 | return self::rebaseArray($tagArray); |
| 775 | } | 793 | } |
| 776 | - | 794 | + |
| 777 | static public function rebaseArray($arr=array()){ | 795 | static public function rebaseArray($arr=array()){ |
| 778 | //Force Array | 796 | //Force Array |
| 779 | $arr=is_array($arr)?$arr:array(); | 797 | $arr=is_array($arr)?$arr:array(); |
| 780 | - | 798 | + |
| 781 | //Rebase recursively | 799 | //Rebase recursively |
| 782 | if(count($arr)===1)$arr=self::rebaseArray($arr[0]); | 800 | if(count($arr)===1)$arr=self::rebaseArray($arr[0]); |
| 783 | return $arr; | 801 | return $arr; |
webservice/atompub/cmis/index.php
| @@ -115,6 +115,9 @@ if ($workspace != 'servicedocument') | @@ -115,6 +115,9 @@ if ($workspace != 'servicedocument') | ||
| 115 | $APP->registerService('dms', 'type', 'KT_cmis_atom_service_type', 'Object Type Entry', null, 'type'); | 115 | $APP->registerService('dms', 'type', 'KT_cmis_atom_service_type', 'Object Type Entry', null, 'type'); |
| 116 | $APP->registerService('dms', 'document', 'KT_cmis_atom_service_document', 'Document Entry', null, 'document'); | 116 | $APP->registerService('dms', 'document', 'KT_cmis_atom_service_document', 'Document Entry', null, 'document'); |
| 117 | $APP->registerService('dms', 'pwc', 'KT_cmis_atom_service_pwc', 'Private Working Copy', null, 'pwc'); | 117 | $APP->registerService('dms', 'pwc', 'KT_cmis_atom_service_pwc', 'Private Working Copy', null, 'pwc'); |
| 118 | + $APP->registerService('dms', 'objectbyid', 'KT_cmis_atom_service_objectbyid', 'Object By Id', null, 'objectbyid'); | ||
| 119 | + $APP->registerService('dms', 'objectbypath', 'KT_cmis_atom_service_objectbypath', 'Object By Path', null, 'objectbypath'); | ||
| 120 | + $APP->registerService('dms', 'typebyid', 'KT_cmis_atom_service_type', 'Type By Id', null, 'typebyid'); | ||
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | //Execute the current url/header request | 123 | //Execute the current url/header request |
webservice/classes/atompub/cmis/KT_cmis_atom_server.inc.php
| @@ -69,21 +69,18 @@ class KT_cmis_atom_server extends KT_atom_server { | @@ -69,21 +69,18 @@ class KT_cmis_atom_server extends KT_atom_server { | ||
| 69 | //Creating the Default Workspace for use with standard atomPub Clients | 69 | //Creating the Default Workspace for use with standard atomPub Clients |
| 70 | $ws = $service->newWorkspace(); | 70 | $ws = $service->newWorkspace(); |
| 71 | 71 | ||
| 72 | - $hadDetail=false; | ||
| 73 | - if(isset($this->workspaceDetail[$workspace])) | ||
| 74 | - { | ||
| 75 | - if(is_array($this->workspaceDetail[$workspace])) | ||
| 76 | - { | ||
| 77 | - foreach ($this->workspaceDetail[$workspace] as $wsTag=>$wsValue) | ||
| 78 | - { | ||
| 79 | - $ws->appendChild($service->newElement($wsTag,$wsValue)); | 72 | + $hadDetail = false; |
| 73 | + if(isset($this->workspaceDetail[$workspace])) { | ||
| 74 | + if(is_array($this->workspaceDetail[$workspace])) { | ||
| 75 | + foreach ($this->workspaceDetail[$workspace] as $wsTag => $wsValue){ | ||
| 76 | + $ws->appendChild($service->newElement($wsTag, $wsValue)); | ||
| 80 | $hadDetail=true; | 77 | $hadDetail=true; |
| 81 | } | 78 | } |
| 82 | } | 79 | } |
| 83 | } | 80 | } |
| 84 | 81 | ||
| 85 | if(!$hadDetail) { | 82 | if(!$hadDetail) { |
| 86 | - $ws->appendChild($service->newElement('atom:title',$workspace)); | 83 | + $ws->appendChild($service->newElement('atom:title', $workspace)); |
| 87 | } | 84 | } |
| 88 | 85 | ||
| 89 | $ws->appendChild($service->newAttr('cmis:repositoryRelationship', $this->repositoryInfo['repositoryRelationship'])); | 86 | $ws->appendChild($service->newAttr('cmis:repositoryRelationship', $this->repositoryInfo['repositoryRelationship'])); |
| @@ -99,11 +96,9 @@ class KT_cmis_atom_server extends KT_atom_server { | @@ -99,11 +96,9 @@ class KT_cmis_atom_server extends KT_atom_server { | ||
| 99 | if (!is_array($repoData)) { | 96 | if (!is_array($repoData)) { |
| 100 | $element->appendChild($service->newElement('cmis:' . $key, $repoData)); | 97 | $element->appendChild($service->newElement('cmis:' . $key, $repoData)); |
| 101 | } | 98 | } |
| 102 | - else | ||
| 103 | - { | 99 | + else { |
| 104 | $elementSub = $service->newElement('cmis:' . $key); | 100 | $elementSub = $service->newElement('cmis:' . $key); |
| 105 | - foreach($repoData as $key2 => $data) | ||
| 106 | - { | 101 | + foreach($repoData as $key2 => $data) { |
| 107 | $elementSub->appendChild($service->newElement('cmis:' . $key2, CMISUtil::boolToString($data))); | 102 | $elementSub->appendChild($service->newElement('cmis:' . $key2, CMISUtil::boolToString($data))); |
| 108 | } | 103 | } |
| 109 | $element->appendChild($elementSub); | 104 | $element->appendChild($elementSub); |
| @@ -111,21 +106,24 @@ class KT_cmis_atom_server extends KT_atom_server { | @@ -111,21 +106,24 @@ class KT_cmis_atom_server extends KT_atom_server { | ||
| 111 | } | 106 | } |
| 112 | $ws->appendChild($element); | 107 | $ws->appendChild($element); |
| 113 | 108 | ||
| 109 | + // collections | ||
| 110 | + // TODO check collectionType usage against spec | ||
| 114 | foreach($collection as $serviceName => $serviceInstance) | 111 | foreach($collection as $serviceName => $serviceInstance) |
| 115 | { | 112 | { |
| 116 | foreach($serviceInstance as $instance) | 113 | foreach($serviceInstance as $instance) |
| 117 | { | 114 | { |
| 118 | $collectionStr = CMIS_APP_BASE_URI . $workspace . '/' . $serviceName . '/' | 115 | $collectionStr = CMIS_APP_BASE_URI . $workspace . '/' . $serviceName . '/' |
| 119 | . (is_array($instance['parameters']) ? implode('/', $instance['parameters']).'/' : ''); | 116 | . (is_array($instance['parameters']) ? implode('/', $instance['parameters']).'/' : ''); |
| 117 | + // FIXME? do we need to return the value from the function? | ||
| 120 | $col = $service->newCollection($collectionStr, $instance['title'], $instance['collectionType'], $instance['accept'], $ws); | 118 | $col = $service->newCollection($collectionStr, $instance['title'], $instance['collectionType'], $instance['accept'], $ws); |
| 121 | } | 119 | } |
| 122 | } | 120 | } |
| 121 | + | ||
| 122 | + // uri templates - getObjectById, getObjectByPath, getTypeById | ||
| 123 | + $ws->appendChild($service->uriTemplate('objectbyid', $workspace)); | ||
| 124 | + $ws->appendChild($service->uriTemplate('objectbypath', $workspace)); | ||
| 125 | + $ws->appendChild($service->uriTemplate('typebyid', $workspace)); | ||
| 123 | } | 126 | } |
| 124 | - | ||
| 125 | -// ob_start(); | ||
| 126 | -// readfile('C:\Users\Paul\Documents\Downloads\cmis_mod_kt.xml'); | ||
| 127 | -// $this->output = ob_get_contents(); | ||
| 128 | -// ob_end_clean(); | ||
| 129 | 127 | ||
| 130 | $this->output = $service->getAPPdoc(); | 128 | $this->output = $service->getAPPdoc(); |
| 131 | } | 129 | } |
webservice/classes/atompub/cmis/KT_cmis_atom_serviceDoc.inc.php
| @@ -83,7 +83,7 @@ class KT_cmis_atom_serviceDoc extends KT_atom_serviceDoc { | @@ -83,7 +83,7 @@ class KT_cmis_atom_serviceDoc extends KT_atom_serviceDoc { | ||
| 83 | $this->DOM->appendChild($this->service); | 83 | $this->DOM->appendChild($this->service); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | - public function &newCollection($url = NULL, $title = NULL, $cmisCollectionType = NULL, $accept = null, &$ws = NULL) | 86 | + public function newCollection($url = NULL, $title = NULL, $cmisCollectionType = NULL, $accept = null, &$ws = NULL) |
| 87 | { | 87 | { |
| 88 | $collection=$this->newElement('collection'); | 88 | $collection=$this->newElement('collection'); |
| 89 | $collection->appendChild($this->newAttr('href', $url)); | 89 | $collection->appendChild($this->newAttr('href', $url)); |
| @@ -93,8 +93,45 @@ class KT_cmis_atom_serviceDoc extends KT_atom_serviceDoc { | @@ -93,8 +93,45 @@ class KT_cmis_atom_serviceDoc extends KT_atom_serviceDoc { | ||
| 93 | $collection->appendChild($this->newElement('accept', $accept)); | 93 | $collection->appendChild($this->newElement('accept', $accept)); |
| 94 | } | 94 | } |
| 95 | if(isset($ws))$ws->appendChild($collection); | 95 | if(isset($ws))$ws->appendChild($collection); |
| 96 | + | ||
| 97 | + // FIXME? do we need to return the value from the function if $ws is supplied? | ||
| 96 | return $collection; | 98 | return $collection; |
| 97 | } | 99 | } |
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Creates the specified URI template within the AtomPub response | ||
| 103 | + * | ||
| 104 | + * @param string $templateType | ||
| 105 | + * @param string $workspace | ||
| 106 | + * @return string $uriTemplate | ||
| 107 | + * | ||
| 108 | + * NOTE not adding in all the arguments for optional functionality not supported, e.g. ACL/Policies/Relationships/Renditions; | ||
| 109 | + * arguments for functionality which is non-optional (filters/allowableActions) are included but not yet supported | ||
| 110 | + * by the API code | ||
| 111 | + */ | ||
| 112 | + public function uriTemplate($templateType, $workspace) | ||
| 113 | + { | ||
| 114 | + $content = array('template' => CMIS_APP_BASE_URI . $workspace, 'mediatype' => 'application/atom+xml;type=entry'); | ||
| 115 | + | ||
| 116 | + switch($templateType) { | ||
| 117 | + case 'objectbyid': | ||
| 118 | + $content['template'] .= '/objectbyid/{id}/{filter}/{includeAllowableActions}'; | ||
| 119 | + break; | ||
| 120 | + case 'objectbypath': | ||
| 121 | + $content['template'] .= '/objectbypath/{path}/{filter}/{includeAllowableActions}'; | ||
| 122 | + break; | ||
| 123 | + case 'typebyid': | ||
| 124 | + $content['template'] .= '/typebyid/{id}'; | ||
| 125 | + break; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + $uriTemplate = $this->newElement('cmisra:uritemplate'); | ||
| 129 | + $uriTemplate->appendChild($this->newElement('cmisra:template', $content['template'])); | ||
| 130 | + $uriTemplate->appendChild($this->newElement('cmisra:type', $content)); | ||
| 131 | + $uriTemplate->appendChild($this->newElement('cmisra:mediatype', $content['mediatype'])); | ||
| 132 | + | ||
| 133 | + return $uriTemplate; | ||
| 134 | + } | ||
| 98 | 135 | ||
| 99 | } | 136 | } |
| 100 | 137 |