diff --git a/lib/api/ktcmis/ktNavigationService.inc.php b/lib/api/ktcmis/ktNavigationService.inc.php index 2a88729..d247442 100644 --- a/lib/api/ktcmis/ktNavigationService.inc.php +++ b/lib/api/ktcmis/ktNavigationService.inc.php @@ -157,8 +157,16 @@ class KTNavigationService extends KTCMISBase { */ public function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') { - $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, - $includeRelationships, $returnToRoot); + try { + $ancestryResult = $this->NavigationService->getFolderParent($repositoryId, $folderId, $includeAllowableActions, + $includeRelationships, $returnToRoot); + } + catch (Exception $e) { + return array( + "status_code" => 1, + "message" => "Failed getting ancestry for folder: " . $e->getMessage() + ); + } if (PEAR::isError($ancestryResult)) { diff --git a/lib/api/ktcmis/services/CMISNavigationService.inc.php b/lib/api/ktcmis/services/CMISNavigationService.inc.php index 4e00335..e29e2b8 100644 --- a/lib/api/ktcmis/services/CMISNavigationService.inc.php +++ b/lib/api/ktcmis/services/CMISNavigationService.inc.php @@ -71,7 +71,7 @@ class CMISNavigationService { */ // NOTE This method does NOT support paging as defined in the paging section - // NOTE If the Repository supports the optional “VersionSpecificFiling” capability, + // NOTE If the Repository supports the optional “VersionSpecificFiling? capability, // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. // Otherwise, the latest version of the documents SHALL be returned. // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid @@ -112,7 +112,7 @@ class CMISNavigationService { * @param int $skipCount * @return array $descendants */ - // NOTE If the Repository supports the optional “VersionSpecificFiling” capability, + // NOTE If the Repository supports the optional “VersionSpecificFiling? capability, // then the repository SHALL return the document versions filed in the specified folder or its descendant folders. // Otherwise, the latest version of the documents SHALL be returned. // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid @@ -155,9 +155,14 @@ class CMISNavigationService { */ // TODO FilterNotValidException: The Repository SHALL throw this exception if this property filter input parameter is not valid // TODO If this service method is invoked on the root folder of the Repository, then the Repository SHALL return an empty result set. - // NOTE SHOULD always include the “ObjectId” and “ParentId” properties for all objects returned + // NOTE SHOULD always include the “ObjectId? and “ParentId? properties for all objects returned function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') { + // NOTE the root folder obviously has no parent, throw an ObjectNotFoundException here if this is the root folder + if (CMISUtil::isRootFolder($repositoryId, $folderId, $this->ktapi)) { + throw new ObjectNotFoundException('Root folder has no parent'); + } + $ancestry = array(); $repository = new CMISRepository($repositoryId); diff --git a/lib/api/ktcmis/util/CMISUtil.inc.php b/lib/api/ktcmis/util/CMISUtil.inc.php index f04c79d..765b7c0 100644 --- a/lib/api/ktcmis/util/CMISUtil.inc.php +++ b/lib/api/ktcmis/util/CMISUtil.inc.php @@ -614,6 +614,16 @@ class CMISUtil { return $tempfilename; } + /** + * attempts to fetch the folder id from a name + * + * NOTE this won't be reliable if there is more than one folder in the system with the same name + * the only reason this exists is to accomodate the method of browsing used by the drupal module + * + * @param string $name + * @param object $ktapi + * @return string + */ static public function getIdFromName($name, &$ktapi) { $folder = $ktapi->get_folder_by_name($name); @@ -621,10 +631,22 @@ class CMISUtil { return self::encodeObjectId(FOLDER, $folder->get_folderid()); } + /** + * Checks for the root folder + * + * @param unknown_type $repositoryId + * @param unknown_type $folderId + * @param unknown_type $ktapi + * @return unknown + */ static public function isRootFolder($repositoryId, $folderId, &$ktapi) { $repository = new CMISRepository($repositoryId); $repositoryInfo = $repository->getRepositoryInfo(); + + // NOTE this call is required to accomodate the definition of the root folder id in the config as required by the drupal module + // we should try to update the drupal module to not require this, but this way is just easier at the moment, and most of + // the code accomodates it without any serious hacks $rootFolder = self::getIdFromName($repositoryInfo->getRootFolderId(), $ktapi); return $folderId == $rootFolder; diff --git a/webservice/classes/atompub/cmis/NavigationService.inc.php b/webservice/classes/atompub/cmis/NavigationService.inc.php index fe05697..0be43c9 100644 --- a/webservice/classes/atompub/cmis/NavigationService.inc.php +++ b/webservice/classes/atompub/cmis/NavigationService.inc.php @@ -77,6 +77,9 @@ class NavigationService extends KTNavigationService { { return $result['results']; } + else { + return new PEAR_Error($result['message']); + } } /**