Commit e8c67fdea56e0a70ebb404151cbeea97f241898a
1 parent
b0f18625
Simplify logic to prevent many nested ifs, and use DocumentUtil for
check-in process. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3531 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
109 additions
and
136 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php
| @@ -29,151 +29,124 @@ | @@ -29,151 +29,124 @@ | ||
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | require_once("../../../../config/dmsDefaults.php"); | 31 | require_once("../../../../config/dmsDefaults.php"); |
| 32 | +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | ||
| 32 | 33 | ||
| 33 | KTUtil::extractGPC('fDocumentID', 'fForStore', 'fFolderID', 'fCheckInComment', 'fCheckInType'); | 34 | KTUtil::extractGPC('fDocumentID', 'fForStore', 'fFolderID', 'fCheckInComment', 'fCheckInType'); |
| 34 | 35 | ||
| 35 | -if (checkSession()) { | ||
| 36 | - require_once("$default->fileSystemRoot/lib/email/Email.inc"); | ||
| 37 | - | ||
| 38 | - require_once("$default->fileSystemRoot/lib/users/User.inc"); | ||
| 39 | - | ||
| 40 | - require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 41 | - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 42 | - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 43 | - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentCollaboration.inc"); | ||
| 44 | - | ||
| 45 | - require_once("$default->fileSystemRoot/lib/foldermanagement/FolderCollaboration.inc"); | ||
| 46 | - require_once("$default->fileSystemRoot/lib/foldermanagement/FolderUserRole.inc"); | ||
| 47 | - require_once("$default->fileSystemRoot/lib/roles/Role.inc"); | ||
| 48 | - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 49 | - | ||
| 50 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListFromQuery.inc"); | ||
| 51 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | ||
| 52 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 53 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListFromQuery.inc"); | ||
| 54 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | ||
| 55 | - | ||
| 56 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentUI.inc"); | ||
| 57 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/documentUI.inc"); | ||
| 58 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewUI.inc"); | ||
| 59 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 60 | - require_once("$default->fileSystemRoot/presentation/Html.inc"); | ||
| 61 | - | ||
| 62 | - require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | 36 | +if (!checkSession()) { |
| 37 | + die("Session not set up"); | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +require_once("$default->fileSystemRoot/lib/email/Email.inc"); | ||
| 41 | + | ||
| 42 | +require_once("$default->fileSystemRoot/lib/users/User.inc"); | ||
| 43 | + | ||
| 44 | +require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 45 | +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 46 | +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 47 | +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentCollaboration.inc"); | ||
| 48 | + | ||
| 49 | +require_once("$default->fileSystemRoot/lib/foldermanagement/FolderCollaboration.inc"); | ||
| 50 | +require_once("$default->fileSystemRoot/lib/foldermanagement/FolderUserRole.inc"); | ||
| 51 | +require_once("$default->fileSystemRoot/lib/roles/Role.inc"); | ||
| 52 | +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 53 | + | ||
| 54 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListFromQuery.inc"); | ||
| 55 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | ||
| 56 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 57 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListFromQuery.inc"); | ||
| 58 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | ||
| 59 | + | ||
| 60 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentUI.inc"); | ||
| 61 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/documentUI.inc"); | ||
| 62 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/viewUI.inc"); | ||
| 63 | +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 64 | +require_once("$default->fileSystemRoot/presentation/Html.inc"); | ||
| 63 | 65 | ||
| 66 | +require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | ||
| 67 | + | ||
| 68 | +function checkinDocument() { | ||
| 64 | $oPatternCustom = & new PatternCustom(); | 69 | $oPatternCustom = & new PatternCustom(); |
| 65 | - | ||
| 66 | - if (isset($fDocumentID)) { | ||
| 67 | - // instantiate the document | ||
| 68 | - $oDocument = & Document::get($fDocumentID); | ||
| 69 | - if ($oDocument) { | ||
| 70 | - // user has permission to check the document in | ||
| 71 | - if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 72 | - // and the document is checked out | ||
| 73 | - if ($oDocument->getIsCheckedOut()) { | ||
| 74 | - // by you | ||
| 75 | - if ($oDocument->getCheckedOutUserID() == $_SESSION["userID"]) { | ||
| 76 | - // if we're ready to perform the updates | ||
| 77 | - if ($fForStore) { | ||
| 78 | - // make sure the user actually selected a file first | ||
| 79 | - if (strlen($_FILES['fFile']['name']) > 0) { | ||
| 80 | - // and that the filename matches | ||
| 81 | - $default->log->info("checkInDocumentBL.php uploaded filename=" . $_FILES['fFile']['name'] . "; current filename=" . $oDocument->getFileName()); | ||
| 82 | - if ($oDocument->getFileName() == $_FILES['fFile']['name']) { | ||
| 83 | - // save the original document | ||
| 84 | - $sBackupPath = $oDocument->getPath() . "-" . $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber(); | ||
| 85 | - copy($oDocument->getPath(), $sBackupPath); | ||
| 86 | - | ||
| 87 | - // update the document with the uploaded one | ||
| 88 | - if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { | ||
| 89 | - // now update the database | ||
| 90 | - // overwrite size | ||
| 91 | - $oDocument->setFileSize($_FILES['fFile']['size']); | ||
| 92 | - // update modified date | ||
| 93 | - $oDocument->setLastModifiedDate(getCurrentDateTime()); | ||
| 94 | - // flip the check out status | ||
| 95 | - $oDocument->setIsCheckedOut(false); | ||
| 96 | - // clear the checked in user id | ||
| 97 | - $oDocument->setCheckedOutUserID(-1); | ||
| 98 | - // bump the version numbers | ||
| 99 | - if ($fCheckInType == "major") { | ||
| 100 | - // major version number rollover | ||
| 101 | - $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); | ||
| 102 | - // reset minor version number | ||
| 103 | - $oDocument->setMinorVersionNumber(0); | ||
| 104 | - } else if ($fCheckInType == "minor") { | ||
| 105 | - $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - // update it | ||
| 109 | - if ($oDocument->update()) { | ||
| 110 | - | ||
| 111 | - // create the document transaction record | ||
| 112 | - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); | ||
| 113 | - // TODO: check transaction creation status? | ||
| 114 | - $oDocumentTransaction->create(); | ||
| 115 | - | ||
| 116 | - // fire subscription alerts for the checked in document | ||
| 117 | - $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), | ||
| 118 | - SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 119 | - array( "folderID" => $oDocument->getFolderID(), | ||
| 120 | - "modifiedDocumentName" => $oDocument->getName() )); | ||
| 121 | - $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); | ||
| 122 | - | ||
| 123 | - //redirect to the document view page | ||
| 124 | - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 125 | - } else { | ||
| 126 | - // document update failed | ||
| 127 | - $oPatternCustom->setHtml(renderErrorPage(_("An error occurred while storing this document in the database"))); | ||
| 128 | - } | ||
| 129 | - } else { | ||
| 130 | - // reinstate the backup | ||
| 131 | - copy($sBackupPath, $oDocument->getPath()); | ||
| 132 | - // remove the backup | ||
| 133 | - unlink($sBackupPath); | ||
| 134 | - $oPatternCustom->setHtml(renderErrorPage(_("An error occurred while storing the new file on the filesystem"))); | ||
| 135 | - } | ||
| 136 | - } else { | ||
| 137 | - $sErrorMessage = _("The file you selected does not match the current filename in the DMS. Please try again."); | ||
| 138 | - $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 139 | - } | ||
| 140 | - } else { | ||
| 141 | - $sErrorMessage = _("Please select a document by first clicking on 'Browse'. Then click 'Check-In'"); | ||
| 142 | - $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 143 | - } | ||
| 144 | - } else { | ||
| 145 | - // prompt the user for a check in comment and the file | ||
| 146 | - $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 147 | - } | ||
| 148 | - } else { | ||
| 149 | - // you don't have this doc checked out | ||
| 150 | - $oUser = User::get($oDocument->getCheckedOutUserID()); | ||
| 151 | - $oPatternCustom->setHtml(renderErrorPage(_("You can't check in this document because its checked out by") . $oUser->getName())); | ||
| 152 | - } | ||
| 153 | - } else { | ||
| 154 | - // this document isn't checked out | ||
| 155 | - $oPatternCustom->setHtml(renderErrorPage(_("You can't check in this document because its not checked out"))); | ||
| 156 | - } | ||
| 157 | - } else { | ||
| 158 | - // no permission to checkout the document | ||
| 159 | - $oPatternCustom->setHtml(renderErrorPage(_("You do not have permission to check in this document"))); | ||
| 160 | - } | ||
| 161 | - } else { | ||
| 162 | - // couldn't instantiate the document | ||
| 163 | - $oPatternCustom->setHtml(renderErrorPage(_("Could not check in this document"))); | ||
| 164 | - } | ||
| 165 | - } else { | 70 | + |
| 71 | + $iDocumentID = KTUtil::arrayGet($_REQUEST, 'fDocumentID'); | ||
| 72 | + | ||
| 73 | + if (empty($iDocumentID)) { | ||
| 166 | // no document id was set when coming to this page, | 74 | // no document id was set when coming to this page, |
| 167 | $oPatternCustom->setHtml(renderErrorPage(_("No document is currently selected for check in"))); | 75 | $oPatternCustom->setHtml(renderErrorPage(_("No document is currently selected for check in"))); |
| 76 | + return $oPatternCustom; | ||
| 77 | + } | ||
| 78 | + // instantiate the document | ||
| 79 | + $oDocument = & Document::get($iDocumentID); | ||
| 80 | + | ||
| 81 | + if (!$oDocument) { | ||
| 82 | + // couldn't instantiate the document | ||
| 83 | + $oPatternCustom->setHtml(renderErrorPage(_("Could not check in this document"))); | ||
| 84 | + return $oPatternCustom; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // user has permission to check the document in | ||
| 88 | + if (!Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 89 | + // no permission to checkout the document | ||
| 90 | + $oPatternCustom->setHtml(renderErrorPage(_("You do not have permission to check in this document"))); | ||
| 91 | + return $oPatternCustom; | ||
| 168 | } | 92 | } |
| 169 | 93 | ||
| 170 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 171 | - $main->setCentralPayload($oPatternCustom); | ||
| 172 | - $main->setFormAction($_SERVER["PHP_SELF"]); | ||
| 173 | - $main->setFormEncType("multipart/form-data"); | ||
| 174 | - if (isset($sErrorMessage)) { | ||
| 175 | - $main->setErrorMessage($sErrorMessage); | 94 | + // and the document is checked out |
| 95 | + if (!$oDocument->getIsCheckedOut()) { | ||
| 96 | + $oPatternCustom->setHtml(renderErrorPage(_("You can't check in this document because its not checked out"))); | ||
| 97 | + return $oPatternCustom; | ||
| 176 | } | 98 | } |
| 177 | - $main->render(); | 99 | + |
| 100 | + // by you | ||
| 101 | + if ($oDocument->getCheckedOutUserID() != $_SESSION["userID"]) { | ||
| 102 | + // you don't have this doc checked out | ||
| 103 | + $oUser = User::get($oDocument->getCheckedOutUserID()); | ||
| 104 | + $oPatternCustom->setHtml(renderErrorPage(_("You can't check in this document because its checked out by") . $oUser->getName())); | ||
| 105 | + return $oPatternCustom; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + // if we're ready to perform the updates | ||
| 109 | + $bForStore = KTUtil::arrayGet($_REQUEST, 'fForStore'); | ||
| 110 | + if (! $bForStore) { | ||
| 111 | + // prompt the user for a check in comment and the file | ||
| 112 | + $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 113 | + return $oPatternCustom; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + // make sure the user actually selected a file first | ||
| 117 | + if (strlen($_FILES['fFile']['name']) == 0) { | ||
| 118 | + $sErrorMessage = _("Please select a document by first clicking on 'Browse'. Then click 'Check-In'"); | ||
| 119 | + $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 120 | + return $oPatternCustom; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + // and that the filename matches | ||
| 124 | + global $default; | ||
| 125 | + $default->log->info("checkInDocumentBL.php uploaded filename=" . $_FILES['fFile']['name'] . "; current filename=" . $oDocument->getFileName()); | ||
| 126 | + if ($oDocument->getFileName() != $_FILES['fFile']['name']) { | ||
| 127 | + $sErrorMessage = _("The file you selected does not match the current filename in the DMS. Please try again."); | ||
| 128 | + $oPatternCustom->setHtml(getCheckInPage($oDocument)); | ||
| 129 | + return $oPatternCustom; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + $sCheckInComment = KTUtil::arrayGet($_REQUEST, 'fCheckInComment'); | ||
| 133 | + $sCheckInType = KTUtil::arrayGet($_REQUEST, 'fCheckInType'); | ||
| 134 | + $res = KTDocumentUtil::checkin($oDocument, $_FILES['fFile']['tmp_name'], $sCheckInComment, $sCheckInType); | ||
| 135 | + if (PEAR::isError($res)) { | ||
| 136 | + $oPatternCustom->setHtml(getErrorPage($res)); | ||
| 137 | + return $oPatternCustom; | ||
| 138 | + } | ||
| 139 | + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 178 | } | 140 | } |
| 141 | + | ||
| 142 | +require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 143 | +$oPatternCustom = checkinDocument(); | ||
| 144 | +$main->setCentralPayload($oPatternCustom); | ||
| 145 | +$main->setFormAction($_SERVER["PHP_SELF"]); | ||
| 146 | +$main->setFormEncType("multipart/form-data"); | ||
| 147 | +if (isset($sErrorMessage)) { | ||
| 148 | + $main->setErrorMessage($sErrorMessage); | ||
| 149 | +} | ||
| 150 | +$main->render(); | ||
| 151 | + | ||
| 179 | ?> | 152 | ?> |