Commit 9ec9690393de9cdef49fa45b433512ff2b984698
1 parent
20603e36
don't allow check in unless you checked the document out
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1243 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
61 additions
and
56 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php
| @@ -53,76 +53,81 @@ if (checkSession()) { | @@ -53,76 +53,81 @@ if (checkSession()) { | ||
| 53 | if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 53 | if (Permission::userHasDocumentWritePermission($fDocumentID)) { |
| 54 | // and the document is checked out | 54 | // and the document is checked out |
| 55 | if ($oDocument->getIsCheckedOut()) { | 55 | if ($oDocument->getIsCheckedOut()) { |
| 56 | - // if we're ready to perform the updates | ||
| 57 | - if ($fForStore) { | ||
| 58 | - // make sure the user actually selected a file first | ||
| 59 | - if (strlen($_FILES['fFile']['name']) > 0) { | ||
| 60 | - | ||
| 61 | - // backup the original document | ||
| 62 | - $sBackupPath = $oDocument->getPath() . ".bk"; | ||
| 63 | - copy($oDocument->getPath(), $sBackupPath); | ||
| 64 | - | ||
| 65 | - // update the document with the uploaded one | ||
| 66 | - if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { | ||
| 67 | - // remove the backup | ||
| 68 | - unlink($sBackupPath); | 56 | + // by you |
| 57 | + if ($oDocument->getCheckedOutUserID() == $_SESSION["userID"]) { | ||
| 58 | + // if we're ready to perform the updates | ||
| 59 | + if ($fForStore) { | ||
| 60 | + // make sure the user actually selected a file first | ||
| 61 | + if (strlen($_FILES['fFile']['name']) > 0) { | ||
| 62 | + | ||
| 63 | + // backup the original document | ||
| 64 | + $sBackupPath = $oDocument->getPath() . ".bk"; | ||
| 65 | + copy($oDocument->getPath(), $sBackupPath); | ||
| 69 | 66 | ||
| 70 | - // now update the database | ||
| 71 | - // overwrite size | ||
| 72 | - $oDocument->setFileSize($_FILES['fFile']['size']); | ||
| 73 | - // update modified date | ||
| 74 | - $oDocument->setLastModifiedDate(getCurrentDateTime()); | ||
| 75 | - // flip the check out status | ||
| 76 | - $oDocument->setIsCheckedOut(false); | ||
| 77 | - // clear the checked in user id | ||
| 78 | - $oDocument->setCheckedOutUserID(-1); | ||
| 79 | - // bump the version numbers | ||
| 80 | - if ($fCheckInType == "major") { | ||
| 81 | - // major version number rollover | ||
| 82 | - $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); | ||
| 83 | - // reset minor version number | ||
| 84 | - $oDocument->setMinorVersionNumber(0); | ||
| 85 | - } else if ($fCheckInType == "minor") { | ||
| 86 | - $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - // update it | ||
| 90 | - if ($oDocument->update()) { | ||
| 91 | - | ||
| 92 | - // create the document transaction record | ||
| 93 | - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); | ||
| 94 | - // TODO: check transaction creation status? | ||
| 95 | - $oDocumentTransaction->create(); | 67 | + // update the document with the uploaded one |
| 68 | + if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { | ||
| 69 | + // remove the backup | ||
| 70 | + unlink($sBackupPath); | ||
| 96 | 71 | ||
| 97 | - // fire subscription alerts for the checked in document | ||
| 98 | - $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), | ||
| 99 | - SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 100 | - array( "modifiedDocumentName" => $oDocument->getName() )); | ||
| 101 | - $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); | ||
| 102 | - | ||
| 103 | - //redirect to the document view page | ||
| 104 | - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | 72 | + // now update the database |
| 73 | + // overwrite size | ||
| 74 | + $oDocument->setFileSize($_FILES['fFile']['size']); | ||
| 75 | + // update modified date | ||
| 76 | + $oDocument->setLastModifiedDate(getCurrentDateTime()); | ||
| 77 | + // flip the check out status | ||
| 78 | + $oDocument->setIsCheckedOut(false); | ||
| 79 | + // clear the checked in user id | ||
| 80 | + $oDocument->setCheckedOutUserID(-1); | ||
| 81 | + // bump the version numbers | ||
| 82 | + if ($fCheckInType == "major") { | ||
| 83 | + // major version number rollover | ||
| 84 | + $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); | ||
| 85 | + // reset minor version number | ||
| 86 | + $oDocument->setMinorVersionNumber(0); | ||
| 87 | + } else if ($fCheckInType == "minor") { | ||
| 88 | + $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + // update it | ||
| 92 | + if ($oDocument->update()) { | ||
| 93 | + | ||
| 94 | + // create the document transaction record | ||
| 95 | + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); | ||
| 96 | + // TODO: check transaction creation status? | ||
| 97 | + $oDocumentTransaction->create(); | ||
| 98 | + | ||
| 99 | + // fire subscription alerts for the checked in document | ||
| 100 | + $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), | ||
| 101 | + SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 102 | + array( "modifiedDocumentName" => $oDocument->getName() )); | ||
| 103 | + $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); | ||
| 104 | + | ||
| 105 | + //redirect to the document view page | ||
| 106 | + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 107 | + } else { | ||
| 108 | + // document update failed | ||
| 109 | + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing this document in the database")); | ||
| 110 | + } | ||
| 105 | } else { | 111 | } else { |
| 106 | - // document update failed | ||
| 107 | - $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing this document in the database")); | 112 | + // reinstate the backup |
| 113 | + copy($sBackupPath, $oDocument->getPath()); | ||
| 114 | + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem")); | ||
| 108 | } | 115 | } |
| 109 | } else { | 116 | } else { |
| 110 | - // reinstate the backup | ||
| 111 | - copy($sBackupPath, $oDocument->getPath()); | ||
| 112 | - $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem")); | 117 | + $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; |
| 118 | + $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); | ||
| 113 | } | 119 | } |
| 114 | } else { | 120 | } else { |
| 115 | - $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; | 121 | + // prompt the user for a check in comment and the file |
| 116 | $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); | 122 | $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); |
| 117 | } | 123 | } |
| 118 | } else { | 124 | } else { |
| 119 | - // prompt the user for a check in comment and the file | ||
| 120 | - $oPatternCustom->setHtml(getCheckInEditPage($oDocument)); | 125 | + // you don't have this doc checked out |
| 126 | + $oPatternCustom->setHtml(renderErrorPage("You can't check in this document because its checked out by " . User::getName($oDocument->getCheckedOutUserID()))); | ||
| 121 | } | 127 | } |
| 122 | } else { | 128 | } else { |
| 123 | // this document isn't checked out | 129 | // this document isn't checked out |
| 124 | $oPatternCustom->setHtml(renderErrorPage("You can't check in this document because its not checked out")); | 130 | $oPatternCustom->setHtml(renderErrorPage("You can't check in this document because its not checked out")); |
| 125 | - | ||
| 126 | } | 131 | } |
| 127 | } else { | 132 | } else { |
| 128 | // no permission to checkout the document | 133 | // no permission to checkout the document |