iId = -1; $oVersionDocument->setStatusID(STATUS_VERSION); $oVersionDocument->setLiveDocumentID($oDocument->getID()); $oVersionDocument->setIsCheckedOut(false); $oVersionDocument->setCheckedOutUserID(null); $res = $oVersionDocument->create(); if ($res !== true) { if (PEAR::isError($res)) { return $res; } // XXX: Remove when Document uses PEAR Errors return PEAR::raiseError($_SESSION["errorMessage"]); } $aFields =& DocumentFieldLink::getByDocument($oDocument); $iVersionDocumentID = $oVersionDocument->getID(); foreach ($aFields as $oDFL) { // XXX: PHP5 clone $oVersionDFL = $oDFL; $oVersionDFL->iId = -1; $oVersionDFL->setDocumentID($iVersionDocumentID); $res = $oVersionDFL->create(); } return $oVersionDocument; } function bumpVersion($oDocument) { if (is_numeric($oDocument)) { $oDocument =& Document::get($oDocument); if (PEAR::isError($oDocument)) { return $oDocument; } } $oDocument->setMetadataVersion($oDocument->getMetadataVersion()+1); return $oDocument->update(); } function setModifiedDate($oDocument) { if (is_numeric($oDocument)) { $oDocument =& Document::get($oDocument); if (PEAR::isError($oDocument)) { return $oDocument; } } $oDocument->setLastModifiedDate(getCurrentDateTime()); return $oDocument->update(); } function checkin($oDocument, $sFilename, $sCheckInComment, $sCheckInType = "minor") { $sBackupPath = $oDocument->getPath() . "-" . $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber(); $bSuccess = @copy($oDocument->getPath(), $sBackupPath); if ($bSuccess === false) { return PEAR::raiseError(_("Unable to backup document prior to upload")); } $oVersionedDocument = KTDocumentUtil::createMetadataVersion($oDocument); if (PEAR::isError($oVersionedDocument)) { return $oVersionedDocument; } if (!PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $oDocument->getFolderID(), "", $sFilename)) { // reinstate the backup copy($sBackupPath, $oDocument->getPath()); // remove the backup unlink($sBackupPath); return PEAR::raiseError(_("An error occurred while storing the new file on the filesystem")); } $oDocument->setMetadataVersion($oDocument->getMetadataVersion()+1); $oDocument->setFileSize($_FILES['fFile']['size']); $oDocument->setLastModifiedDate(getCurrentDateTime()); $oDocument->setIsCheckedOut(false); $oDocument->setCheckedOutUserID(-1); // bump the version numbers if ($sCheckInType == "major") { $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); $oDocument->setMinorVersionNumber(0); } else if ($sCheckInType == "minor") { $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); } $bSuccess = $oDocument->update(); if ($bSuccess !== true) { if (PEAR::isError($bSuccess)) { return $bSuccess; } return PEAR::raiseError(_("An error occurred while storing this document in the database")); } // create the document transaction record $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $sCheckInComment, CHECKIN); // TODO: check transaction creation status? $oDocumentTransaction->create(); // fire subscription alerts for the checked in document $count = SubscriptionEngine::fireSubscription($oDocument->getID(), SubscriptionConstants::subscriptionAlertType("CheckInDocument"), SubscriptionConstants::subscriptionType("DocumentSubscription"), array( "folderID" => $oDocument->getFolderID(), "modifiedDocumentName" => $oDocument->getName() )); global $default; $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); return true; } } ?>