/** * Does a document checkin. * * @param string $session_id * @param int $document_id * @param string $filename * @param string $reason * @param string $base64 * @param boolean $major_update * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ function checkin_small_document($session_id, $document_id, $filename, $reason, $base64, $major_update) { $this->debug("checkin_small_document('{$session_id}',{$document_id},'{$filename}','{$reason}','*** base64 content ***',{$major_update})"); $kt =& $this->get_ktapi($session_id); if (is_array($kt)) { return new SOAP_Value('return', "{urn:{$this->namespace}}kt_document_detail", $kt); } $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT); $upload_manager = new KTUploadManager(); $tempfilename = $upload_manager->store_base64_file($base64, 'su_'); if (PEAR::isError($tempfilename)) { $reason = $tempfilename->getMessage(); $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT, 'Cannot write to temp file: ' . $tempfilename . ". Reason: {$reason}"); $this->debug("checkin_small_document - cannot write {$tempfilename}. Reason: {$reason}", $session_id); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_document_detail", $response); } // simulate the upload $tempfilename = $upload_manager->uploaded($filename, $tempfilename, 'C'); $document =& $kt->get_document_by_id($document_id); if (PEAR::isError($document)) { $response['message'] = $document->getMessage(); $this->debug("checkin_small_document - cannot get documentid {$document_id} - " . $document->getMessage(), $session_id); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_document_detail", $response); } $result = $document->checkin($filename, $reason, $tempfilename, $major_update); if (PEAR::isError($result)) { $response['message'] = $result->getMessage(); $this->debug("checkin_small_document - cannot checkin document - " . $result->getMessage(), $session_id); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_document_detail", $response); } // get status after checkin return $this->get_document_detail($session_id, $document_id); }
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'); } // NOTE There is a function in CMISUtil to do this but since KTUploadManager exists and has more functionality // which could come in useful at some point I decided to go with that instead (did not know it existed when // I wrote the CMISUtil function) $uploadManager = new KTUploadManager(); $tempfilename = $uploadManager->store_base64_file($contentStream, 'cmis_'); // 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'); }
/** * Does a document checkin. * * @author KnowledgeTree Team * @access public * @param int $document_id * @param string $filename * @param string $reason * @param string $base64 * @param boolean $major_update * @return kt_document_detail. */ public function checkin_small_document($document_id, $filename, $reason, $base64, $major_update, $sig_username = '', $sig_password = '') { $response = $this->_check_electronic_signature($document_id, $sig_username, $sig_password, $reason, $reason, 'ktcore.transactions.check_in'); if ($response['status_code'] == 1) { return $response; } $upload_manager = new KTUploadManager(); $tempfilename = $upload_manager->store_base64_file($base64, 'su_'); if (PEAR::isError($tempfilename)) { $reason = $tempfilename->getMessage(); $response['status_code'] = 1; $response['message'] = 'Cannot write to temp file: ' . $tempfilename . ". Reason: {$reason}"; return $response; } // simulate the upload $tempfilename = $upload_manager->uploaded($filename, $tempfilename, 'C'); $document =& $this->get_document_by_id($document_id); if (PEAR::isError($document)) { $response['status_code'] = 1; $response['message'] = $document->getMessage(); return $response; } $result = $document->checkin($filename, $reason, $tempfilename, $major_update); if (PEAR::isError($result)) { $response['status_code'] = 1; $response['message'] = $result->getMessage(); return $response; } // get status after checkin return $this->get_document_detail($document_id); }