Commit 4c9030bd71ca4122cf2aa4342c35ee6a3071055a

Authored by nbm
1 parent 7832b33c

Make use of KTDocumentUtil::add to add a document.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3615 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php
@@ -36,11 +36,8 @@ if (!checkSession()) { @@ -36,11 +36,8 @@ if (!checkSession()) {
36 exit(0); 36 exit(0);
37 } 37 }
38 38
39 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc");  
40 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc");  
41 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc");  
42 -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");  
43 -require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); 39 +require_once(KT_LIB_DIR . '/visualpatterns/PatternCustom.inc');
  40 +require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc');
44 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); 41 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
45 require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentInstance.inc"); 42 require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentInstance.inc");
46 require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); 43 require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc");
@@ -54,6 +51,9 @@ require_once("addDocumentUI.inc"); @@ -54,6 +51,9 @@ require_once("addDocumentUI.inc");
54 require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); 51 require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc");
55 52
56 require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); 53 require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php');
  54 +require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php');
  55 +require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc');
  56 +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
57 57
58 $oStorage =& KTStorageManagerUtil::getSingleton(); 58 $oStorage =& KTStorageManagerUtil::getSingleton();
59 59
@@ -148,70 +148,25 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { @@ -148,70 +148,25 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) {
148 exit(0); 148 exit(0);
149 } 149 }
150 150
151 -//if the user selected a file to upload  
152 -//create the document in the database  
153 -$oDocument = & PhysicalDocumentManager::createDocumentFromUploadedFile($_FILES['fFile'], $fFolderID);  
154 -// set the document title  
155 -$oDocument->setName($fName);  
156 -// set the document type id  
157 -$oDocument->setDocumentTypeID($fDocumentTypeID); 151 +$aOptions = array(
  152 + 'contents' => new KTFSFileLike($_FILES['fFile']['tmp_name']),
  153 + 'documenttype' => DocumentType::get($fDocumentTypeID),
  154 +);
158 155
159 -if (Document::documentExists($oDocument->getFileName(), $oDocument->getFolderID())) {  
160 - // document already exists in folder  
161 - $default->log->error("addDocumentBL.php Document exists with name " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID");  
162 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
163 - $oPatternCustom = & new PatternCustom();  
164 - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("A document with this file name already exists in this folder") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>"));  
165 - $main->setCentralPayload($oPatternCustom);  
166 - $main->render();  
167 - exit(0);  
168 -}  
169 -  
170 -if (!$oDocument->create()) {  
171 - // couldn't store document on fs  
172 - $default->log->error("addDocumentBL.php DB error storing document in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID");  
173 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
174 - $oPatternCustom = & new PatternCustom();  
175 - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document in the database, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>"));  
176 - $main->setCentralPayload($oPatternCustom);  
177 - $main->render();  
178 - exit(0); 156 +function localRenderError($oDocument) {
  157 + print $oDocument->toString();
  158 + return;
179 } 159 }
180 160
181 -//if the document was successfully created in the db, then store it on the file system  
182 -if (!$oStorage->upload($oDocument, $_FILES['fFile']['tmp_name'])) {  
183 - // couldn't store document on filesystem  
184 - $default->log->error("addDocumentBL.php Filesystem error attempting to store document " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . "; id=$fFolderID");  
185 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
186 - // delete the document from the database  
187 - $oDocument->delete();  
188 - $oPatternCustom = & new PatternCustom();  
189 - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("An error occured while storing the document on the file system, please try again.") . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>"));  
190 - $main->setCentralPayload($oPatternCustom);  
191 - $main->render(); 161 +DBUtil::startTransaction();
  162 +$oUser =& User::get($_SESSION["userID"]);
  163 +$oDocument =& KTDocumentUtil::add($oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions);
  164 +if (PEAR::isError($oDocument)) {
  165 + localRenderError($oDocument);
192 exit(0); 166 exit(0);
193 } 167 }
194 -  
195 -// ALL SYSTEMS GO!  
196 -  
197 $oDocument->update(); 168 $oDocument->update();
198 169
199 -  
200 -//create the web document link  
201 -$oWebDocument = & new WebDocument($oDocument->getID(), -1, 1, NOT_PUBLISHED, getCurrentDateTime());  
202 -if ($oWebDocument->create()) {  
203 - $default->log->error("addDocumentBL.php created web document for document ID=" . $oDocument->getID());  
204 -} else {  
205 - $default->log->error("addDocumentBL.php couldn't create web document for document ID=" . $oDocument->getID());  
206 -}  
207 -//create the document transaction record  
208 -$oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE);  
209 -if ($oDocumentTransaction->create()) {  
210 - $default->log->debug("addDocumentBL.php created create document transaction for document ID=" . $oDocument->getID());  
211 -} else {  
212 - $default->log->error("addDocumentBL.php couldn't create create document transaction for document ID=" . $oDocument->getID());  
213 -}  
214 -  
215 //the document was created/uploaded due to a collaboration step in another 170 //the document was created/uploaded due to a collaboration step in another
216 //document and must be linked to that document 171 //document and must be linked to that document
217 if (isset($fDependantDocumentID)) { 172 if (isset($fDependantDocumentID)) {
@@ -252,14 +207,10 @@ for ($i=0; $i&lt;count($aQueries); $i++) { @@ -252,14 +207,10 @@ for ($i=0; $i&lt;count($aQueries); $i++) {
252 } 207 }
253 } 208 }
254 209
255 -// fire subscription alerts for the new document  
256 -$count = SubscriptionEngine::fireSubscription($fFolderID, SubscriptionConstants::subscriptionAlertType("AddDocument"),  
257 - SubscriptionConstants::subscriptionType("FolderSubscription"),  
258 - array( "newDocumentName" => $oDocument->getName(),  
259 - "folderName" => Folder::getFolderName($fFolderID)));  
260 -$default->log->info("addDocumentBL.php fired $count subscription alerts for new document " . $oDocument->getName()); 210 +KTDocumentUtil::setComplete($oDocument, 'metadata');
  211 +$oDocument->update();
261 212
262 -$default->log->info("addDocumentBL.php successfully added document " . $oDocument->getFileName() . " to folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); 213 +DBUtil::commit();
263 //redirect to the document details page 214 //redirect to the document details page
264 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); 215 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID());
265 216