function getCheckedOutDocs($repositoryId, $folderId = null, $filter = '', $includeAllowableActions, $includeRelationships, $maxItems = 0, $skipCount = 0) { $checkedout = array(); $results = $this->ktapi->get_checkedout_docs(false); foreach ($results as $document) { $CMISDocument = new CMISDocumentObject($document->getId(), $this->ktapi); // set version label property - possibly belongs in document class $CMISDocument->setProperty('VersionLabel', $CMISDocument->getProperty('VersionSeriesCheckedOutId')); $checkedout[] = $CMISDocument->getProperties(); } return $checkedout; }
public function checkIn($repositoryId, $documentId, $major, $contentStream = null, $changeToken = '', $properties = array(), $checkinComment = '') { $documentId = CMISUtil::decodeObjectId($documentId, $typeId); // throw updateConflictException if the operation is attempting to update an object that is no longer current (as determined by the repository). try { $pwc = new CMISDocumentObject($documentId, $this->ktapi); } catch (exception $e) { throw new UpdateConflictException($e->getMessage()); } // throw exception if the object is not versionable if (!$pwc->getAttribute('versionable')) { throw new ConstraintViolationException('This document is not versionable and may not be checked in'); } $RepositoryService = new CMISRepositoryService(); try { $typeDefinition = $RepositoryService->getTypeDefinition($repositoryId, $typeId); } catch (exception $e) { // if we can't get the type definition, then we can't store the content throw new StorageException($e->getMessage()); } if ($typeDefinition['attributes']['contentStreamAllowed'] == 'notAllowed' && !empty($contentStream)) { throw new StreamNotSupportedException('Content Streams are not supported'); } // check that this is the latest version if ($pwc->getProperty('IsLatestVersion') != true) { throw new VersioningException('The document is not the latest version and cannot be checked in'); } // now do the checkin $tempfilename = CMISUtil::createTemporaryFile($contentStream); $response = $this->ktapi->checkin_document($documentId, $pwc->getProperty('ContentStreamFilename'), $reason, $tempfilename, $major, $sig_username, $sig_password); // if there was any error in cancelling the checkout if ($response['status_code'] == 1) { throw new RuntimeException('There was an error checking in the document: ' . $response['message']); } return CMISUtil::encodeObjectId(DOCUMENT, $documentId); }
public function setContentStream($repositoryId, $documentId, $overwriteFlag, $contentStream, $changeToken = null) { // if no document id was supplied, we are going to create the underlying physical document // NOTE while it might have been nice to keep this out of here, KTAPI has no method for creating a document without // a physical upload, so we cannot create the document first and then add the upload as a content stream, the // entire creation step needs to happen here. // Attempt to decode $documentId, use as is if not detected as encoded $tmpObjectId = $documentId; $tmpObjectId = CMISUtil::decodeObjectId($tmpObjectId, $tmpTypeId); if ($tmpTypeId != 'Unknown') { $documentId = $tmpObjectId; } // TODO deal with other types except documents // fetch type definition of supplied document $CMISDocument = new CMISDocumentObject($documentId, $this->ktapi); // if content stream is not allowed for this object type definition, throw a ConstraintViolationException if ($CMISDocument->getAttribute('contentStreamAllowed') == 'notAllowed') { // NOTE spec version 0.61c specifies both a ConstraintViolationException and a StreamNotSupportedException // for this case. Choosing to throw StreamNotSupportedException until the specification is clarified // as it is a more specific exception throw new StreamNotSupportedException('Content Streams are not allowed for this object type'); } $csFileName = $CMISDocument->getProperty('ContentStreamFilename'); if (!empty($csFileName) && !$overwriteFlag) { throw new ContentAlreadyExistsException('Unable to overwrite existing content stream'); } $tempfilename = CMISUtil::createTemporaryFile($contentStream); // update the document content from this temporary file as per usual // TODO Use checkin_document_with_metadata instead if metadata content submitted || update metadata separately? $response = $this->ktapi->checkin_document($documentId, $csFileName, 'CMIS setContentStream action', $tempfilename, false); if ($response['status_code'] != 0) { throw new StorageException('Unable to update the content stream. ' . $response['message']); } // else // { // $objectId = CMISUtil::encodeObjectId('Document', $response['results']['id']); // } @unlink($csFile); // update the CMIS document object with the content stream information // $CMISDocument->reload($document['result']['document_id']); return $CMISDocument->getProperty('ObjectId'); }
public function checkOut($repositoryId, &$documentId, $changeToken = '') { $contentCopied = false; $documentId = CMISUtil::decodeObjectId($documentId, $typeId); // NOTE We are not planning on persisting the PWC beyond the current session, it will be re-created on access of the checked out document // TODO consider persisting in the database? How will this relate to JSR if we are switching to that? // NOTE within the current system it is assumed if a new document metadata version is created that this is the latest version of the document // TODO see if there is an easy way to modify this, else we may not have an easy way to persist PWC objects // throw updateConflictException if the operation is attempting to update an object that is no longer current (as determined by the repository). try { $pwc = new CMISDocumentObject($documentId, $this->ktapi); } catch (exception $e) { throw new UpdateConflictException($e->getMessage()); } // throw exception if the object is not versionable if (!$pwc->getAttribute('versionable')) { throw new ConstraintViolationException('This document is not versionable and may not be checked out'); } // NOTE KTAPI as currently implemented does not give a direct response which indicates if the document is already checked out, // as long as the same use is calling the checkout again, so should we add a check here specifically? // run checkout process - set $download = false (third function argument) as we want to return the document content via the contentStream $response = $this->ktapi->checkout_document($documentId, 'CMIS Checkout Action', false, $sig_username, $sig_password); // if there was an error, throw an exception if ($response['status_code'] == 1) { throw new StorageException($response['message']); } // if successful, set $contentCopied = true; unless contentStream is not set if ($pwc->getProperty('ContentStreamFilename') != '') { $contentCopied = true; } $documentId = CMISUtil::encodeObjectId('Document', $documentId); // mark document object as checked out $pwc->setProperty('IsVersionSeriesCheckedOut', true); $userName = ''; $user = $this->ktapi->get_user(); if (!PEAR::isError($user)) { $userName = $user->getName(); } $pwc->setProperty('VersionSeriesCheckedOutBy', $userName); $pwc->setProperty('VersionSeriesCheckedOutId', $documentId); return $contentCopied; }