Commit 6af4e62d6505d332b381a45c0ae8a35404007bcc
1 parent
58c7b861
KTS-2721
"Refactor adding a document to use the storage manager" Fixed. Removed all references to KTFSFileLike. Added a function to the storagemanager for uploading a temp file. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7731 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
89 additions
and
53 deletions
ktapi/KTAPIFolder.inc.php
| ... | ... | @@ -478,7 +478,8 @@ class KTAPI_Folder extends KTAPI_FolderItem |
| 478 | 478 | |
| 479 | 479 | |
| 480 | 480 | $options = array( |
| 481 | - 'contents' => new KTFSFileLike($tempfilename), | |
| 481 | + //'contents' => new KTFSFileLike($tempfilename), | |
| 482 | + 'temp_file' => $tempfilename, | |
| 482 | 483 | 'novalidate' => true, |
| 483 | 484 | 'documenttype' => DocumentType::get($documenttypeid), |
| 484 | 485 | 'description' => $title, | ... | ... |
ktwebdav/lib/KTWebDAVServer.inc.php
| ... | ... | @@ -1371,9 +1371,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server |
| 1371 | 1371 | ); |
| 1372 | 1372 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); |
| 1373 | 1373 | |
| 1374 | - include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 1374 | + //include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 1375 | 1375 | $aOptions = array( |
| 1376 | - 'contents' => new KTFSFileLike($sTempFilename), | |
| 1376 | + //'contents' => new KTFSFileLike($sTempFilename), | |
| 1377 | + 'temp_file' => $sTempFilename, | |
| 1377 | 1378 | 'metadata' => array(), |
| 1378 | 1379 | 'novalidate' => true, |
| 1379 | 1380 | ); |
| ... | ... | @@ -1427,9 +1428,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server |
| 1427 | 1428 | ); |
| 1428 | 1429 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); |
| 1429 | 1430 | |
| 1430 | - include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 1431 | + //include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 1431 | 1432 | $aOptions = array( |
| 1432 | - 'contents' => new KTFSFileLike($sTempFilename), | |
| 1433 | + //'contents' => new KTFSFileLike($sTempFilename), | |
| 1434 | + 'temp_file' => $sTempFilename, | |
| 1433 | 1435 | 'metadata' => array(), |
| 1434 | 1436 | 'novalidate' => true, |
| 1435 | 1437 | ); | ... | ... |
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -234,7 +234,7 @@ class KTDocumentUtil { |
| 234 | 234 | function &_add($oFolder, $sFilename, $oUser, $aOptions) { |
| 235 | 235 | global $default; |
| 236 | 236 | |
| 237 | - $oContents = KTUtil::arrayGet($aOptions, 'contents'); | |
| 237 | + //$oContents = KTUtil::arrayGet($aOptions, 'contents'); | |
| 238 | 238 | $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false); |
| 239 | 239 | $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype'); |
| 240 | 240 | $sDescription = KTUtil::arrayGet($aOptions, 'description', $sFilename); |
| ... | ... | @@ -256,20 +256,20 @@ class KTDocumentUtil { |
| 256 | 256 | 'documenttypeid' => $iDocumentTypeId, |
| 257 | 257 | )); |
| 258 | 258 | |
| 259 | - if (is_null($oContents)) { | |
| 260 | - $res = KTDocumentUtil::setIncomplete($oDocument, 'contents'); | |
| 261 | - if (PEAR::isError($res)) { | |
| 262 | - $oDocument->delete(); | |
| 263 | - return $res; | |
| 264 | - } | |
| 265 | - } else { | |
| 259 | +// if (is_null($oContents)) { | |
| 260 | +// $res = KTDocumentUtil::setIncomplete($oDocument, 'contents'); | |
| 261 | +// if (PEAR::isError($res)) { | |
| 262 | +// $oDocument->delete(); | |
| 263 | +// return $res; | |
| 264 | +// } | |
| 265 | +// } else { | |
| 266 | 266 | // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents'))); |
| 267 | - $res = KTDocumentUtil::storeContents($oDocument, $oContents, $aOptions); | |
| 267 | + $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions); | |
| 268 | 268 | if (PEAR::isError($res)) { |
| 269 | 269 | $oDocument->delete(); |
| 270 | 270 | return $res; |
| 271 | 271 | } |
| 272 | - } | |
| 272 | +// } | |
| 273 | 273 | |
| 274 | 274 | if (is_null($aMetadata)) { |
| 275 | 275 | $res = KTDocumentUtil::setIncomplete($oDocument, 'metadata'); |
| ... | ... | @@ -694,7 +694,7 @@ class KTDocumentUtil { |
| 694 | 694 | /** |
| 695 | 695 | * Stores contents (filelike) from source into the document storage |
| 696 | 696 | */ |
| 697 | - function storeContents(&$oDocument, $oContents, $aOptions = null) { | |
| 697 | + function storeContents(&$oDocument, $oContents = null, $aOptions = null) { | |
| 698 | 698 | if (is_null($aOptions)) { |
| 699 | 699 | $aOptions = array(); |
| 700 | 700 | } |
| ... | ... | @@ -704,17 +704,20 @@ class KTDocumentUtil { |
| 704 | 704 | $oKTConfig =& KTConfig::getSingleton(); |
| 705 | 705 | $sBasedir = $oKTConfig->get('urls/tmpDirectory'); |
| 706 | 706 | |
| 707 | - $sFilename = tempnam($sBasedir, 'kt_storecontents'); | |
| 708 | - $oOutputFile = new KTFSFileLike($sFilename); | |
| 709 | - $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | |
| 710 | - if (($res === false)) { | |
| 711 | - return PEAR::raiseError(_kt("Couldn't store contents, and no reason given.")); | |
| 712 | - } else if (PEAR::isError($res)) { | |
| 713 | - return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); | |
| 714 | - } | |
| 707 | + $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : tempnam($sBasedir, 'kt_storecontents'); | |
| 708 | + | |
| 709 | +// $oOutputFile = new KTFSFileLike($sFilename); | |
| 710 | +// $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | |
| 711 | +// if (($res === false)) { | |
| 712 | +// return PEAR::raiseError(_kt("Couldn't store contents, and no reason given.")); | |
| 713 | +// } else if (PEAR::isError($res)) { | |
| 714 | +// return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); | |
| 715 | +// } | |
| 716 | + | |
| 715 | 717 | $sType = KTMime::getMimeTypeFromFile($sFilename); |
| 716 | 718 | $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); |
| 717 | 719 | $oDocument->setMimeTypeId($iMimeTypeId); |
| 720 | + | |
| 718 | 721 | $res = $oStorage->upload($oDocument, $sFilename); |
| 719 | 722 | if ($res === false) { |
| 720 | 723 | return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('No reason given'))); |
| ... | ... | @@ -725,7 +728,7 @@ class KTDocumentUtil { |
| 725 | 728 | KTDocumentUtil::setComplete($oDocument, 'contents'); |
| 726 | 729 | |
| 727 | 730 | if ($aOptions['cleanup_initial_file']) { |
| 728 | - @unlink($oContents->sFilename); | |
| 731 | + @unlink($sFilename); | |
| 729 | 732 | } |
| 730 | 733 | |
| 731 | 734 | return true; | ... | ... |
lib/storage/ondiskhashedstoragemanager.inc.php
| ... | ... | @@ -8,32 +8,32 @@ |
| 8 | 8 | * KnowledgeTree Open Source Edition |
| 9 | 9 | * Document Management Made Simple |
| 10 | 10 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 11 | - * | |
| 11 | + * | |
| 12 | 12 | * This program is free software; you can redistribute it and/or modify it under |
| 13 | 13 | * the terms of the GNU General Public License version 3 as published by the |
| 14 | 14 | * Free Software Foundation. |
| 15 | - * | |
| 15 | + * | |
| 16 | 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 19 | 19 | * details. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You should have received a copy of the GNU General Public License |
| 22 | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 25 | 25 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 26 | - * | |
| 26 | + * | |
| 27 | 27 | * The interactive user interfaces in modified source and object code versions |
| 28 | 28 | * of this program must display Appropriate Legal Notices, as required under |
| 29 | 29 | * Section 5 of the GNU General Public License version 3. |
| 30 | - * | |
| 30 | + * | |
| 31 | 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 32 | 32 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 33 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 33 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 34 | 34 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 35 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 36 | - * copyright notice. | |
| 35 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 36 | + * copyright notice. | |
| 37 | 37 | * Contributor( s): ______________________________________ |
| 38 | 38 | */ |
| 39 | 39 | |
| ... | ... | @@ -77,6 +77,29 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | + /** | |
| 81 | + * Upload a temporary file | |
| 82 | + * | |
| 83 | + * @param unknown_type $sUploadedFile | |
| 84 | + * @param unknown_type $sTmpFilePath | |
| 85 | + * @return unknown | |
| 86 | + */ | |
| 87 | + function uploadTmpFile($sUploadedFile, $sTmpFilePath) { | |
| 88 | + | |
| 89 | + //copy the file accross | |
| 90 | + if (OS_WINDOWS) { | |
| 91 | + $sTmpFilePath = str_replace('\\','/',$sTmpFilePath); | |
| 92 | + } | |
| 93 | + if ($this->writeToFile($sUploadedFile, $sTmpFilePath)) { | |
| 94 | + if (file_exists($sTmpFilePath)) { | |
| 95 | + return true; | |
| 96 | + } else { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + } | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | + | |
| 80 | 103 | function writeToFile($sTmpFilePath, $sDocumentFileSystemPath) { |
| 81 | 104 | // Make it easy to write compressed/encrypted storage |
| 82 | 105 | |
| ... | ... | @@ -318,7 +341,7 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { |
| 318 | 341 | $sDocumentRoot = $oConfig->get('urls/documentRoot'); |
| 319 | 342 | $iContentId = $oVersion->getContentVersionId(); |
| 320 | 343 | $oContentVersion = KTDocumentContentVersion::get($iContentId); |
| 321 | - | |
| 344 | + | |
| 322 | 345 | $sPath = $oContentVersion->getStoragePath(); |
| 323 | 346 | $sFullPath = sprintf("%s/%s", $sDocumentRoot, $sPath); |
| 324 | 347 | if (file_exists($sFullPath)) { | ... | ... |
plugins/ktcore/folder/addDocument.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -193,14 +193,20 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 193 | 193 | $sBasedir = $oKTConfig->get("urls/tmpDirectory"); |
| 194 | 194 | |
| 195 | 195 | $sFilename = tempnam($sBasedir, 'kt_storecontents'); |
| 196 | - $oContents = new KTFSFileLike($data['file']['tmp_name']); | |
| 197 | - $oOutputFile = new KTFSFileLike($sFilename); | |
| 198 | - $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | |
| 199 | - $data['file']['tmp_name'] = $sFilename; | |
| 200 | 196 | |
| 201 | - if (PEAR::isError($res)) { | |
| 202 | - $oForm->handleError(sprintf(_kt("Failed to store file: %s"), $res->getMessage())); | |
| 203 | - } | |
| 197 | + //$oContents = new KTFSFileLike($data['file']['tmp_name']); | |
| 198 | + //$oOutputFile = new KTFSFileLike($sFilename); | |
| 199 | + //$res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | |
| 200 | + | |
| 201 | + //if (PEAR::isError($res)) { | |
| 202 | + // $oForm->handleError(sprintf(_kt("Failed to store file: %s"), $res->getMessage())); | |
| 203 | + //} | |
| 204 | + | |
| 205 | + | |
| 206 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | |
| 207 | + $oStorage->uploadTmpFile($data['file']['tmp_name'], $sFilename); | |
| 208 | + | |
| 209 | + $data['file']['tmp_name'] = $sFilename; | |
| 204 | 210 | $_SESSION['_add_data'] = array($key => $data); |
| 205 | 211 | |
| 206 | 212 | // if we don't need metadata |
| ... | ... | @@ -294,7 +300,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 294 | 300 | $oUploadChannel->addObserver($mpo); |
| 295 | 301 | |
| 296 | 302 | require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); |
| 297 | - require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 303 | + //require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 298 | 304 | require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); |
| 299 | 305 | require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); |
| 300 | 306 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); |
| ... | ... | @@ -309,7 +315,8 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 309 | 315 | |
| 310 | 316 | $iFolderId = $this->oFolder->getId(); |
| 311 | 317 | $aOptions = array( |
| 312 | - 'contents' => new KTFSFileLike($aFile['tmp_name']), | |
| 318 | + // 'contents' => new KTFSFileLike($aFile['tmp_name']), | |
| 319 | + 'temp_file' => $aFile['tmp_name'], | |
| 313 | 320 | 'documenttype' => DocumentType::get($extra_d['document_type']), |
| 314 | 321 | 'metadata' => $MDPack, |
| 315 | 322 | 'description' => $sTitle, | ... | ... |