Commit 776d168937be65d82a4e9f002289f34f5d85da9a

Authored by Michael Joseph
1 parent 64333537

checking that the file uploaded matches the filename currently in the dms


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2256 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php
@@ -61,60 +61,66 @@ if (checkSession()) { @@ -61,60 +61,66 @@ if (checkSession()) {
61 if ($fForStore) { 61 if ($fForStore) {
62 // make sure the user actually selected a file first 62 // make sure the user actually selected a file first
63 if (strlen($_FILES['fFile']['name']) > 0) { 63 if (strlen($_FILES['fFile']['name']) > 0) {
64 -  
65 - // save the original document  
66 - $sBackupPath = $oDocument->getPath() . "-" . $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();  
67 - copy($oDocument->getPath(), $sBackupPath);  
68 -  
69 - // update the document with the uploaded one  
70 - if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) {  
71 - // now update the database  
72 - // overwrite size  
73 - $oDocument->setFileSize($_FILES['fFile']['size']);  
74 - // update modified date  
75 - $oDocument->setLastModifiedDate(getCurrentDateTime());  
76 - // flip the check out status  
77 - $oDocument->setIsCheckedOut(false);  
78 - // clear the checked in user id  
79 - $oDocument->setCheckedOutUserID(-1);  
80 - // bump the version numbers  
81 - if ($fCheckInType == "major") {  
82 - // major version number rollover  
83 - $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1);  
84 - // reset minor version number  
85 - $oDocument->setMinorVersionNumber(0);  
86 - } else if ($fCheckInType == "minor") {  
87 - $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1);  
88 - }  
89 -  
90 - // update it  
91 - if ($oDocument->update()) {  
92 -  
93 - // create the document transaction record  
94 - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN);  
95 - // TODO: check transaction creation status?  
96 - $oDocumentTransaction->create();  
97 -  
98 - // fire subscription alerts for the checked in document  
99 - $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"),  
100 - SubscriptionConstants::subscriptionType("DocumentSubscription"),  
101 - array( "folderID" => $oDocument->getFolderID(),  
102 - "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 - }  
111 - } else {  
112 - // reinstate the backup  
113 - copy($sBackupPath, $oDocument->getPath());  
114 - // remove the backup  
115 - unlink($sBackupPath);  
116 - $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem"));  
117 - } 64 + // and that the filename matches
  65 + $default->log->info("checkInDocumentBL.php uploaded filename=" . $_FILES['fFile']['name'] . "; current filename=" . $oDocument->getFileName());
  66 + if ($oDocument->getFileName() == $_FILES['fFile']['name']) {
  67 + // save the original document
  68 + $sBackupPath = $oDocument->getPath() . "-" . $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();
  69 + copy($oDocument->getPath(), $sBackupPath);
  70 +
  71 + // update the document with the uploaded one
  72 + if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) {
  73 + // now update the database
  74 + // overwrite size
  75 + $oDocument->setFileSize($_FILES['fFile']['size']);
  76 + // update modified date
  77 + $oDocument->setLastModifiedDate(getCurrentDateTime());
  78 + // flip the check out status
  79 + $oDocument->setIsCheckedOut(false);
  80 + // clear the checked in user id
  81 + $oDocument->setCheckedOutUserID(-1);
  82 + // bump the version numbers
  83 + if ($fCheckInType == "major") {
  84 + // major version number rollover
  85 + $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1);
  86 + // reset minor version number
  87 + $oDocument->setMinorVersionNumber(0);
  88 + } else if ($fCheckInType == "minor") {
  89 + $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1);
  90 + }
  91 +
  92 + // update it
  93 + if ($oDocument->update()) {
  94 +
  95 + // create the document transaction record
  96 + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN);
  97 + // TODO: check transaction creation status?
  98 + $oDocumentTransaction->create();
  99 +
  100 + // fire subscription alerts for the checked in document
  101 + $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"),
  102 + SubscriptionConstants::subscriptionType("DocumentSubscription"),
  103 + array( "folderID" => $oDocument->getFolderID(),
  104 + "modifiedDocumentName" => $oDocument->getName() ));
  105 + $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName());
  106 +
  107 + //redirect to the document view page
  108 + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID());
  109 + } else {
  110 + // document update failed
  111 + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing this document in the database"));
  112 + }
  113 + } else {
  114 + // reinstate the backup
  115 + copy($sBackupPath, $oDocument->getPath());
  116 + // remove the backup
  117 + unlink($sBackupPath);
  118 + $oPatternCustom->setHtml(renderErrorPage("An error occurred while storing the new file on the filesystem"));
  119 + }
  120 + } else {
  121 + $sErrorMessage = "The file you selected does not match the current filename in the DMS. Please try again.";
  122 + $oPatternCustom->setHtml(getCheckInPage($oDocument));
  123 + }
118 } else { 124 } else {
119 $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; 125 $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'";
120 $oPatternCustom->setHtml(getCheckInPage($oDocument)); 126 $oPatternCustom->setHtml(getCheckInPage($oDocument));