From 9ec9690393de9cdef49fa45b433512ff2b984698 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Sat, 1 Mar 2003 10:01:51 +0000 Subject: [PATCH] don't allow check in unless you checked the document out --- presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------- 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php index 6f4f59a..9e101dd 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php @@ -53,76 +53,81 @@ if (checkSession()) { if (Permission::userHasDocumentWritePermission($fDocumentID)) { // and the document is checked out if ($oDocument->getIsCheckedOut()) { - // if we're ready to perform the updates - if ($fForStore) { - // make sure the user actually selected a file first - if (strlen($_FILES['fFile']['name']) > 0) { - - // backup the original document - $sBackupPath = $oDocument->getPath() . ".bk"; - copy($oDocument->getPath(), $sBackupPath); - - // update the document with the uploaded one - if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { - // remove the backup - unlink($sBackupPath); + // by you + if ($oDocument->getCheckedOutUserID() == $_SESSION["userID"]) { + // if we're ready to perform the updates + if ($fForStore) { + // make sure the user actually selected a file first + if (strlen($_FILES['fFile']['name']) > 0) { + + // backup the original document + $sBackupPath = $oDocument->getPath() . ".bk"; + copy($oDocument->getPath(), $sBackupPath); - // now update the database - // overwrite size - $oDocument->setFileSize($_FILES['fFile']['size']); - // update modified date - $oDocument->setLastModifiedDate(getCurrentDateTime()); - // flip the check out status - $oDocument->setIsCheckedOut(false); - // clear the checked in user id - $oDocument->setCheckedOutUserID(-1); - // bump the version numbers - if ($fCheckInType == "major") { - // major version number rollover - $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); - // reset minor version number - $oDocument->setMinorVersionNumber(0); - } else if ($fCheckInType == "minor") { - $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); - } - - // update it - if ($oDocument->update()) { - - // create the document transaction record - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); - // TODO: check transaction creation status? - $oDocumentTransaction->create(); + // update the document with the uploaded one + if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { + // remove the backup + unlink($sBackupPath); - // fire subscription alerts for the checked in document - $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), - SubscriptionConstants::subscriptionType("DocumentSubscription"), - array( "modifiedDocumentName" => $oDocument->getName() )); - $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); - - //redirect to the document view page - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); + // now update the database + // overwrite size + $oDocument->setFileSize($_FILES['fFile']['size']); + // update modified date + $oDocument->setLastModifiedDate(getCurrentDateTime()); + // flip the check out status + $oDocument->setIsCheckedOut(false); + // clear the checked in user id + $oDocument->setCheckedOutUserID(-1); + // bump the version numbers + if ($fCheckInType == "major") { + // major version number rollover + $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); + // reset minor version number + $oDocument->setMinorVersionNumber(0); + } else if ($fCheckInType == "minor") { + $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); + } + + // update it + if ($oDocument->update()) { + + // create the document transaction record + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); + // TODO: check transaction creation status? + $oDocumentTransaction->create(); + + // fire subscription alerts for the checked in document + $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), + SubscriptionConstants::subscriptionType("DocumentSubscription"), + array( "modifiedDocumentName" => $oDocument->getName() )); + $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); + + //redirect to the document view page + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); + } else { + // document update failed + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing this document in the database")); + } } else { - // document update failed - $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing this document in the database")); + // reinstate the backup + copy($sBackupPath, $oDocument->getPath()); + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem")); } } else { - // reinstate the backup - copy($sBackupPath, $oDocument->getPath()); - $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem")); + $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; + $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); } } else { - $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; + // prompt the user for a check in comment and the file $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); } } else { - // prompt the user for a check in comment and the file - $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); + // you don't have this doc checked out + $oPatternCustom->setHtml(renderErrorPage("You can't check in this document because its checked out by " . User::getName($oDocument->getCheckedOutUserID()))); } } else { // this document isn't checked out $oPatternCustom->setHtml(renderErrorPage("You can't check in this document because its not checked out")); - } } else { // no permission to checkout the document -- libgit2 0.21.4