/** * Deals with folder service POST actions. * This includes creation/moving of both folders and documents. */ public function POST_action() { $RepositoryService = new RepositoryService(); $repositories = $RepositoryService->getRepositories(); $repositoryId = $repositories[0]['repositoryId']; // set default action, objectId and typeId $action = 'create'; $objectId = null; $typeId = null; $folderId = $this->params[0]; $title = KT_cmis_atom_service_helper::getAtomValues($this->parsedXMLContent['@children'], 'title'); $summary = KT_cmis_atom_service_helper::getAtomValues($this->parsedXMLContent['@children'], 'summary'); $properties = array('name' => $title, 'summary' => $summary); // determine whether this is a folder or a document action // document action create will have a content tag <atom:content> or <content> containing base64 encoding of the document // move action will have an existing id supplied as a parameter - not sure how this works yet as the CMIS clients we are // testing don't support move functionality at this time (2009/07/23) and so we are presuming the following format: // /folder/<folderId>/children/<objectId> // also possible that there will be an existing ObjectId property, try to cater for both until we know how it really works // check for existing object id as parameter in url if (isset($this->params[2])) { $action = 'move'; $objectId = $this->params[2]; } $cmisObjectProperties = KT_cmis_atom_service_helper::getCmisProperties($this->parsedXMLContent['@children']['cmis:object']); // check for existing object id as property of submitted object data if (!empty($cmisObjectProperties['ObjectId'])) { $action = 'move'; $objectId = $cmisObjectProperties['ObjectId']; } // TODO there may be more to do for the checking of an existing object. // e.g. verifying that it does indeed exist, and throwing an exception if it does not: // "If the objected property is present but not valid an exception will be thrown" (from CMIS specification) // NOTE this exception should be thrown in the service API code and not here. // determine type if object is being moved if (!is_null($objectId)) { CMISUtil::decodeObjectId($objectId, $typeId); } // now check for content stream $content = KT_cmis_atom_service_helper::getAtomValues($this->parsedXMLContent['@children'], 'content'); // TODO this will possibly need to change somewhat once Relationship Objects come into play. if ($action == 'create' && is_null($content) || $typeId == 'Folder') { $type = 'folder'; } else { $type = 'document'; } $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); $success = false; $error = null; if ($action == 'create') { if ($type == 'folder') { $newObjectId = $ObjectService->createFolder($repositoryId, ucwords($cmisObjectProperties['ObjectTypeId']), $properties, $folderId); } else { $newObjectId = $ObjectService->createDocument($repositoryId, ucwords($cmisObjectProperties['ObjectTypeId']), $properties, $folderId, $content); } // check if returned Object Id is a valid CMIS Object Id CMISUtil::decodeObjectId($newObjectId, $typeId); if ($typeId != 'Unknown') { $success = true; } else { $error = $newObjectId['message']; } } else { if ($action == 'move') { $response = $ObjectService->moveObject($repositoryId, $objectId, '', $folderId); if (!PEAR::isError($response)) { $success = true; } else { $error = $response->getMessage(); } // same object as before $newObjectId = $objectId; $typeId = ucwords($type); } } if ($success) { $this->setStatus($action == 'create' ? self::STATUS_CREATED : self::STATUS_UPDATED); $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $newObjectId, 'POST'); } else { $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $error); } //Expose the responseFeed $this->responseFeed = $feed; }
public function PUT_action() { $repositoryId = KT_cmis_atom_service_helper::getRepositoryId($RepositoryService); $VersioningService = new VersioningService(KT_cmis_atom_service_helper::getKt()); $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); // check for content stream // NOTE this is a hack! will not work with CMISSpaces at least, probably not with any client except RestTest and similar // where we can manually modify the input // first we try for an atom content tag $content = KT_cmis_atom_service_helper::getAtomValues($this->parsedXMLContent['@children'], 'content'); if (!empty($content)) { $contentStream = $content; } else { $content = KT_cmis_atom_service_helper::findTag('content', $this->parsedXMLContent['@children'], null, false); $contentStream = $content['@value']; } // if we haven't found it now, the real hack begins - retrieve the EXISTING content and submit this as the contentStream // this is needed because KnowledgeTree will not accept a checkin without a content stream but CMISSpaces (and possibly // other CMIS clients are the same, does not send a content stream on checkin nor does it offer the user a method to choose one) // NOTE that if the content is INTENDED to be empty this and all the above checks will FAIL! // FIXME this is horrible, terrible, ugly and bad! if (empty($contentStream)) { $contentStream = base64_encode(KT_cmis_atom_service_helper::getContentStream($this, $ObjectService, $repositoryId)); } // and if we don't have it by now, we give up...but leave the error to be generated by the underlying KnowledgeTree code // checkin function call // TODO dynamically detect version change type - leaving this for now as the CMIS clients tested do not appear to // offer the choice to the user - perhaps it will turn out that this will come from somewhere else but for now // we assume minor version updates only $major = false; $response = $VersioningService->checkIn($repositoryId, $this->params[0], $major, $contentStream); if (PEAR::isError($response)) { $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_SERVER_ERROR, $response->getMessage()); // Expose the responseFeed $this->responseFeed = $feed; return null; } $feed = KT_cmis_atom_service_helper::getObjectFeed($this, $ObjectService, $repositoryId, $this->params[0]); // Expose the responseFeed $this->responseFeed = $feed; }