Commit fdfa82fa610c5213f74d8204b75649af595a8210
1 parent
37797d9a
Separated KnowledgeTree CMIS API interface classes into separate files instead o…
…f a single file for all 4 classes plus base class Committed by: Paul Barrett
Showing
12 changed files
with
1126 additions
and
905 deletions
lib/api/ktcmis/ktNavigationService.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Navigation Service CMIS wrapper API for KnowledgeTree. | |
| 4 | +* | |
| 5 | +* KnowledgeTree Community Edition | |
| 6 | +* Document Management Made Simple | |
| 7 | +* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | +* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | +* | |
| 10 | +* This program is free software; you can redistribute it and/or modify it under | |
| 11 | +* the terms of the GNU General Public License version 3 as published by the | |
| 12 | +* Free Software Foundation. | |
| 13 | +* | |
| 14 | +* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | +* details. | |
| 18 | +* | |
| 19 | +* You should have received a copy of the GNU General Public License | |
| 20 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | +* | |
| 22 | +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | +* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | +* | |
| 25 | +* The interactive user interfaces in modified source and object code versions | |
| 26 | +* of this program must display Appropriate Legal Notices, as required under | |
| 27 | +* Section 5 of the GNU General Public License version 3. | |
| 28 | +* | |
| 29 | +* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | +* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | +* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | +* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | +* copyright notice. | |
| 35 | +* | |
| 36 | +* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | +* @license GNU General Public License version 3 | |
| 38 | +* @author KnowledgeTree Team | |
| 39 | +* @package KTCMIS | |
| 40 | +* @version Version 0.9 | |
| 41 | +*/ | |
| 42 | + | |
| 43 | +require_once(realpath(dirname(__FILE__) . '/ktService.inc.php')); | |
| 44 | +require_once(CMIS_DIR . '/services/CMISNavigationService.inc.php'); | |
| 45 | + | |
| 46 | +/* | |
| 47 | + * Handles repository navigation | |
| 48 | + */ | |
| 49 | +class KTNavigationService extends KTCMISBase { | |
| 50 | + | |
| 51 | + protected $NavigationService; | |
| 52 | + | |
| 53 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 54 | + { | |
| 55 | + parent::__construct($ktapi, $username, $password); | |
| 56 | + // instantiate underlying CMIS service | |
| 57 | + $this->NavigationService = new CMISNavigationService(); | |
| 58 | + $this->setInterface(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function startSession($username, $password) | |
| 62 | + { | |
| 63 | + parent::startSession($username, $password); | |
| 64 | + $this->setInterface(); | |
| 65 | + return self::$session; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public function setInterface(&$ktapi = null) | |
| 69 | + { | |
| 70 | + parent::setInterface($ktapi); | |
| 71 | + $this->NavigationService->setInterface(self::$ktapi); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Get descendents of the specified folder, up to the depth indicated | |
| 76 | + * | |
| 77 | + * @param string $repositoryId | |
| 78 | + * @param string $folderId | |
| 79 | + * @param boolean $includeAllowableActions | |
| 80 | + * @param boolean $includeRelationships | |
| 81 | + * @param string $typeID | |
| 82 | + * @param int $depth | |
| 83 | + * @param string $filter | |
| 84 | + * @return array $descendants | |
| 85 | + */ | |
| 86 | + public function getDescendants($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, | |
| 87 | + $depth = 1, $typeID = 'Any', $filter = '') | |
| 88 | + { | |
| 89 | + // TODO optional parameters | |
| 90 | + $descendantsResult = $this->NavigationService->getDescendants($repositoryId, $folderId, $includeAllowableActions, | |
| 91 | + $includeRelationships, $depth); | |
| 92 | + | |
| 93 | + if (PEAR::isError($descendantsResult)) | |
| 94 | + { | |
| 95 | + return array( | |
| 96 | + "status_code" => 1, | |
| 97 | + "message" => "Failed getting descendants for folder" | |
| 98 | + ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + // format for webservices consumption | |
| 102 | + // NOTE this will almost definitely be changing in the future, this is just to get something working | |
| 103 | + $descendants = CMISUtil::decodeObjectHierarchy($descendantsResult, 'child'); | |
| 104 | + | |
| 105 | + return array ( | |
| 106 | + "status_code" => 0, | |
| 107 | + "results" => $descendants | |
| 108 | + ); | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * Get direct children of the specified folder | |
| 113 | + * | |
| 114 | + * @param string $repositoryId | |
| 115 | + * @param string $folderId | |
| 116 | + * @param boolean $includeAllowableActions | |
| 117 | + * @param boolean $includeRelationships | |
| 118 | + * @param string $typeID | |
| 119 | + * @param string $filter | |
| 120 | + * @param int $maxItems | |
| 121 | + * @param int $skipCount | |
| 122 | + * @return array $descendants | |
| 123 | + */ | |
| 124 | + public function getChildren($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, | |
| 125 | + $typeID = 'Any', $filter = '', $maxItems = 0, $skipCount = 0) | |
| 126 | + { | |
| 127 | + // TODO paging | |
| 128 | + // TODO optional parameters | |
| 129 | + $childrenResult = $this->NavigationService->getChildren($repositoryId, $folderId, $includeAllowableActions, $includeRelationships); | |
| 130 | + | |
| 131 | + if (PEAR::isError($childrenResult)) | |
| 132 | + { | |
| 133 | + return array( | |
| 134 | + "status_code" => 1, | |
| 135 | + "message" => "Failed getting descendants for folder" | |
| 136 | + ); | |
| 137 | + } | |
| 138 | + | |
| 139 | + $children = CMISUtil::decodeObjectHierarchy($childrenResult, 'child'); | |
| 140 | + | |
| 141 | + return array( | |
| 142 | + "status_code" => 0, | |
| 143 | + "results" => $children | |
| 144 | + ); | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Gets the parent of the selected folder | |
| 149 | + * | |
| 150 | + * @param string $repositoryId | |
| 151 | + * @param string $folderId | |
| 152 | + * @param boolean $includeAllowableActions | |
| 153 | + * @param boolean $includeRelationships | |
| 154 | + * @param boolean $returnToRoot | |
| 155 | + * @param string $filter | |
| 156 | + * @return ancestry[] | |
| 157 | + */ | |
| 158 | + public function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') | |
| 159 | + { | |
| 160 | + $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, | |
| 161 | + $includeRelationships, $returnToRoot); | |
| 162 | + | |
| 163 | + if (PEAR::isError($ancestryResult)) | |
| 164 | + { | |
| 165 | + return array( | |
| 166 | + "status_code" => 1, | |
| 167 | + "message" => "Failed getting ancestry for folder" | |
| 168 | + ); | |
| 169 | + } | |
| 170 | + | |
| 171 | + $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'child'); | |
| 172 | + | |
| 173 | + return array( | |
| 174 | + "status_code" => 0, | |
| 175 | + "results" => $ancestry | |
| 176 | + ); | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * Gets the parents for the selected object | |
| 181 | + * | |
| 182 | + * @param string $repositoryId | |
| 183 | + * @param string $folderId | |
| 184 | + * @param boolean $includeAllowableActions | |
| 185 | + * @param boolean $includeRelationships | |
| 186 | + * @param string $filter | |
| 187 | + * @return ancestry[] | |
| 188 | + */ | |
| 189 | + function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') | |
| 190 | + { | |
| 191 | + $ancestryResult = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions, | |
| 192 | + $includeRelationships); | |
| 193 | + | |
| 194 | + if (PEAR::isError($ancestryResult)) | |
| 195 | + { | |
| 196 | + return array( | |
| 197 | + "status_code" => 1, | |
| 198 | + "message" => "Failed getting ancestry for object" | |
| 199 | + ); | |
| 200 | + } | |
| 201 | + | |
| 202 | + $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'child'); | |
| 203 | + | |
| 204 | + return array( | |
| 205 | + "status_code" => 0, | |
| 206 | + "results" => $ancestry | |
| 207 | + ); | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * Returns a list of checked out documents from the selected repository | |
| 212 | + * | |
| 213 | + * @param string $repositoryId | |
| 214 | + * @param string $folderId The folder for which checked out docs are requested | |
| 215 | + * @param string $filter | |
| 216 | + * @param boolean $includeAllowableActions | |
| 217 | + * @param boolean $includeRelationships | |
| 218 | + * @param int $maxItems | |
| 219 | + * @param int $skipCount | |
| 220 | + * @return array $checkedout The collection of checked out documents | |
| 221 | + */ | |
| 222 | + function getCheckedOutDocs($repositoryId, $includeAllowableActions, $includeRelationships, $folderId = null, $filter = '', | |
| 223 | + $maxItems = 0, $skipCount = 0) | |
| 224 | + { | |
| 225 | + $checkedout = $this->NavigationService->getCheckedOutDocs($repositoryId, $includeAllowableActions, $includeRelationships, | |
| 226 | + $folderId, $filter, $maxItems, $skipCount); | |
| 227 | + | |
| 228 | + if (PEAR::isError($checkedout)) | |
| 229 | + { | |
| 230 | + return array( | |
| 231 | + "status_code" => 1, | |
| 232 | + "message" => "Failed getting list of checked out documents" | |
| 233 | + ); | |
| 234 | + } | |
| 235 | + | |
| 236 | + // convert to array format for external code | |
| 237 | + $co = array(); | |
| 238 | + foreach ($checkedout as $documentProperties) | |
| 239 | + { | |
| 240 | + $co[] = CMISUtil::createObjectPropertiesEntry($documentProperties);; | |
| 241 | + } | |
| 242 | + | |
| 243 | + return array( | |
| 244 | + "status_code" => 0, | |
| 245 | + "results" => $co | |
| 246 | + ); | |
| 247 | + } | |
| 248 | + | |
| 249 | +} | |
| 250 | + | |
| 251 | +?> | |
| 0 | 252 | \ No newline at end of file | ... | ... |
lib/api/ktcmis/ktObjectService.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Object Service CMIS wrapper API for KnowledgeTree. | |
| 4 | +* | |
| 5 | +* KnowledgeTree Community Edition | |
| 6 | +* Document Management Made Simple | |
| 7 | +* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | +* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | +* | |
| 10 | +* This program is free software; you can redistribute it and/or modify it under | |
| 11 | +* the terms of the GNU General Public License version 3 as published by the | |
| 12 | +* Free Software Foundation. | |
| 13 | +* | |
| 14 | +* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | +* details. | |
| 18 | +* | |
| 19 | +* You should have received a copy of the GNU General Public License | |
| 20 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | +* | |
| 22 | +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | +* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | +* | |
| 25 | +* The interactive user interfaces in modified source and object code versions | |
| 26 | +* of this program must display Appropriate Legal Notices, as required under | |
| 27 | +* Section 5 of the GNU General Public License version 3. | |
| 28 | +* | |
| 29 | +* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | +* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | +* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | +* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | +* copyright notice. | |
| 35 | +* | |
| 36 | +* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | +* @license GNU General Public License version 3 | |
| 38 | +* @author KnowledgeTree Team | |
| 39 | +* @package KTCMIS | |
| 40 | +* @version Version 0.9 | |
| 41 | +*/ | |
| 42 | + | |
| 43 | +require_once(realpath(dirname(__FILE__) . '/ktService.inc.php')); | |
| 44 | +require_once(CMIS_DIR . '/services/CMISObjectService.inc.php'); | |
| 45 | + | |
| 46 | +/** | |
| 47 | + * Handles requests for and actions on Folders and Documents | |
| 48 | + */ | |
| 49 | +class KTObjectService extends KTCMISBase { | |
| 50 | + | |
| 51 | + protected $ObjectService; | |
| 52 | + | |
| 53 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 54 | + { | |
| 55 | + parent::__construct($ktapi, $username, $password); | |
| 56 | + // instantiate underlying CMIS service | |
| 57 | + $this->ObjectService = new CMISObjectService(); | |
| 58 | + $this->setInterface(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function startSession($username, $password) | |
| 62 | + { | |
| 63 | + parent::startSession($username, $password); | |
| 64 | + $this->setInterface(); | |
| 65 | + return self::$session; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public function setInterface(&$ktapi = null) | |
| 69 | + { | |
| 70 | + parent::setInterface($ktapi); | |
| 71 | + $this->ObjectService->setInterface(self::$ktapi); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Gets the properties for the selected object | |
| 76 | + * | |
| 77 | + * @param string $repositoryId | |
| 78 | + * @param string $objectId | |
| 79 | + * @param boolean $includeAllowableActions | |
| 80 | + * @param boolean $includeRelationships | |
| 81 | + * @param string $returnVersion | |
| 82 | + * @param string $filter | |
| 83 | + * @return properties[] | |
| 84 | + */ | |
| 85 | + public function getProperties($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, | |
| 86 | + $returnVersion = false, $filter = '') | |
| 87 | + { | |
| 88 | + try { | |
| 89 | + $propertyCollection = $this->ObjectService->getProperties($repositoryId, $objectId, $includeAllowableActions, | |
| 90 | + $includeRelationships); | |
| 91 | + } | |
| 92 | + catch (Exception $e) | |
| 93 | + { | |
| 94 | + return array( | |
| 95 | + "status_code" => 1, | |
| 96 | + "message" => $e->getMessage() | |
| 97 | + ); | |
| 98 | + } | |
| 99 | + | |
| 100 | + $properties = CMISUtil::createObjectPropertiesEntry($propertyCollection); | |
| 101 | + | |
| 102 | + return array( | |
| 103 | + "status_code" => 0, | |
| 104 | + "results" => $properties | |
| 105 | + ); | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Creates a new document within the repository | |
| 110 | + * | |
| 111 | + * @param string $repositoryId The repository to which the document must be added | |
| 112 | + * @param string $typeId Object Type id for the document object being created | |
| 113 | + * @param array $properties Array of properties which must be applied to the created document object | |
| 114 | + * @param string $folderId The id of the folder which will be the parent of the created document object | |
| 115 | + * This parameter is optional IF unfilingCapability is supported | |
| 116 | + * @param contentStream $contentStream optional content stream data | |
| 117 | + * @param string $versioningState optional version state value: checkedout/major/minor | |
| 118 | + * @return string $objectId The id of the created folder object | |
| 119 | + */ | |
| 120 | + public function createDocument($repositoryId, $typeId, $properties, $folderId = null, | |
| 121 | + $contentStream = null, $versioningState = null) | |
| 122 | + { | |
| 123 | + $objectId = null; | |
| 124 | + | |
| 125 | + try { | |
| 126 | + $objectId = $this->ObjectService->createDocument($repositoryId, $typeId, $properties, $folderId, | |
| 127 | + $contentStream, $versioningState); | |
| 128 | + } | |
| 129 | + catch (Exception $e) | |
| 130 | + { | |
| 131 | + return array( | |
| 132 | + "status_code" => 1, | |
| 133 | + "message" => $e->getMessage() | |
| 134 | + ); | |
| 135 | + } | |
| 136 | + | |
| 137 | + return array( | |
| 138 | + 'status_code' => 0, | |
| 139 | + 'results' => $objectId | |
| 140 | + ); | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Creates a new folder within the repository | |
| 145 | + * | |
| 146 | + * @param string $repositoryId The repository to which the folder must be added | |
| 147 | + * @param string $typeId Object Type id for the folder object being created | |
| 148 | + * @param array $properties Array of properties which must be applied to the created folder object | |
| 149 | + * @param string $folderId The id of the folder which will be the parent of the created folder object | |
| 150 | + * @return string $objectId The id of the created folder object | |
| 151 | + */ | |
| 152 | + public function createFolder($repositoryId, $typeId, $properties, $folderId) | |
| 153 | + { | |
| 154 | + $objectId = null; | |
| 155 | + | |
| 156 | + try { | |
| 157 | + $objectId = $this->ObjectService->createFolder($repositoryId, $typeId, $properties, $folderId); | |
| 158 | + } | |
| 159 | + catch (Exception $e) | |
| 160 | + { | |
| 161 | + return array( | |
| 162 | + "status_code" => 1, | |
| 163 | + "message" => $e->getMessage() | |
| 164 | + ); | |
| 165 | + } | |
| 166 | + | |
| 167 | + return array( | |
| 168 | + 'status_code' => 0, | |
| 169 | + 'results' => $objectId | |
| 170 | + ); | |
| 171 | + } | |
| 172 | + | |
| 173 | + /** | |
| 174 | + * Fetches the content stream data for an object | |
| 175 | + * | |
| 176 | + * @param string $repositoryId | |
| 177 | + * @param string $objectId | |
| 178 | + * @return string $contentStream (binary or text data) | |
| 179 | + */ | |
| 180 | + function getContentStream($repositoryId, $objectId) | |
| 181 | + { | |
| 182 | + try { | |
| 183 | + $contentStream = $this->ObjectService->getContentStream($repositoryId, $objectId); | |
| 184 | + } | |
| 185 | + catch (Exception $e) | |
| 186 | + { | |
| 187 | + return array( | |
| 188 | + "status_code" => 1, | |
| 189 | + "message" => $e->getMessage() | |
| 190 | + ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + return array( | |
| 194 | + 'status_code' => 0, | |
| 195 | + 'results' => $contentStream | |
| 196 | + ); | |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * Moves a fileable object from one folder to another. | |
| 201 | + * | |
| 202 | + * @param object $repositoryId | |
| 203 | + * @param object $objectId | |
| 204 | + * @param object $changeToken [optional] | |
| 205 | + * @param object $targetFolderId | |
| 206 | + * @param object $sourceFolderId [optional] | |
| 207 | + */ | |
| 208 | + public function moveObject($repositoryId, $objectId, $changeToken = '', $targetFolderId, $sourceFolderId = null) | |
| 209 | + { | |
| 210 | + try { | |
| 211 | + $this->ObjectService->moveObject($repositoryId, $objectId, $changeToken, $targetFolderId, $sourceFolderId); | |
| 212 | + } | |
| 213 | + catch (Exception $e) | |
| 214 | + { | |
| 215 | + return array( | |
| 216 | + "status_code" => 1, | |
| 217 | + "message" => $e->getMessage() | |
| 218 | + ); | |
| 219 | + } | |
| 220 | + | |
| 221 | + return array( | |
| 222 | + 'status_code' => 0, | |
| 223 | + 'results' => $objectId | |
| 224 | + ); | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Deletes an object from the repository | |
| 229 | + * | |
| 230 | + * @param string $repositoryId | |
| 231 | + * @param string $objectId | |
| 232 | + * @param string $changeToken [optional] | |
| 233 | + * @return array | |
| 234 | + */ | |
| 235 | + // NOTE Invoking this service method on an object SHALL not delete the entire version series for a Document Object. | |
| 236 | + // To delete an entire version series, use the deleteAllVersions() service | |
| 237 | + public function deleteObject($repositoryId, $objectId, $changeToken = null) | |
| 238 | + { | |
| 239 | + try { | |
| 240 | + $this->ObjectService->deleteObject($repositoryId, $objectId, $changeToken); | |
| 241 | + } | |
| 242 | + catch (Exception $e) | |
| 243 | + { | |
| 244 | + return array( | |
| 245 | + "status_code" => 1, | |
| 246 | + "message" => $e->getMessage() | |
| 247 | + ); | |
| 248 | + } | |
| 249 | + | |
| 250 | + return array( | |
| 251 | + 'status_code' => 0, | |
| 252 | + 'results' => $objectId | |
| 253 | + ); | |
| 254 | + } | |
| 255 | + | |
| 256 | + public function deleteTree($repositoryId, $objectId, $changeToken = null, $unfileNonfolderObject = 'delete', $continueOnFailure = false) | |
| 257 | + { | |
| 258 | + try { | |
| 259 | + $result = $this->ObjectService->deleteTree($repositoryId, $objectId, $changeToken, $unfileNonfolderObject, $continueOnFailure); | |
| 260 | + } | |
| 261 | + catch (Exception $e) | |
| 262 | + { | |
| 263 | + return array( | |
| 264 | + "status_code" => 1, | |
| 265 | + "message" => $e->getMessage() | |
| 266 | + ); | |
| 267 | + } | |
| 268 | + | |
| 269 | + // check whether there is a list of items which did not delete | |
| 270 | + if (count($result) > 0) | |
| 271 | + { | |
| 272 | + return array( | |
| 273 | + "status_code" => 1, | |
| 274 | + "message" => $result | |
| 275 | + ); | |
| 276 | + } | |
| 277 | + | |
| 278 | + return array( | |
| 279 | + 'status_code' => 0, | |
| 280 | + 'results' => $objectId | |
| 281 | + ); | |
| 282 | + } | |
| 283 | + | |
| 284 | + /** | |
| 285 | + * Sets the content stream data for an existing document | |
| 286 | + * | |
| 287 | + * if $overwriteFlag = TRUE, the new content stream is applied whether or not the document has an existing content stream | |
| 288 | + * if $overwriteFlag = FALSE, the new content stream is applied only if the document does not have an existing content stream | |
| 289 | + * | |
| 290 | + * NOTE A Repository MAY automatically create new Document versions as part of this service method. | |
| 291 | + * Therefore, the documentId output NEED NOT be identical to the documentId input. | |
| 292 | + * | |
| 293 | + * @param string $repositoryId | |
| 294 | + * @param string $documentId | |
| 295 | + * @param boolean $overwriteFlag | |
| 296 | + * @param string $contentStream | |
| 297 | + * @param string $changeToken | |
| 298 | + * @return string $documentId | |
| 299 | + */ | |
| 300 | + function setContentStream($repositoryId, $documentId, $overwriteFlag, $contentStream, $changeToken = null) | |
| 301 | + { | |
| 302 | + try { | |
| 303 | + $documentId = $this->ObjectService->setContentStream($repositoryId, $documentId, $overwriteFlag, $contentStream, $changeToken); | |
| 304 | + } | |
| 305 | + catch (Exception $e) | |
| 306 | + { | |
| 307 | + return array( | |
| 308 | + "status_code" => 1, | |
| 309 | + "message" => $e->getMessage() | |
| 310 | + ); | |
| 311 | + } | |
| 312 | + | |
| 313 | + return array( | |
| 314 | + 'status_code' => 0, | |
| 315 | + 'results' => $documentId | |
| 316 | + ); | |
| 317 | + } | |
| 318 | + | |
| 319 | +} | |
| 320 | + | |
| 321 | +?> | |
| 0 | 322 | \ No newline at end of file | ... | ... |
lib/api/ktcmis/ktRepositoryService.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Repository Service CMIS wrapper API for KnowledgeTree. | |
| 4 | +* | |
| 5 | +* KnowledgeTree Community Edition | |
| 6 | +* Document Management Made Simple | |
| 7 | +* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | +* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | +* | |
| 10 | +* This program is free software; you can redistribute it and/or modify it under | |
| 11 | +* the terms of the GNU General Public License version 3 as published by the | |
| 12 | +* Free Software Foundation. | |
| 13 | +* | |
| 14 | +* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | +* details. | |
| 18 | +* | |
| 19 | +* You should have received a copy of the GNU General Public License | |
| 20 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | +* | |
| 22 | +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | +* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | +* | |
| 25 | +* The interactive user interfaces in modified source and object code versions | |
| 26 | +* of this program must display Appropriate Legal Notices, as required under | |
| 27 | +* Section 5 of the GNU General Public License version 3. | |
| 28 | +* | |
| 29 | +* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | +* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | +* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | +* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | +* copyright notice. | |
| 35 | +* | |
| 36 | +* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | +* @license GNU General Public License version 3 | |
| 38 | +* @author KnowledgeTree Team | |
| 39 | +* @package KTCMIS | |
| 40 | +* @version Version 0.9 | |
| 41 | +*/ | |
| 42 | + | |
| 43 | +require_once(realpath(dirname(__FILE__) . '/ktService.inc.php')); | |
| 44 | +require_once(CMIS_DIR . '/services/CMISRepositoryService.inc.php'); | |
| 45 | + | |
| 46 | +/** | |
| 47 | + * Handles low level repository information queries | |
| 48 | + */ | |
| 49 | +class KTRepositoryService extends KTCMISBase { | |
| 50 | + | |
| 51 | + protected $RepositoryService; | |
| 52 | + | |
| 53 | + public function __construct() | |
| 54 | + { | |
| 55 | + // instantiate underlying CMIS service | |
| 56 | + $this->RepositoryService = new CMISRepositoryService(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Fetch a list of all available repositories | |
| 61 | + * | |
| 62 | + * NOTE Since we only have one repository at the moment, this is expected to only return one result | |
| 63 | + * | |
| 64 | + * @return repositoryList[] | |
| 65 | + */ | |
| 66 | + public function getRepositories() | |
| 67 | + { | |
| 68 | + $repositories = $this->RepositoryService->getRepositories(); | |
| 69 | + if (PEAR::isError($repositories)) | |
| 70 | + { | |
| 71 | + return array( | |
| 72 | + "status_code" => 1, | |
| 73 | + "message" => "Failed getting repositories" | |
| 74 | + ); | |
| 75 | + } | |
| 76 | + | |
| 77 | + // extract the required info fields into array format for easy encoding; | |
| 78 | + $count = 0; | |
| 79 | + $repositoryList = array(); | |
| 80 | + foreach ($repositories as $repository) | |
| 81 | + { | |
| 82 | + $repositoryList[$count]['repositoryId'] = $repository->getRepositoryId(); | |
| 83 | + $repositoryList[$count]['repositoryName'] = $repository->getRepositoryName(); | |
| 84 | + $repositoryList[$count]['repositoryURI'] = $repository->getRepositoryURI(); | |
| 85 | + ++$count; | |
| 86 | + } | |
| 87 | + | |
| 88 | + return array( | |
| 89 | + "status_code" => 0, | |
| 90 | + "results" => $repositoryList | |
| 91 | + ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Fetches information about the selected repository | |
| 96 | + * | |
| 97 | + * @param string $repositoryId | |
| 98 | + */ | |
| 99 | + public function getRepositoryInfo($repositoryId) | |
| 100 | + { | |
| 101 | + $repositoryInfo = $this->RepositoryService->getRepositoryInfo($repositoryId); | |
| 102 | + if (PEAR::isError($repositoryInfo)) | |
| 103 | + { | |
| 104 | + return array( | |
| 105 | + "status_code" => 1, | |
| 106 | + "message" => "Failed getting repository information" | |
| 107 | + ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + // TODO output this manually, the function works but only for some objects so rather avoid it completely? | |
| 111 | + // NOTE the problems appear to be due to recursive objects | |
| 112 | + return array ( | |
| 113 | + "status_code" => 0, | |
| 114 | + "results" => CMISUtil::objectToArray($repositoryInfo) | |
| 115 | + ); | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Fetch the list of supported object types for the selected repository | |
| 120 | + * | |
| 121 | + * @param string $repositoryId | |
| 122 | + */ | |
| 123 | + public function getTypes($repositoryId, $typeId = '', $returnPropertyDefinitions = false, | |
| 124 | + $maxItems = 0, $skipCount = 0, &$hasMoreItems = false) | |
| 125 | + { | |
| 126 | + try { | |
| 127 | + $repositoryObjectTypeResult = $this->RepositoryService->getTypes($repositoryId, $typeId, $returnPropertyDefinitions, | |
| 128 | + $maxItems, $skipCount, $hasMoreItems); | |
| 129 | + } | |
| 130 | + catch (Exception $e) | |
| 131 | + { | |
| 132 | + return array( | |
| 133 | + "status_code" => 1, | |
| 134 | + "message" => $e->getMessage() | |
| 135 | + ); | |
| 136 | + } | |
| 137 | + | |
| 138 | + // format as array style output | |
| 139 | + // NOTE only concerned with attributes at this time | |
| 140 | + // TODO add support for properties | |
| 141 | + foreach($repositoryObjectTypeResult as $key => $objectType) | |
| 142 | + { | |
| 143 | + $repositoryObjectTypes[$key] = $objectType['attributes']; | |
| 144 | + // TODO properties | |
| 145 | + // $repositoryObjectTypes[$key]['properties'] = $objectType['properties']; | |
| 146 | + } | |
| 147 | + | |
| 148 | + return array ( | |
| 149 | + "status_code" => 0, | |
| 150 | + "results" => $repositoryObjectTypes | |
| 151 | + ); | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Fetch the object type definition for the requested type | |
| 156 | + * | |
| 157 | + * @param string $repositoryId | |
| 158 | + * @param string $typeId | |
| 159 | + */ | |
| 160 | + public function getTypeDefinition($repositoryId, $typeId) | |
| 161 | + { | |
| 162 | + try { | |
| 163 | + $typeDefinitionResult = $this->RepositoryService->getTypeDefinition($repositoryId, $typeId); | |
| 164 | + } | |
| 165 | + catch (Exception $e) | |
| 166 | + { | |
| 167 | + return array( | |
| 168 | + "status_code" => 1, | |
| 169 | + "message" => $e->getMessage() | |
| 170 | + ); | |
| 171 | + } | |
| 172 | + | |
| 173 | + // format as array style output | |
| 174 | + // NOTE only concerned with attributes at this time | |
| 175 | + // TODO add support for properties | |
| 176 | + $typeDefinition = $typeDefinitionResult['attributes']; | |
| 177 | + | |
| 178 | + return array ( | |
| 179 | + "status_code" => 0, | |
| 180 | + "results" => $typeDefinition | |
| 181 | + ); | |
| 182 | + } | |
| 183 | + | |
| 184 | +} | |
| 185 | + | |
| 186 | +?> | |
| 0 | 187 | \ No newline at end of file | ... | ... |
lib/api/ktcmis/ktService.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Base service class for CMIS wrapper API for KnowledgeTree. | |
| 4 | +* | |
| 5 | +* KnowledgeTree Community Edition | |
| 6 | +* Document Management Made Simple | |
| 7 | +* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | +* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | +* | |
| 10 | +* This program is free software; you can redistribute it and/or modify it under | |
| 11 | +* the terms of the GNU General Public License version 3 as published by the | |
| 12 | +* Free Software Foundation. | |
| 13 | +* | |
| 14 | +* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | +* details. | |
| 18 | +* | |
| 19 | +* You should have received a copy of the GNU General Public License | |
| 20 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | +* | |
| 22 | +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | +* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | +* | |
| 25 | +* The interactive user interfaces in modified source and object code versions | |
| 26 | +* of this program must display Appropriate Legal Notices, as required under | |
| 27 | +* Section 5 of the GNU General Public License version 3. | |
| 28 | +* | |
| 29 | +* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | +* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | +* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | +* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | +* copyright notice. | |
| 35 | +* | |
| 36 | +* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | +* @license GNU General Public License version 3 | |
| 38 | +* @author KnowledgeTree Team | |
| 39 | +* @package KTCMIS | |
| 40 | +* @version Version 0.9 | |
| 41 | +*/ | |
| 42 | + | |
| 43 | +require_once(realpath(dirname(__FILE__) . '/../../../config/dmsDefaults.php')); | |
| 44 | +require_once(KT_DIR . '/ktapi/ktapi.inc.php'); | |
| 45 | + | |
| 46 | +define ('CMIS_DIR', KT_LIB_DIR . '/api/ktcmis'); | |
| 47 | +require_once(CMIS_DIR . '/exceptions/PermissionDeniedException.inc.php'); | |
| 48 | +require_once(CMIS_DIR . '/util/CMISUtil.inc.php'); | |
| 49 | + | |
| 50 | +/** | |
| 51 | + * Base class for all KT CMIS classes | |
| 52 | + * Handles authentication | |
| 53 | + * | |
| 54 | + * This class is required for all CMIS Service classes | |
| 55 | + */ | |
| 56 | +class KTCMISBase { | |
| 57 | + | |
| 58 | + // we want all child classes to share the ktapi and session instances, no matter where they are set from, | |
| 59 | + // so we declare them as static | |
| 60 | + static protected $ktapi; | |
| 61 | + static protected $session; | |
| 62 | + | |
| 63 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 64 | + { | |
| 65 | + // TODO confirm KTAPI instance active??? shouldn't really be responsibility of this code | |
| 66 | + if (is_null($ktapi) && (!is_null($username) && !is_null($password))) { | |
| 67 | + $this->startSession($username, $password); | |
| 68 | + } | |
| 69 | + else { | |
| 70 | + self::$ktapi = $ktapi; | |
| 71 | + self::$session = self::$ktapi->get_session(); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + // TODO this probably does not belong here??? probably should require all auth external, handled by transport protocol. | |
| 76 | + // perhaps simple refusal to execute without valid session? | |
| 77 | + // NOTE left in to allow transport protocol to delegate auth to this level, but not actually used in any code at present | |
| 78 | + public function startSession($username, $password) | |
| 79 | + { | |
| 80 | + // attempt to recover session if one exists | |
| 81 | + if (!is_null(self::$session) && !PEAR::isError(self::$session)) | |
| 82 | + { | |
| 83 | + self::$session =& self::$ktapi->get_active_session(self::$session->get_sessionid()); | |
| 84 | + } | |
| 85 | + | |
| 86 | + // start new session if no existing session or problem getting existing session (expired, etc...) | |
| 87 | + if (is_null(self::$session) || PEAR::isError(self::$session)) | |
| 88 | + { | |
| 89 | + self::$ktapi = new KTAPI(); | |
| 90 | + self::$session =& self::$ktapi->start_session($username, $password); | |
| 91 | + } | |
| 92 | + | |
| 93 | + // failed authentication? | |
| 94 | + if (PEAR::isError(self::$session)) | |
| 95 | + { | |
| 96 | + throw new PermissionDeniedException('You must be authenticated to perform this action'); | |
| 97 | + } | |
| 98 | + | |
| 99 | + return self::$session; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public function setInterface(&$ktapi = null) | |
| 103 | + { | |
| 104 | + if (!is_null($ktapi)) { | |
| 105 | + self::$ktapi = $ktapi; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function getInterface() | |
| 110 | + { | |
| 111 | + return self::$ktapi; | |
| 112 | + } | |
| 113 | + | |
| 114 | + public function getSession() | |
| 115 | + { | |
| 116 | + return self::$session; | |
| 117 | + } | |
| 118 | + | |
| 119 | + // TODO what about destroying sessions? only on logout (which is not offered by the CMIS clients tested so far) | |
| 120 | +} | |
| 121 | + | |
| 122 | +?> | |
| 0 | 123 | \ No newline at end of file | ... | ... |
lib/api/ktcmis/ktVersioningService.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* Versioning Service CMIS wrapper API for KnowledgeTree. | |
| 4 | +* | |
| 5 | +* KnowledgeTree Community Edition | |
| 6 | +* Document Management Made Simple | |
| 7 | +* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | +* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | +* | |
| 10 | +* This program is free software; you can redistribute it and/or modify it under | |
| 11 | +* the terms of the GNU General Public License version 3 as published by the | |
| 12 | +* Free Software Foundation. | |
| 13 | +* | |
| 14 | +* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | +* details. | |
| 18 | +* | |
| 19 | +* You should have received a copy of the GNU General Public License | |
| 20 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | +* | |
| 22 | +* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | +* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | +* | |
| 25 | +* The interactive user interfaces in modified source and object code versions | |
| 26 | +* of this program must display Appropriate Legal Notices, as required under | |
| 27 | +* Section 5 of the GNU General Public License version 3. | |
| 28 | +* | |
| 29 | +* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | +* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | +* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | +* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | +* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | +* copyright notice. | |
| 35 | +* | |
| 36 | +* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | +* @license GNU General Public License version 3 | |
| 38 | +* @author KnowledgeTree Team | |
| 39 | +* @package KTCMIS | |
| 40 | +* @version Version 0.9 | |
| 41 | +*/ | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * Split into individual classes to handle each section of functionality. | |
| 45 | + * This is really just a handling layer between CMIS and the web services. | |
| 46 | + */ | |
| 47 | + | |
| 48 | +require_once(realpath(dirname(__FILE__) . '/ktService.inc.php')); | |
| 49 | +require_once(CMIS_DIR . '/services/CMISVersioningService.inc.php'); | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * Handles requests for and actions on versionable objects | |
| 53 | + */ | |
| 54 | +class KTVersioningService extends KTCMISBase { | |
| 55 | + | |
| 56 | + protected $VersioningService; | |
| 57 | + | |
| 58 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 59 | + { | |
| 60 | + parent::__construct($ktapi, $username, $password); | |
| 61 | + // instantiate underlying CMIS service | |
| 62 | + $this->VersioningService = new CMISVersioningService(); | |
| 63 | + $this->setInterface(); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public function startSession($username, $password) | |
| 67 | + { | |
| 68 | + parent::startSession($username, $password); | |
| 69 | + $this->setInterface(); | |
| 70 | + return self::$session; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public function setInterface(&$ktapi = null) | |
| 74 | + { | |
| 75 | + parent::setInterface($ktapi); | |
| 76 | + $this->VersioningService->setInterface(self::$ktapi); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Deletes all Document Objects in the specified Version Series, including the Private Working Copy | |
| 81 | + * | |
| 82 | + * @param string $repositoryId | |
| 83 | + * @param string $versionSeriesId | |
| 84 | + * @return boolean true if successful | |
| 85 | + */ | |
| 86 | + public function deleteAllVersions($repositoryId, $versionSeriesId) | |
| 87 | + { | |
| 88 | + try { | |
| 89 | + $result = $this->VersioningService->deleteAllVersions($repositoryId, $versionSeriesId); | |
| 90 | + } | |
| 91 | + catch (Exception $e) | |
| 92 | + { | |
| 93 | + return array( | |
| 94 | + "status_code" => 1, | |
| 95 | + "message" => $e->getMessage() | |
| 96 | + ); | |
| 97 | + } | |
| 98 | + | |
| 99 | + return array( | |
| 100 | + 'status_code' => 0, | |
| 101 | + 'results' => $result | |
| 102 | + ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Checks out a document and creates the PWC (Private Working Copy) which will represent the checked out document | |
| 107 | + * | |
| 108 | + * @param string $repositoryId | |
| 109 | + * @param string $documentId | |
| 110 | + * @param string $changeToken [optional] | |
| 111 | + * @return array results | |
| 112 | + */ | |
| 113 | + // TODO set up delivery of content stream? or is that up to the CMIS client? | |
| 114 | + public function checkOut($repositoryId, $documentId, $changeToken = '') | |
| 115 | + { | |
| 116 | + try { | |
| 117 | + $result = $this->VersioningService->checkOut($repositoryId, $documentId, $changeToken); | |
| 118 | + } | |
| 119 | + catch (Exception $e) | |
| 120 | + { | |
| 121 | + return array( | |
| 122 | + "status_code" => 1, | |
| 123 | + "message" => $e->getMessage() | |
| 124 | + ); | |
| 125 | + } | |
| 126 | + | |
| 127 | + return array( | |
| 128 | + 'status_code' => 0, | |
| 129 | + 'results' => (!empty($result) ? $result : 'Document Checked Out') | |
| 130 | + ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Reverses the effect of a checkout: I.E. deletes the PWC (Private Working Copy) and re-sets the status of the document to "not checked out" | |
| 135 | + * | |
| 136 | + * @param string $repositoryId | |
| 137 | + * @param string $documentId | |
| 138 | + * @param string $changeToken [optional] | |
| 139 | + */ | |
| 140 | + // TODO exceptions: | |
| 141 | + // • ConstraintViolationException: The Repository SHALL throw this exception if ANY of the following conditions are met: | |
| 142 | + // o The Document’s Object-Type definition’s versionable attribute is FALSE. | |
| 143 | + // • updateConflictException | |
| 144 | + // • versioningException | |
| 145 | + public function cancelCheckOut($repositoryId, $documentId, $changeToken = '') | |
| 146 | + { | |
| 147 | + try { | |
| 148 | + $result = $this->VersioningService->cancelCheckOut($repositoryId, $documentId, $changeToken); | |
| 149 | + } | |
| 150 | + catch (Exception $e) | |
| 151 | + { | |
| 152 | + return array( | |
| 153 | + "status_code" => 1, | |
| 154 | + "message" => $e->getMessage() | |
| 155 | + ); | |
| 156 | + } | |
| 157 | + | |
| 158 | + return array( | |
| 159 | + 'status_code' => 0, | |
| 160 | + 'results' => (!empty($result) ? $result : 'Document Checkout Cancelled') | |
| 161 | + ); | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Checks in a checked out document | |
| 166 | + * | |
| 167 | + * @param string $repositoryId | |
| 168 | + * @param string $documentId | |
| 169 | + * @param boolean $major | |
| 170 | + * @param string $changeToken [optional] | |
| 171 | + * @param array $properties [optional] | |
| 172 | + * @param contentStream $contentStream [optional] | |
| 173 | + * @param string $checkinComment [optional] | |
| 174 | + * @return string $documentId | |
| 175 | + */ | |
| 176 | + public function checkIn($repositoryId, $documentId, $major, $contentStream = null, $changeToken = '', $properties = array(), $checkinComment = '') | |
| 177 | + { | |
| 178 | + try { | |
| 179 | + $result = $this->VersioningService->checkIn($repositoryId, $documentId, $major, $contentStream, $changeToken, $properties, $checkinComment); | |
| 180 | + } | |
| 181 | + catch (Exception $e) | |
| 182 | + { | |
| 183 | + return array( | |
| 184 | + "status_code" => 1, | |
| 185 | + "message" => $e->getMessage() | |
| 186 | + ); | |
| 187 | + } | |
| 188 | + | |
| 189 | + return array( | |
| 190 | + 'status_code' => 0, | |
| 191 | + 'results' => (!empty($result) ? $result : 'Document Checked In Successfully') | |
| 192 | + ); | |
| 193 | + } | |
| 194 | + | |
| 195 | +} | |
| 196 | + | |
| 197 | +?> | |
| 0 | 198 | \ No newline at end of file | ... | ... |
lib/api/ktcmis/ktcmis.inc.php deleted
| 1 | -<?php | |
| 2 | -/** | |
| 3 | -* Implements a CMIS wrapper API for KnowledgeTree. | |
| 4 | -* | |
| 5 | -* KnowledgeTree Community Edition | |
| 6 | -* Document Management Made Simple | |
| 7 | -* Copyright (C) 2008,2009 KnowledgeTree Inc. | |
| 8 | -* Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 9 | -* | |
| 10 | -* This program is free software; you can redistribute it and/or modify it under | |
| 11 | -* the terms of the GNU General Public License version 3 as published by the | |
| 12 | -* Free Software Foundation. | |
| 13 | -* | |
| 14 | -* This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | -* details. | |
| 18 | -* | |
| 19 | -* You should have received a copy of the GNU General Public License | |
| 20 | -* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | -* | |
| 22 | -* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | -* California 94120-7775, or email info@knowledgetree.com. | |
| 24 | -* | |
| 25 | -* The interactive user interfaces in modified source and object code versions | |
| 26 | -* of this program must display Appropriate Legal Notices, as required under | |
| 27 | -* Section 5 of the GNU General Public License version 3. | |
| 28 | -* | |
| 29 | -* In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | -* these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | -* KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | -* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | -* must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | -* copyright notice. | |
| 35 | -* | |
| 36 | -* @copyright 2008-2009, KnowledgeTree Inc. | |
| 37 | -* @license GNU General Public License version 3 | |
| 38 | -* @author KnowledgeTree Team | |
| 39 | -* @package KTCMIS | |
| 40 | -* @version Version 0.9 | |
| 41 | -*/ | |
| 42 | - | |
| 43 | -/** | |
| 44 | - * Split into individual classes to handle each section of functionality. | |
| 45 | - * This is really just a handling layer between CMIS and the web services. | |
| 46 | - */ | |
| 47 | - | |
| 48 | -// TODO implement exceptions in various calls (in the underlying classes) | |
| 49 | -// FIXME none of the error handling actually does anything, it's leftover from copy/paste of some ktapi code | |
| 50 | - | |
| 51 | -require_once(realpath(dirname(__FILE__) . '/../../../config/dmsDefaults.php')); | |
| 52 | -require_once(KT_DIR . '/ktapi/ktapi.inc.php'); | |
| 53 | - | |
| 54 | -define ('CMIS_DIR', KT_LIB_DIR . '/api/ktcmis'); | |
| 55 | -require_once(CMIS_DIR . '/exceptions/PermissionDeniedException.inc.php'); | |
| 56 | -require_once(CMIS_DIR . '/services/CMISRepositoryService.inc.php'); | |
| 57 | -require_once(CMIS_DIR . '/services/CMISNavigationService.inc.php'); | |
| 58 | -require_once(CMIS_DIR . '/services/CMISObjectService.inc.php'); | |
| 59 | -require_once(CMIS_DIR . '/services/CMISVersioningService.inc.php'); | |
| 60 | -require_once(CMIS_DIR . '/util/CMISUtil.inc.php'); | |
| 61 | - | |
| 62 | -/** | |
| 63 | - * Base class for all KT CMIS classes | |
| 64 | - * Handles authentication | |
| 65 | - */ | |
| 66 | -class KTCMISBase { | |
| 67 | - | |
| 68 | - // we want all child classes to share the ktapi and session instances, no matter where they are set from, | |
| 69 | - // so we declare them as static | |
| 70 | - static protected $ktapi; | |
| 71 | - static protected $session; | |
| 72 | - | |
| 73 | - public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 74 | - { | |
| 75 | - // TODO confirm KTAPI instance active??? shouldn't really be responsibility of this code | |
| 76 | - if (is_null($ktapi) && (!is_null($username) && !is_null($password))) { | |
| 77 | - $this->startSession($username, $password); | |
| 78 | - } | |
| 79 | - else { | |
| 80 | - self::$ktapi = $ktapi; | |
| 81 | - self::$session = self::$ktapi->get_session(); | |
| 82 | - } | |
| 83 | - } | |
| 84 | - | |
| 85 | - // TODO this probably does not belong here??? probably should require all auth external, handled by transport protocol. | |
| 86 | - // perhaps simple refusal to execute without valid session? | |
| 87 | - // NOTE left in to allow transport protocol to delegate auth to this level, but not actually used in any code at present | |
| 88 | - public function startSession($username, $password) | |
| 89 | - { | |
| 90 | - // attempt to recover session if one exists | |
| 91 | - if (!is_null(self::$session) && !PEAR::isError(self::$session)) | |
| 92 | - { | |
| 93 | - self::$session =& self::$ktapi->get_active_session(self::$session->get_sessionid()); | |
| 94 | - } | |
| 95 | - | |
| 96 | - // start new session if no existing session or problem getting existing session (expired, etc...) | |
| 97 | - if (is_null(self::$session) || PEAR::isError(self::$session)) | |
| 98 | - { | |
| 99 | - self::$ktapi = new KTAPI(); | |
| 100 | - self::$session =& self::$ktapi->start_session($username, $password); | |
| 101 | - } | |
| 102 | - | |
| 103 | - // failed authentication? | |
| 104 | - if (PEAR::isError(self::$session)) | |
| 105 | - { | |
| 106 | - throw new PermissionDeniedException('You must be authenticated to perform this action'); | |
| 107 | - } | |
| 108 | - | |
| 109 | - return self::$session; | |
| 110 | - } | |
| 111 | - | |
| 112 | - public function setInterface(&$ktapi = null) | |
| 113 | - { | |
| 114 | - if (!is_null($ktapi)) { | |
| 115 | - self::$ktapi = $ktapi; | |
| 116 | - } | |
| 117 | - } | |
| 118 | - | |
| 119 | - public function getInterface() | |
| 120 | - { | |
| 121 | - return self::$ktapi; | |
| 122 | - } | |
| 123 | - | |
| 124 | - public function getSession() | |
| 125 | - { | |
| 126 | - return self::$session; | |
| 127 | - } | |
| 128 | - | |
| 129 | - // TODO what about destroying sessions? only on logout (which is not offered by the CMIS clients tested so far) | |
| 130 | -} | |
| 131 | - | |
| 132 | -/** | |
| 133 | - * Handles low level repository information queries | |
| 134 | - */ | |
| 135 | -class KTRepositoryService extends KTCMISBase { | |
| 136 | - | |
| 137 | - protected $RepositoryService; | |
| 138 | - | |
| 139 | - public function __construct() | |
| 140 | - { | |
| 141 | - // instantiate underlying CMIS service | |
| 142 | - $this->RepositoryService = new CMISRepositoryService(); | |
| 143 | - } | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * Fetch a list of all available repositories | |
| 147 | - * | |
| 148 | - * NOTE Since we only have one repository at the moment, this is expected to only return one result | |
| 149 | - * | |
| 150 | - * @return repositoryList[] | |
| 151 | - */ | |
| 152 | - public function getRepositories() | |
| 153 | - { | |
| 154 | - $repositories = $this->RepositoryService->getRepositories(); | |
| 155 | - if (PEAR::isError($repositories)) | |
| 156 | - { | |
| 157 | - return array( | |
| 158 | - "status_code" => 1, | |
| 159 | - "message" => "Failed getting repositories" | |
| 160 | - ); | |
| 161 | - } | |
| 162 | - | |
| 163 | - // extract the required info fields into array format for easy encoding; | |
| 164 | - $count = 0; | |
| 165 | - $repositoryList = array(); | |
| 166 | - foreach ($repositories as $repository) | |
| 167 | - { | |
| 168 | - $repositoryList[$count]['repositoryId'] = $repository->getRepositoryId(); | |
| 169 | - $repositoryList[$count]['repositoryName'] = $repository->getRepositoryName(); | |
| 170 | - $repositoryList[$count]['repositoryURI'] = $repository->getRepositoryURI(); | |
| 171 | - ++$count; | |
| 172 | - } | |
| 173 | - | |
| 174 | - return array( | |
| 175 | - "status_code" => 0, | |
| 176 | - "results" => $repositoryList | |
| 177 | - ); | |
| 178 | - } | |
| 179 | - | |
| 180 | - /** | |
| 181 | - * Fetches information about the selected repository | |
| 182 | - * | |
| 183 | - * @param string $repositoryId | |
| 184 | - */ | |
| 185 | - public function getRepositoryInfo($repositoryId) | |
| 186 | - { | |
| 187 | - $repositoryInfo = $this->RepositoryService->getRepositoryInfo($repositoryId); | |
| 188 | - if (PEAR::isError($repositoryInfo)) | |
| 189 | - { | |
| 190 | - return array( | |
| 191 | - "status_code" => 1, | |
| 192 | - "message" => "Failed getting repository information" | |
| 193 | - ); | |
| 194 | - } | |
| 195 | - | |
| 196 | - // TODO output this manually, the function works but only for some objects so rather avoid it completely? | |
| 197 | - // NOTE the problems appear to be due to recursive objects | |
| 198 | - return array ( | |
| 199 | - "status_code" => 0, | |
| 200 | - "results" => CMISUtil::objectToArray($repositoryInfo) | |
| 201 | - ); | |
| 202 | - } | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * Fetch the list of supported object types for the selected repository | |
| 206 | - * | |
| 207 | - * @param string $repositoryId | |
| 208 | - */ | |
| 209 | - public function getTypes($repositoryId, $typeId = '', $returnPropertyDefinitions = false, | |
| 210 | - $maxItems = 0, $skipCount = 0, &$hasMoreItems = false) | |
| 211 | - { | |
| 212 | - try { | |
| 213 | - $repositoryObjectTypeResult = $this->RepositoryService->getTypes($repositoryId, $typeId, $returnPropertyDefinitions, | |
| 214 | - $maxItems, $skipCount, $hasMoreItems); | |
| 215 | - } | |
| 216 | - catch (Exception $e) | |
| 217 | - { | |
| 218 | - return array( | |
| 219 | - "status_code" => 1, | |
| 220 | - "message" => $e->getMessage() | |
| 221 | - ); | |
| 222 | - } | |
| 223 | - | |
| 224 | - // format as array style output | |
| 225 | - // NOTE only concerned with attributes at this time | |
| 226 | - // TODO add support for properties | |
| 227 | - foreach($repositoryObjectTypeResult as $key => $objectType) | |
| 228 | - { | |
| 229 | - $repositoryObjectTypes[$key] = $objectType['attributes']; | |
| 230 | - // TODO properties | |
| 231 | - // $repositoryObjectTypes[$key]['properties'] = $objectType['properties']; | |
| 232 | - } | |
| 233 | - | |
| 234 | - return array ( | |
| 235 | - "status_code" => 0, | |
| 236 | - "results" => $repositoryObjectTypes | |
| 237 | - ); | |
| 238 | - } | |
| 239 | - | |
| 240 | - /** | |
| 241 | - * Fetch the object type definition for the requested type | |
| 242 | - * | |
| 243 | - * @param string $repositoryId | |
| 244 | - * @param string $typeId | |
| 245 | - */ | |
| 246 | - public function getTypeDefinition($repositoryId, $typeId) | |
| 247 | - { | |
| 248 | - try { | |
| 249 | - $typeDefinitionResult = $this->RepositoryService->getTypeDefinition($repositoryId, $typeId); | |
| 250 | - } | |
| 251 | - catch (Exception $e) | |
| 252 | - { | |
| 253 | - return array( | |
| 254 | - "status_code" => 1, | |
| 255 | - "message" => $e->getMessage() | |
| 256 | - ); | |
| 257 | - } | |
| 258 | - | |
| 259 | - // format as array style output | |
| 260 | - // NOTE only concerned with attributes at this time | |
| 261 | - // TODO add support for properties | |
| 262 | - $typeDefinition = $typeDefinitionResult['attributes']; | |
| 263 | - | |
| 264 | - return array ( | |
| 265 | - "status_code" => 0, | |
| 266 | - "results" => $typeDefinition | |
| 267 | - ); | |
| 268 | - } | |
| 269 | - | |
| 270 | -} | |
| 271 | - | |
| 272 | -/* | |
| 273 | - * Handles repository navigation | |
| 274 | - */ | |
| 275 | -class KTNavigationService extends KTCMISBase { | |
| 276 | - | |
| 277 | - protected $NavigationService; | |
| 278 | - | |
| 279 | - public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 280 | - { | |
| 281 | - parent::__construct($ktapi, $username, $password); | |
| 282 | - // instantiate underlying CMIS service | |
| 283 | - $this->NavigationService = new CMISNavigationService(); | |
| 284 | - $this->setInterface(); | |
| 285 | - } | |
| 286 | - | |
| 287 | - public function startSession($username, $password) | |
| 288 | - { | |
| 289 | - parent::startSession($username, $password); | |
| 290 | - $this->setInterface(); | |
| 291 | - return self::$session; | |
| 292 | - } | |
| 293 | - | |
| 294 | - public function setInterface(&$ktapi = null) | |
| 295 | - { | |
| 296 | - parent::setInterface($ktapi); | |
| 297 | - $this->NavigationService->setInterface(self::$ktapi); | |
| 298 | - } | |
| 299 | - | |
| 300 | - /** | |
| 301 | - * Get descendents of the specified folder, up to the depth indicated | |
| 302 | - * | |
| 303 | - * @param string $repositoryId | |
| 304 | - * @param string $folderId | |
| 305 | - * @param boolean $includeAllowableActions | |
| 306 | - * @param boolean $includeRelationships | |
| 307 | - * @param string $typeID | |
| 308 | - * @param int $depth | |
| 309 | - * @param string $filter | |
| 310 | - * @return array $descendants | |
| 311 | - */ | |
| 312 | - public function getDescendants($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, | |
| 313 | - $depth = 1, $typeID = 'Any', $filter = '') | |
| 314 | - { | |
| 315 | - // TODO optional parameters | |
| 316 | - $descendantsResult = $this->NavigationService->getDescendants($repositoryId, $folderId, $includeAllowableActions, | |
| 317 | - $includeRelationships, $depth); | |
| 318 | - | |
| 319 | - if (PEAR::isError($descendantsResult)) | |
| 320 | - { | |
| 321 | - return array( | |
| 322 | - "status_code" => 1, | |
| 323 | - "message" => "Failed getting descendants for folder" | |
| 324 | - ); | |
| 325 | - } | |
| 326 | - | |
| 327 | - // format for webservices consumption | |
| 328 | - // NOTE this will almost definitely be changing in the future, this is just to get something working | |
| 329 | - $descendants = CMISUtil::decodeObjectHierarchy($descendantsResult, 'child'); | |
| 330 | - | |
| 331 | - return array ( | |
| 332 | - "status_code" => 0, | |
| 333 | - "results" => $descendants | |
| 334 | - ); | |
| 335 | - } | |
| 336 | - | |
| 337 | - /** | |
| 338 | - * Get direct children of the specified folder | |
| 339 | - * | |
| 340 | - * @param string $repositoryId | |
| 341 | - * @param string $folderId | |
| 342 | - * @param boolean $includeAllowableActions | |
| 343 | - * @param boolean $includeRelationships | |
| 344 | - * @param string $typeID | |
| 345 | - * @param string $filter | |
| 346 | - * @param int $maxItems | |
| 347 | - * @param int $skipCount | |
| 348 | - * @return array $descendants | |
| 349 | - */ | |
| 350 | - public function getChildren($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, | |
| 351 | - $typeID = 'Any', $filter = '', $maxItems = 0, $skipCount = 0) | |
| 352 | - { | |
| 353 | - // TODO paging | |
| 354 | - // TODO optional parameters | |
| 355 | - $childrenResult = $this->NavigationService->getChildren($repositoryId, $folderId, $includeAllowableActions, $includeRelationships); | |
| 356 | - | |
| 357 | - if (PEAR::isError($childrenResult)) | |
| 358 | - { | |
| 359 | - return array( | |
| 360 | - "status_code" => 1, | |
| 361 | - "message" => "Failed getting descendants for folder" | |
| 362 | - ); | |
| 363 | - } | |
| 364 | - | |
| 365 | - $children = CMISUtil::decodeObjectHierarchy($childrenResult, 'child'); | |
| 366 | - | |
| 367 | - return array( | |
| 368 | - "status_code" => 0, | |
| 369 | - "results" => $children | |
| 370 | - ); | |
| 371 | - } | |
| 372 | - | |
| 373 | - /** | |
| 374 | - * Gets the parent of the selected folder | |
| 375 | - * | |
| 376 | - * @param string $repositoryId | |
| 377 | - * @param string $folderId | |
| 378 | - * @param boolean $includeAllowableActions | |
| 379 | - * @param boolean $includeRelationships | |
| 380 | - * @param boolean $returnToRoot | |
| 381 | - * @param string $filter | |
| 382 | - * @return ancestry[] | |
| 383 | - */ | |
| 384 | - public function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') | |
| 385 | - { | |
| 386 | - $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, | |
| 387 | - $includeRelationships, $returnToRoot); | |
| 388 | - | |
| 389 | - if (PEAR::isError($ancestryResult)) | |
| 390 | - { | |
| 391 | - return array( | |
| 392 | - "status_code" => 1, | |
| 393 | - "message" => "Failed getting ancestry for folder" | |
| 394 | - ); | |
| 395 | - } | |
| 396 | - | |
| 397 | - $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'child'); | |
| 398 | - | |
| 399 | - return array( | |
| 400 | - "status_code" => 0, | |
| 401 | - "results" => $ancestry | |
| 402 | - ); | |
| 403 | - } | |
| 404 | - | |
| 405 | - /** | |
| 406 | - * Gets the parents for the selected object | |
| 407 | - * | |
| 408 | - * @param string $repositoryId | |
| 409 | - * @param string $folderId | |
| 410 | - * @param boolean $includeAllowableActions | |
| 411 | - * @param boolean $includeRelationships | |
| 412 | - * @param string $filter | |
| 413 | - * @return ancestry[] | |
| 414 | - */ | |
| 415 | - function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') | |
| 416 | - { | |
| 417 | - $ancestryResult = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions, | |
| 418 | - $includeRelationships); | |
| 419 | - | |
| 420 | - if (PEAR::isError($ancestryResult)) | |
| 421 | - { | |
| 422 | - return array( | |
| 423 | - "status_code" => 1, | |
| 424 | - "message" => "Failed getting ancestry for object" | |
| 425 | - ); | |
| 426 | - } | |
| 427 | - | |
| 428 | - $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'child'); | |
| 429 | - | |
| 430 | - return array( | |
| 431 | - "status_code" => 0, | |
| 432 | - "results" => $ancestry | |
| 433 | - ); | |
| 434 | - } | |
| 435 | - | |
| 436 | - /** | |
| 437 | - * Returns a list of checked out documents from the selected repository | |
| 438 | - * | |
| 439 | - * @param string $repositoryId | |
| 440 | - * @param string $folderId The folder for which checked out docs are requested | |
| 441 | - * @param string $filter | |
| 442 | - * @param boolean $includeAllowableActions | |
| 443 | - * @param boolean $includeRelationships | |
| 444 | - * @param int $maxItems | |
| 445 | - * @param int $skipCount | |
| 446 | - * @return array $checkedout The collection of checked out documents | |
| 447 | - */ | |
| 448 | - function getCheckedOutDocs($repositoryId, $includeAllowableActions, $includeRelationships, $folderId = null, $filter = '', | |
| 449 | - $maxItems = 0, $skipCount = 0) | |
| 450 | - { | |
| 451 | - $checkedout = $this->NavigationService->getCheckedOutDocs($repositoryId, $includeAllowableActions, $includeRelationships, | |
| 452 | - $folderId, $filter, $maxItems, $skipCount); | |
| 453 | - | |
| 454 | - if (PEAR::isError($checkedout)) | |
| 455 | - { | |
| 456 | - return array( | |
| 457 | - "status_code" => 1, | |
| 458 | - "message" => "Failed getting list of checked out documents" | |
| 459 | - ); | |
| 460 | - } | |
| 461 | - | |
| 462 | - // convert to array format for external code | |
| 463 | - $co = array(); | |
| 464 | - foreach ($checkedout as $documentProperties) | |
| 465 | - { | |
| 466 | - $co[] = CMISUtil::createObjectPropertiesEntry($documentProperties);; | |
| 467 | - } | |
| 468 | - | |
| 469 | - return array( | |
| 470 | - "status_code" => 0, | |
| 471 | - "results" => $co | |
| 472 | - ); | |
| 473 | - } | |
| 474 | - | |
| 475 | -} | |
| 476 | - | |
| 477 | -/** | |
| 478 | - * Handles requests for and actions on Folders and Documents | |
| 479 | - */ | |
| 480 | -class KTObjectService extends KTCMISBase { | |
| 481 | - | |
| 482 | - protected $ObjectService; | |
| 483 | - | |
| 484 | - public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 485 | - { | |
| 486 | - parent::__construct($ktapi, $username, $password); | |
| 487 | - // instantiate underlying CMIS service | |
| 488 | - $this->ObjectService = new CMISObjectService(); | |
| 489 | - $this->setInterface(); | |
| 490 | - } | |
| 491 | - | |
| 492 | - public function startSession($username, $password) | |
| 493 | - { | |
| 494 | - parent::startSession($username, $password); | |
| 495 | - $this->setInterface(); | |
| 496 | - return self::$session; | |
| 497 | - } | |
| 498 | - | |
| 499 | - public function setInterface(&$ktapi = null) | |
| 500 | - { | |
| 501 | - parent::setInterface($ktapi); | |
| 502 | - $this->ObjectService->setInterface(self::$ktapi); | |
| 503 | - } | |
| 504 | - | |
| 505 | - /** | |
| 506 | - * Gets the properties for the selected object | |
| 507 | - * | |
| 508 | - * @param string $repositoryId | |
| 509 | - * @param string $objectId | |
| 510 | - * @param boolean $includeAllowableActions | |
| 511 | - * @param boolean $includeRelationships | |
| 512 | - * @param string $returnVersion | |
| 513 | - * @param string $filter | |
| 514 | - * @return properties[] | |
| 515 | - */ | |
| 516 | - public function getProperties($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, | |
| 517 | - $returnVersion = false, $filter = '') | |
| 518 | - { | |
| 519 | - try { | |
| 520 | - $propertyCollection = $this->ObjectService->getProperties($repositoryId, $objectId, $includeAllowableActions, | |
| 521 | - $includeRelationships); | |
| 522 | - } | |
| 523 | - catch (Exception $e) | |
| 524 | - { | |
| 525 | - return array( | |
| 526 | - "status_code" => 1, | |
| 527 | - "message" => $e->getMessage() | |
| 528 | - ); | |
| 529 | - } | |
| 530 | - | |
| 531 | - $properties = CMISUtil::createObjectPropertiesEntry($propertyCollection); | |
| 532 | - | |
| 533 | - return array( | |
| 534 | - "status_code" => 0, | |
| 535 | - "results" => $properties | |
| 536 | - ); | |
| 537 | - } | |
| 538 | - | |
| 539 | - /** | |
| 540 | - * Creates a new document within the repository | |
| 541 | - * | |
| 542 | - * @param string $repositoryId The repository to which the document must be added | |
| 543 | - * @param string $typeId Object Type id for the document object being created | |
| 544 | - * @param array $properties Array of properties which must be applied to the created document object | |
| 545 | - * @param string $folderId The id of the folder which will be the parent of the created document object | |
| 546 | - * This parameter is optional IF unfilingCapability is supported | |
| 547 | - * @param contentStream $contentStream optional content stream data | |
| 548 | - * @param string $versioningState optional version state value: checkedout/major/minor | |
| 549 | - * @return string $objectId The id of the created folder object | |
| 550 | - */ | |
| 551 | - public function createDocument($repositoryId, $typeId, $properties, $folderId = null, | |
| 552 | - $contentStream = null, $versioningState = null) | |
| 553 | - { | |
| 554 | - $objectId = null; | |
| 555 | - | |
| 556 | - try { | |
| 557 | - $objectId = $this->ObjectService->createDocument($repositoryId, $typeId, $properties, $folderId, | |
| 558 | - $contentStream, $versioningState); | |
| 559 | - } | |
| 560 | - catch (Exception $e) | |
| 561 | - { | |
| 562 | - return array( | |
| 563 | - "status_code" => 1, | |
| 564 | - "message" => $e->getMessage() | |
| 565 | - ); | |
| 566 | - } | |
| 567 | - | |
| 568 | - return array( | |
| 569 | - 'status_code' => 0, | |
| 570 | - 'results' => $objectId | |
| 571 | - ); | |
| 572 | - } | |
| 573 | - | |
| 574 | - /** | |
| 575 | - * Creates a new folder within the repository | |
| 576 | - * | |
| 577 | - * @param string $repositoryId The repository to which the folder must be added | |
| 578 | - * @param string $typeId Object Type id for the folder object being created | |
| 579 | - * @param array $properties Array of properties which must be applied to the created folder object | |
| 580 | - * @param string $folderId The id of the folder which will be the parent of the created folder object | |
| 581 | - * @return string $objectId The id of the created folder object | |
| 582 | - */ | |
| 583 | - public function createFolder($repositoryId, $typeId, $properties, $folderId) | |
| 584 | - { | |
| 585 | - $objectId = null; | |
| 586 | - | |
| 587 | - try { | |
| 588 | - $objectId = $this->ObjectService->createFolder($repositoryId, $typeId, $properties, $folderId); | |
| 589 | - } | |
| 590 | - catch (Exception $e) | |
| 591 | - { | |
| 592 | - return array( | |
| 593 | - "status_code" => 1, | |
| 594 | - "message" => $e->getMessage() | |
| 595 | - ); | |
| 596 | - } | |
| 597 | - | |
| 598 | - return array( | |
| 599 | - 'status_code' => 0, | |
| 600 | - 'results' => $objectId | |
| 601 | - ); | |
| 602 | - } | |
| 603 | - | |
| 604 | - /** | |
| 605 | - * Fetches the content stream data for an object | |
| 606 | - * | |
| 607 | - * @param string $repositoryId | |
| 608 | - * @param string $objectId | |
| 609 | - * @return string $contentStream (binary or text data) | |
| 610 | - */ | |
| 611 | - function getContentStream($repositoryId, $objectId) | |
| 612 | - { | |
| 613 | - try { | |
| 614 | - $contentStream = $this->ObjectService->getContentStream($repositoryId, $objectId); | |
| 615 | - } | |
| 616 | - catch (Exception $e) | |
| 617 | - { | |
| 618 | - return array( | |
| 619 | - "status_code" => 1, | |
| 620 | - "message" => $e->getMessage() | |
| 621 | - ); | |
| 622 | - } | |
| 623 | - | |
| 624 | - return array( | |
| 625 | - 'status_code' => 0, | |
| 626 | - 'results' => $contentStream | |
| 627 | - ); | |
| 628 | - } | |
| 629 | - | |
| 630 | - /** | |
| 631 | - * Moves a fileable object from one folder to another. | |
| 632 | - * | |
| 633 | - * @param object $repositoryId | |
| 634 | - * @param object $objectId | |
| 635 | - * @param object $changeToken [optional] | |
| 636 | - * @param object $targetFolderId | |
| 637 | - * @param object $sourceFolderId [optional] | |
| 638 | - */ | |
| 639 | - public function moveObject($repositoryId, $objectId, $changeToken = '', $targetFolderId, $sourceFolderId = null) | |
| 640 | - { | |
| 641 | - try { | |
| 642 | - $this->ObjectService->moveObject($repositoryId, $objectId, $changeToken, $targetFolderId, $sourceFolderId); | |
| 643 | - } | |
| 644 | - catch (Exception $e) | |
| 645 | - { | |
| 646 | - return array( | |
| 647 | - "status_code" => 1, | |
| 648 | - "message" => $e->getMessage() | |
| 649 | - ); | |
| 650 | - } | |
| 651 | - | |
| 652 | - return array( | |
| 653 | - 'status_code' => 0, | |
| 654 | - 'results' => $objectId | |
| 655 | - ); | |
| 656 | - } | |
| 657 | - | |
| 658 | - /** | |
| 659 | - * Deletes an object from the repository | |
| 660 | - * | |
| 661 | - * @param string $repositoryId | |
| 662 | - * @param string $objectId | |
| 663 | - * @param string $changeToken [optional] | |
| 664 | - * @return array | |
| 665 | - */ | |
| 666 | - // NOTE Invoking this service method on an object SHALL not delete the entire version series for a Document Object. | |
| 667 | - // To delete an entire version series, use the deleteAllVersions() service | |
| 668 | - public function deleteObject($repositoryId, $objectId, $changeToken = null) | |
| 669 | - { | |
| 670 | - try { | |
| 671 | - $this->ObjectService->deleteObject($repositoryId, $objectId, $changeToken); | |
| 672 | - } | |
| 673 | - catch (Exception $e) | |
| 674 | - { | |
| 675 | - return array( | |
| 676 | - "status_code" => 1, | |
| 677 | - "message" => $e->getMessage() | |
| 678 | - ); | |
| 679 | - } | |
| 680 | - | |
| 681 | - return array( | |
| 682 | - 'status_code' => 0, | |
| 683 | - 'results' => $objectId | |
| 684 | - ); | |
| 685 | - } | |
| 686 | - | |
| 687 | - public function deleteTree($repositoryId, $objectId, $changeToken = null, $unfileNonfolderObject = 'delete', $continueOnFailure = false) | |
| 688 | - { | |
| 689 | - try { | |
| 690 | - $result = $this->ObjectService->deleteTree($repositoryId, $objectId, $changeToken, $unfileNonfolderObject, $continueOnFailure); | |
| 691 | - } | |
| 692 | - catch (Exception $e) | |
| 693 | - { | |
| 694 | - return array( | |
| 695 | - "status_code" => 1, | |
| 696 | - "message" => $e->getMessage() | |
| 697 | - ); | |
| 698 | - } | |
| 699 | - | |
| 700 | - // check whether there is a list of items which did not delete | |
| 701 | - if (count($result) > 0) | |
| 702 | - { | |
| 703 | - return array( | |
| 704 | - "status_code" => 1, | |
| 705 | - "message" => $result | |
| 706 | - ); | |
| 707 | - } | |
| 708 | - | |
| 709 | - return array( | |
| 710 | - 'status_code' => 0, | |
| 711 | - 'results' => $objectId | |
| 712 | - ); | |
| 713 | - } | |
| 714 | - | |
| 715 | - /** | |
| 716 | - * Sets the content stream data for an existing document | |
| 717 | - * | |
| 718 | - * if $overwriteFlag = TRUE, the new content stream is applied whether or not the document has an existing content stream | |
| 719 | - * if $overwriteFlag = FALSE, the new content stream is applied only if the document does not have an existing content stream | |
| 720 | - * | |
| 721 | - * NOTE A Repository MAY automatically create new Document versions as part of this service method. | |
| 722 | - * Therefore, the documentId output NEED NOT be identical to the documentId input. | |
| 723 | - * | |
| 724 | - * @param string $repositoryId | |
| 725 | - * @param string $documentId | |
| 726 | - * @param boolean $overwriteFlag | |
| 727 | - * @param string $contentStream | |
| 728 | - * @param string $changeToken | |
| 729 | - * @return string $documentId | |
| 730 | - */ | |
| 731 | - function setContentStream($repositoryId, $documentId, $overwriteFlag, $contentStream, $changeToken = null) | |
| 732 | - { | |
| 733 | - try { | |
| 734 | - $documentId = $this->ObjectService->setContentStream($repositoryId, $documentId, $overwriteFlag, $contentStream, $changeToken); | |
| 735 | - } | |
| 736 | - catch (Exception $e) | |
| 737 | - { | |
| 738 | - return array( | |
| 739 | - "status_code" => 1, | |
| 740 | - "message" => $e->getMessage() | |
| 741 | - ); | |
| 742 | - } | |
| 743 | - | |
| 744 | - return array( | |
| 745 | - 'status_code' => 0, | |
| 746 | - 'results' => $documentId | |
| 747 | - ); | |
| 748 | - } | |
| 749 | - | |
| 750 | -} | |
| 751 | - | |
| 752 | -/** | |
| 753 | - * Handles requests for and actions on versionable objects | |
| 754 | - */ | |
| 755 | -class KTVersioningService extends KTCMISBase { | |
| 756 | - | |
| 757 | - protected $VersioningService; | |
| 758 | - | |
| 759 | - public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 760 | - { | |
| 761 | - parent::__construct($ktapi, $username, $password); | |
| 762 | - // instantiate underlying CMIS service | |
| 763 | - $this->VersioningService = new CMISVersioningService(); | |
| 764 | - $this->setInterface(); | |
| 765 | - } | |
| 766 | - | |
| 767 | - public function startSession($username, $password) | |
| 768 | - { | |
| 769 | - parent::startSession($username, $password); | |
| 770 | - $this->setInterface(); | |
| 771 | - return self::$session; | |
| 772 | - } | |
| 773 | - | |
| 774 | - public function setInterface(&$ktapi = null) | |
| 775 | - { | |
| 776 | - parent::setInterface($ktapi); | |
| 777 | - $this->VersioningService->setInterface(self::$ktapi); | |
| 778 | - } | |
| 779 | - | |
| 780 | - /** | |
| 781 | - * Deletes all Document Objects in the specified Version Series, including the Private Working Copy | |
| 782 | - * | |
| 783 | - * @param string $repositoryId | |
| 784 | - * @param string $versionSeriesId | |
| 785 | - * @return boolean true if successful | |
| 786 | - */ | |
| 787 | - public function deleteAllVersions($repositoryId, $versionSeriesId) | |
| 788 | - { | |
| 789 | - try { | |
| 790 | - $result = $this->VersioningService->deleteAllVersions($repositoryId, $versionSeriesId); | |
| 791 | - } | |
| 792 | - catch (Exception $e) | |
| 793 | - { | |
| 794 | - return array( | |
| 795 | - "status_code" => 1, | |
| 796 | - "message" => $e->getMessage() | |
| 797 | - ); | |
| 798 | - } | |
| 799 | - | |
| 800 | - return array( | |
| 801 | - 'status_code' => 0, | |
| 802 | - 'results' => $result | |
| 803 | - ); | |
| 804 | - } | |
| 805 | - | |
| 806 | - /** | |
| 807 | - * Checks out a document and creates the PWC (Private Working Copy) which will represent the checked out document | |
| 808 | - * | |
| 809 | - * @param string $repositoryId | |
| 810 | - * @param string $documentId | |
| 811 | - * @param string $changeToken [optional] | |
| 812 | - * @return array results | |
| 813 | - */ | |
| 814 | - // TODO set up delivery of content stream? or is that up to the CMIS client? | |
| 815 | - public function checkOut($repositoryId, $documentId, $changeToken = '') | |
| 816 | - { | |
| 817 | - try { | |
| 818 | - $result = $this->VersioningService->checkOut($repositoryId, $documentId, $changeToken); | |
| 819 | - } | |
| 820 | - catch (Exception $e) | |
| 821 | - { | |
| 822 | - return array( | |
| 823 | - "status_code" => 1, | |
| 824 | - "message" => $e->getMessage() | |
| 825 | - ); | |
| 826 | - } | |
| 827 | - | |
| 828 | - return array( | |
| 829 | - 'status_code' => 0, | |
| 830 | - 'results' => (!empty($result) ? $result : 'Document Checked Out') | |
| 831 | - ); | |
| 832 | - } | |
| 833 | - | |
| 834 | - /** | |
| 835 | - * Reverses the effect of a checkout: I.E. deletes the PWC (Private Working Copy) and re-sets the status of the document to "not checked out" | |
| 836 | - * | |
| 837 | - * @param string $repositoryId | |
| 838 | - * @param string $documentId | |
| 839 | - * @param string $changeToken [optional] | |
| 840 | - */ | |
| 841 | - // TODO exceptions: | |
| 842 | - // • ConstraintViolationException: The Repository SHALL throw this exception if ANY of the following conditions are met: | |
| 843 | - // o The Document’s Object-Type definition’s versionable attribute is FALSE. | |
| 844 | - // • updateConflictException | |
| 845 | - // • versioningException | |
| 846 | - public function cancelCheckOut($repositoryId, $documentId, $changeToken = '') | |
| 847 | - { | |
| 848 | - try { | |
| 849 | - $result = $this->VersioningService->cancelCheckOut($repositoryId, $documentId, $changeToken); | |
| 850 | - } | |
| 851 | - catch (Exception $e) | |
| 852 | - { | |
| 853 | - return array( | |
| 854 | - "status_code" => 1, | |
| 855 | - "message" => $e->getMessage() | |
| 856 | - ); | |
| 857 | - } | |
| 858 | - | |
| 859 | - return array( | |
| 860 | - 'status_code' => 0, | |
| 861 | - 'results' => (!empty($result) ? $result : 'Document Checkout Cancelled') | |
| 862 | - ); | |
| 863 | - } | |
| 864 | - | |
| 865 | - /** | |
| 866 | - * Checks in a checked out document | |
| 867 | - * | |
| 868 | - * @param string $repositoryId | |
| 869 | - * @param string $documentId | |
| 870 | - * @param boolean $major | |
| 871 | - * @param string $changeToken [optional] | |
| 872 | - * @param array $properties [optional] | |
| 873 | - * @param contentStream $contentStream [optional] | |
| 874 | - * @param string $checkinComment [optional] | |
| 875 | - * @return string $documentId | |
| 876 | - */ | |
| 877 | - public function checkIn($repositoryId, $documentId, $major, $contentStream = null, $changeToken = '', $properties = array(), $checkinComment = '') | |
| 878 | - { | |
| 879 | - try { | |
| 880 | - $result = $this->VersioningService->checkIn($repositoryId, $documentId, $major, $contentStream, $changeToken, $properties, $checkinComment); | |
| 881 | - } | |
| 882 | - catch (Exception $e) | |
| 883 | - { | |
| 884 | - return array( | |
| 885 | - "status_code" => 1, | |
| 886 | - "message" => $e->getMessage() | |
| 887 | - ); | |
| 888 | - } | |
| 889 | - | |
| 890 | - return array( | |
| 891 | - 'status_code' => 0, | |
| 892 | - 'results' => (!empty($result) ? $result : 'Document Checked In Successfully') | |
| 893 | - ); | |
| 894 | - } | |
| 895 | - | |
| 896 | -} | |
| 897 | - | |
| 898 | -?> |
tests/ktcmis/testCmisApi.php
| ... | ... | @@ -3,7 +3,10 @@ |
| 3 | 3 | // TODO use CMISUtil::encodeObjectId to create testing ids, as we may change how the encoding works in future |
| 4 | 4 | |
| 5 | 5 | require_once (KT_DIR . '/tests/test.php'); |
| 6 | -require_once (KT_LIB_DIR . '/api/ktcmis/ktcmis.inc.php'); | |
| 6 | +require_once (KT_LIB_DIR . '/api/ktcmis/ktNavigationService.inc.php'); | |
| 7 | +require_once (KT_LIB_DIR . '/api/ktcmis/ktObjectService.inc.php'); | |
| 8 | +require_once (KT_LIB_DIR . '/api/ktcmis/ktRepositoryService.inc.php'); | |
| 9 | +require_once (KT_LIB_DIR . '/api/ktcmis/ktVersioningService.inc.php'); | |
| 7 | 10 | |
| 8 | 11 | // username and password for authentication |
| 9 | 12 | // must be set correctly for all of the tests to pass in all circumstances |
| ... | ... | @@ -526,7 +529,7 @@ class CMISTestCase extends KTUnitTestCase { |
| 526 | 529 | $response = $NavigationService->getCheckedOutDocs($repositoryId, false, false); |
| 527 | 530 | $this->assertEqual($response['status_code'], 0); |
| 528 | 531 | $this->assertNotNull($response['results']); |
| 529 | - $this->assertTrue(in_array($documentId, $response['results'])); | |
| 532 | + $this->assertTrue($this->findInPropertiesArray('ObjectId', $documentId, $response['results'])); | |
| 530 | 533 | // now let's cancel the checkout so that we can delete later during cleanup :) |
| 531 | 534 | $response = $VersioningService->cancelCheckOut($repositoryId, $pwcId); |
| 532 | 535 | |
| ... | ... | @@ -537,7 +540,46 @@ class CMISTestCase extends KTUnitTestCase { |
| 537 | 540 | // tear down the folder/doc tree structure with which we were testing |
| 538 | 541 | $this->cleanupFolderDocStructure(); |
| 539 | 542 | } |
| 543 | + | |
| 544 | + /** | |
| 545 | + * Searches a CMIS properties array for a specific value | |
| 546 | + * | |
| 547 | + * @param string $key The CMIS property key to look for | |
| 548 | + * @param string $needle The value to check | |
| 549 | + * @param array $haystack The CMIS properties array | |
| 550 | + * @param int $propeLevel -1 or positive value -> -1 = not yet found | positive = found | |
| 551 | + * @return boolean | |
| 552 | + */ | |
| 553 | + function findInPropertiesArray($key, $needle, $haystack, $propLevel = null) | |
| 554 | + { | |
| 555 | + $found = false; | |
| 556 | + | |
| 557 | + if (empty($propLevel)) $propLevel = -1; | |
| 540 | 558 | |
| 559 | + foreach($haystack as $elKey => $elValue) | |
| 560 | + { | |
| 561 | + if (($propLevel == -1) && ((string)$elKey != 'properties')) { | |
| 562 | + $found = $this->findInPropertiesArray($key, $needle, $elValue, $propLevel); | |
| 563 | + if ($found) break; | |
| 564 | + } | |
| 565 | + else if ((string)$elKey == 'properties') { | |
| 566 | + $propLevel = 1; | |
| 567 | + } | |
| 568 | + | |
| 569 | + // now check through actual properties array | |
| 570 | + $properties = $elValue; | |
| 571 | + foreach($properties as $propKey => $property) | |
| 572 | + { | |
| 573 | + if (($propKey == $key) && ($property['value'] == $needle)) { | |
| 574 | + $found = true; | |
| 575 | + break; | |
| 576 | + } | |
| 577 | + } | |
| 578 | + } | |
| 579 | + | |
| 580 | + return $found; | |
| 581 | + } | |
| 582 | + | |
| 541 | 583 | /** |
| 542 | 584 | * Helper function to create a document |
| 543 | 585 | */ | ... | ... |
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
| ... | ... | @@ -30,6 +30,7 @@ i. Other (Content-less document, Folder, Relationship, Type, etc) – best effor |
| 30 | 30 | When POSTing an Atom Document, the atom fields take precedence over the CMIS property field for writeable properties. For example, atom:title will overwrite cmis:name |
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | +// load all available CMIS services | |
| 33 | 34 | include_once CMIS_ATOM_LIB_FOLDER . 'RepositoryService.inc.php'; |
| 34 | 35 | include_once CMIS_ATOM_LIB_FOLDER . 'NavigationService.inc.php'; |
| 35 | 36 | include_once CMIS_ATOM_LIB_FOLDER . 'ObjectService.inc.php'; |
| ... | ... | @@ -667,7 +668,6 @@ class KT_cmis_atom_service_pwc extends KT_cmis_atom_service { |
| 667 | 668 | |
| 668 | 669 | public function PUT_action() |
| 669 | 670 | { |
| 670 | - // call the checkin function | |
| 671 | 671 | $RepositoryService = new RepositoryService(); |
| 672 | 672 | $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt()); |
| 673 | 673 | ... | ... |
webservice/classes/atompub/cmis/NavigationService.inc.php
webservice/classes/atompub/cmis/ObjectService.inc.php
webservice/classes/atompub/cmis/RepositoryService.inc.php
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | * for processing of CMIS queries and responses via atompub/webservices |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -require_once KT_LIB_DIR . '/api/ktcmis/ktcmis.inc.php'; | |
| 8 | +require_once KT_LIB_DIR . '/api/ktcmis/ktRepositoryService.inc.php'; | |
| 9 | 9 | |
| 10 | 10 | class RepositoryService extends KTRepositoryService { |
| 11 | 11 | ... | ... |
webservice/classes/atompub/cmis/VersioningService.inc.php