function do_checkin() { $oForm = $this->form_main(); $res = $oForm->validate(); $data = $res['results']; $extra_errors = array(); // If the filename is different to the original check if "Force Original Filename" is set and return an error if it is. $docFileName = $this->oDocument->getFilename(); if ($data['file']['name'] != $docFileName) { global $default; if ($default->disableForceFilenameOption) { $extra_errors['file'] = sprintf(_kt('The file you uploaded was not called "%s". The file must have the same name as the original file.'), htmlentities($docFileName, ENT_QUOTES, 'UTF-8')); } else { if ($data['forcefilename']) { $extra_errors['file'] = sprintf(_kt('The file you uploaded was not called "%s". If you wish to change the filename, please set "Force Original Filename" below to false. '), htmlentities($docFileName, ENT_QUOTES, 'UTF-8')); } } } if (!empty($res['errors']) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } $sReason = $data['reason']; $sCurrentFilename = $docFileName; $sNewFilename = $data['file']['name']; $aOptions = array(); if ($data['major_update']) { $aOptions['major_update'] = true; } if ($sCurrentFilename != $sNewFilename) { $aOptions['newfilename'] = $sNewFilename; } $res = KTDocumentUtil::checkin($this->oDocument, $data['file']['tmp_name'], $sReason, $this->oUser, $aOptions); if (PEAR::isError($res)) { $this->errorRedirectToMain(_kt('An error occurred while trying to check in the document'), 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason); } redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); exit(0); }
/** * This checks a document into the repository. * * <code> * $ktapi = new KTAPI(); * $session = $ktapi->start_system_session(); * $document = $ktapi->get_document_by_id($documentid); * if($document->is_checked_out()){ * $document->checkin('filename.txt', 'Reason for checkin', '/tmp/filename'); * } * </code> * * @author KnowledgeTree Team * @access public * @param string $filename The name of the file * @param string $reason The reason for checking the document in * @param string $tempfilename The location of the temporary file * @param bool $major_update Determines if the version number should have a major increment (+1) or a minor increment (+0.1) */ function checkin($filename, $reason, $tempfilename, $major_update = false) { if (!is_file($tempfilename)) { return new PEAR_Error('File does not exist.'); } $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } if (!$this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT); } $filename = KTUtil::replaceInvalidCharacters($filename); $options = array('major_update' => $major_update); $currentfilename = $this->document->getFileName(); if ($filename != $currentfilename) { $options['newfilename'] = $filename; } DBUtil::startTransaction(); $result = KTDocumentUtil::checkin($this->document, $tempfilename, $reason, $user, $options); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result); } DBUtil::commit(); KTUploadManager::temporary_file_imported($tempfilename); }