Commit 262da92f9081c6d91fa18316877ae0bbb4975db8
1 parent
2208336f
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/STABLE/branches/3.4.5-Release-Branch@7730 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
119 additions
and
84 deletions
ktapi/KTAPIFolder.inc.php
| @@ -450,7 +450,8 @@ class KTAPI_Folder extends KTAPI_FolderItem | @@ -450,7 +450,8 @@ class KTAPI_Folder extends KTAPI_FolderItem | ||
| 450 | 450 | ||
| 451 | 451 | ||
| 452 | $options = array( | 452 | $options = array( |
| 453 | - 'contents' => new KTFSFileLike($tempfilename), | 453 | + //'contents' => new KTFSFileLike($tempfilename), |
| 454 | + 'temp_file' => $tempfilename, | ||
| 454 | 'novalidate' => true, | 455 | 'novalidate' => true, |
| 455 | 'documenttype' => DocumentType::get($documenttypeid), | 456 | 'documenttype' => DocumentType::get($documenttypeid), |
| 456 | 'description' => $title, | 457 | 'description' => $title, |
ktwebdav/lib/KTWebDAVServer.inc.php
| @@ -1259,9 +1259,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server | @@ -1259,9 +1259,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server | ||
| 1259 | ); | 1259 | ); |
| 1260 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); | 1260 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); |
| 1261 | 1261 | ||
| 1262 | - include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | 1262 | + //include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); |
| 1263 | $aOptions = array( | 1263 | $aOptions = array( |
| 1264 | - 'contents' => new KTFSFileLike($sTempFilename), | 1264 | + //'contents' => new KTFSFileLike($sTempFilename), |
| 1265 | + 'temp_file' => $sTempFilename, | ||
| 1265 | 'metadata' => array(), | 1266 | 'metadata' => array(), |
| 1266 | 'novalidate' => true, | 1267 | 'novalidate' => true, |
| 1267 | ); | 1268 | ); |
| @@ -1309,9 +1310,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server | @@ -1309,9 +1310,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server | ||
| 1309 | ); | 1310 | ); |
| 1310 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); | 1311 | $this->ktwebdavLog("aFileArray is " . print_r($aFileArray, true), 'info', true); |
| 1311 | 1312 | ||
| 1312 | - include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | 1313 | + //include_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); |
| 1313 | $aOptions = array( | 1314 | $aOptions = array( |
| 1314 | - 'contents' => new KTFSFileLike($sTempFilename), | 1315 | + //'contents' => new KTFSFileLike($sTempFilename), |
| 1316 | + 'temp_file' => $sTempFilename, | ||
| 1315 | 'metadata' => array(), | 1317 | 'metadata' => array(), |
| 1316 | 'novalidate' => true, | 1318 | 'novalidate' => true, |
| 1317 | ); | 1319 | ); |
lib/documentmanagement/documentutil.inc.php
| @@ -183,7 +183,7 @@ class KTDocumentUtil { | @@ -183,7 +183,7 @@ class KTDocumentUtil { | ||
| 183 | function &_add($oFolder, $sFilename, $oUser, $aOptions) { | 183 | function &_add($oFolder, $sFilename, $oUser, $aOptions) { |
| 184 | global $default; | 184 | global $default; |
| 185 | 185 | ||
| 186 | - $oContents = KTUtil::arrayGet($aOptions, 'contents'); | 186 | + //$oContents = KTUtil::arrayGet($aOptions, 'contents'); |
| 187 | $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false); | 187 | $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false); |
| 188 | $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype'); | 188 | $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype'); |
| 189 | $sDescription = KTUtil::arrayGet($aOptions, 'description', $sFilename); | 189 | $sDescription = KTUtil::arrayGet($aOptions, 'description', $sFilename); |
| @@ -208,20 +208,20 @@ class KTDocumentUtil { | @@ -208,20 +208,20 @@ class KTDocumentUtil { | ||
| 208 | return $oDocument; | 208 | return $oDocument; |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | - if (is_null($oContents)) { | ||
| 212 | - $res = KTDocumentUtil::setIncomplete($oDocument, 'contents'); | ||
| 213 | - if (PEAR::isError($res)) { | ||
| 214 | - $oDocument->delete(); | ||
| 215 | - return $res; | ||
| 216 | - } | ||
| 217 | - } else { | 211 | +// if (is_null($oContents)) { |
| 212 | +// $res = KTDocumentUtil::setIncomplete($oDocument, 'contents'); | ||
| 213 | +// if (PEAR::isError($res)) { | ||
| 214 | +// $oDocument->delete(); | ||
| 215 | +// return $res; | ||
| 216 | +// } | ||
| 217 | +// } else { | ||
| 218 | // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents'))); | 218 | // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents'))); |
| 219 | - $res = KTDocumentUtil::storeContents($oDocument, $oContents, $aOptions); | 219 | + $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions); |
| 220 | if (PEAR::isError($res)) { | 220 | if (PEAR::isError($res)) { |
| 221 | $oDocument->delete(); | 221 | $oDocument->delete(); |
| 222 | return $res; | 222 | return $res; |
| 223 | } | 223 | } |
| 224 | - } | 224 | +// } |
| 225 | 225 | ||
| 226 | if (is_null($aMetadata)) { | 226 | if (is_null($aMetadata)) { |
| 227 | $res = KTDocumentUtil::setIncomplete($oDocument, 'metadata'); | 227 | $res = KTDocumentUtil::setIncomplete($oDocument, 'metadata'); |
| @@ -547,7 +547,7 @@ class KTDocumentUtil { | @@ -547,7 +547,7 @@ class KTDocumentUtil { | ||
| 547 | /** | 547 | /** |
| 548 | * Stores contents (filelike) from source into the document storage | 548 | * Stores contents (filelike) from source into the document storage |
| 549 | */ | 549 | */ |
| 550 | - function storeContents(&$oDocument, $oContents, $aOptions = null) { | 550 | + function storeContents(&$oDocument, $oContents = null, $aOptions = null) { |
| 551 | if (is_null($aOptions)) { | 551 | if (is_null($aOptions)) { |
| 552 | $aOptions = array(); | 552 | $aOptions = array(); |
| 553 | } | 553 | } |
| @@ -557,17 +557,20 @@ class KTDocumentUtil { | @@ -557,17 +557,20 @@ class KTDocumentUtil { | ||
| 557 | $oKTConfig =& KTConfig::getSingleton(); | 557 | $oKTConfig =& KTConfig::getSingleton(); |
| 558 | $sBasedir = $oKTConfig->get('urls/tmpDirectory'); | 558 | $sBasedir = $oKTConfig->get('urls/tmpDirectory'); |
| 559 | 559 | ||
| 560 | - $sFilename = tempnam($sBasedir, 'kt_storecontents'); | ||
| 561 | - $oOutputFile = new KTFSFileLike($sFilename); | ||
| 562 | - $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | ||
| 563 | - if (($res === false)) { | ||
| 564 | - return PEAR::raiseError(_kt("Couldn't store contents, and no reason given.")); | ||
| 565 | - } else if (PEAR::isError($res)) { | ||
| 566 | - return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); | ||
| 567 | - } | 560 | + $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : tempnam($sBasedir, 'kt_storecontents'); |
| 561 | + | ||
| 562 | +// $oOutputFile = new KTFSFileLike($sFilename); | ||
| 563 | +// $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | ||
| 564 | +// if (($res === false)) { | ||
| 565 | +// return PEAR::raiseError(_kt("Couldn't store contents, and no reason given.")); | ||
| 566 | +// } else if (PEAR::isError($res)) { | ||
| 567 | +// return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); | ||
| 568 | +// } | ||
| 569 | + | ||
| 568 | $sType = KTMime::getMimeTypeFromFile($sFilename); | 570 | $sType = KTMime::getMimeTypeFromFile($sFilename); |
| 569 | $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); | 571 | $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); |
| 570 | $oDocument->setMimeTypeId($iMimeTypeId); | 572 | $oDocument->setMimeTypeId($iMimeTypeId); |
| 573 | + | ||
| 571 | $res = $oStorage->upload($oDocument, $sFilename); | 574 | $res = $oStorage->upload($oDocument, $sFilename); |
| 572 | if ($res === false) { | 575 | if ($res === false) { |
| 573 | return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('No reason given'))); | 576 | return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('No reason given'))); |
| @@ -578,7 +581,7 @@ class KTDocumentUtil { | @@ -578,7 +581,7 @@ class KTDocumentUtil { | ||
| 578 | KTDocumentUtil::setComplete($oDocument, 'contents'); | 581 | KTDocumentUtil::setComplete($oDocument, 'contents'); |
| 579 | 582 | ||
| 580 | if ($aOptions['cleanup_initial_file']) { | 583 | if ($aOptions['cleanup_initial_file']) { |
| 581 | - @unlink($oContents->sFilename); | 584 | + @unlink($sFilename); |
| 582 | } | 585 | } |
| 583 | 586 | ||
| 584 | return true; | 587 | return true; |
lib/storage/ondiskhashedstoragemanager.inc.php
| @@ -71,6 +71,29 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { | @@ -71,6 +71,29 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { | ||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | + /** | ||
| 75 | + * Upload a temporary file | ||
| 76 | + * | ||
| 77 | + * @param unknown_type $sUploadedFile | ||
| 78 | + * @param unknown_type $sTmpFilePath | ||
| 79 | + * @return unknown | ||
| 80 | + */ | ||
| 81 | + function uploadTmpFile($sUploadedFile, $sTmpFilePath) { | ||
| 82 | + | ||
| 83 | + //copy the file accross | ||
| 84 | + if (OS_WINDOWS) { | ||
| 85 | + $sTmpFilePath = str_replace('\\','/',$sTmpFilePath); | ||
| 86 | + } | ||
| 87 | + if ($this->writeToFile($sUploadedFile, $sTmpFilePath)) { | ||
| 88 | + if (file_exists($sTmpFilePath)) { | ||
| 89 | + return true; | ||
| 90 | + } else { | ||
| 91 | + return false; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + return false; | ||
| 95 | + } | ||
| 96 | + | ||
| 74 | function writeToFile($sTmpFilePath, $sDocumentFileSystemPath) { | 97 | function writeToFile($sTmpFilePath, $sDocumentFileSystemPath) { |
| 75 | // Make it easy to write compressed/encrypted storage | 98 | // Make it easy to write compressed/encrypted storage |
| 76 | 99 | ||
| @@ -162,7 +185,7 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { | @@ -162,7 +185,7 @@ class KTOnDiskHashedStorageManager extends KTStorageManager { | ||
| 162 | } | 185 | } |
| 163 | // HTTP/1.0 | 186 | // HTTP/1.0 |
| 164 | //header("Pragma: no-cache"); // Don't send this header! It breaks IE. | 187 | //header("Pragma: no-cache"); // Don't send this header! It breaks IE. |
| 165 | - | 188 | + |
| 166 | $oFile = new KTFSFileLike($sPath); | 189 | $oFile = new KTFSFileLike($sPath); |
| 167 | KTFileLikeUtil::send_contents($oFile); | 190 | KTFileLikeUtil::send_contents($oFile); |
| 168 | } else { | 191 | } else { |
plugins/ktcore/folder/addDocument.php
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -52,7 +52,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -52,7 +52,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 52 | if (empty($res)) { | 52 | if (empty($res)) { |
| 53 | return $res; | 53 | return $res; |
| 54 | } | 54 | } |
| 55 | - | 55 | + |
| 56 | $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected"); | 56 | $postExpected = KTUtil::arrayGet($_REQUEST, "postExpected"); |
| 57 | $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived"); | 57 | $postReceived = KTUtil::arrayGet($_REQUEST, "postReceived"); |
| 58 | if (!empty($postExpected)) { | 58 | if (!empty($postExpected)) { |
| @@ -67,7 +67,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -67,7 +67,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 67 | 67 | ||
| 68 | function form_initialdata() { | 68 | function form_initialdata() { |
| 69 | $oForm = new KTForm; | 69 | $oForm = new KTForm; |
| 70 | - | 70 | + |
| 71 | $oForm->setOptions(array( | 71 | $oForm->setOptions(array( |
| 72 | 'label' => _kt("Add a document"), | 72 | 'label' => _kt("Add a document"), |
| 73 | 'action' => 'processInitialData', | 73 | 'action' => 'processInitialData', |
| @@ -79,13 +79,13 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -79,13 +79,13 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 79 | 'submit_label' => _kt("Add"), | 79 | 'submit_label' => _kt("Add"), |
| 80 | 'file_upload' => true, | 80 | 'file_upload' => true, |
| 81 | )); | 81 | )); |
| 82 | - | 82 | + |
| 83 | $aTypes; | 83 | $aTypes; |
| 84 | foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) { | 84 | foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) { |
| 85 | if(!$oDocumentType->getDisabled()) { | 85 | if(!$oDocumentType->getDisabled()) { |
| 86 | $aTypes[] = $oDocumentType; | 86 | $aTypes[] = $oDocumentType; |
| 87 | } | 87 | } |
| 88 | - } | 88 | + } |
| 89 | $oForm->setWidgets(array( | 89 | $oForm->setWidgets(array( |
| 90 | array('ktcore.widgets.file',array( | 90 | array('ktcore.widgets.file',array( |
| 91 | 'label' => _kt('File'), | 91 | 'label' => _kt('File'), |
| @@ -109,9 +109,9 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -109,9 +109,9 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 109 | 'id_method' => 'getId', | 109 | 'id_method' => 'getId', |
| 110 | 'label_method' => 'getName', | 110 | 'label_method' => 'getName', |
| 111 | 'simple_select' => false, | 111 | 'simple_select' => false, |
| 112 | - )), | 112 | + )), |
| 113 | )); | 113 | )); |
| 114 | - | 114 | + |
| 115 | $oForm->setValidators(array( | 115 | $oForm->setValidators(array( |
| 116 | array('ktcore.validators.file', array( | 116 | array('ktcore.validators.file', array( |
| 117 | 'test' => 'file', | 117 | 'test' => 'file', |
| @@ -126,65 +126,70 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -126,65 +126,70 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 126 | 'output' => 'document_type', | 126 | 'output' => 'document_type', |
| 127 | 'class' => 'DocumentType', | 127 | 'class' => 'DocumentType', |
| 128 | 'ids' => true, | 128 | 'ids' => true, |
| 129 | - )), | 129 | + )), |
| 130 | )); | 130 | )); |
| 131 | - | 131 | + |
| 132 | return $oForm; | 132 | return $oForm; |
| 133 | } | 133 | } |
| 134 | - | 134 | + |
| 135 | function getFieldsetsForType($iTypeId) { | 135 | function getFieldsetsForType($iTypeId) { |
| 136 | $typeid = KTUtil::getId($iTypeId); | 136 | $typeid = KTUtil::getId($iTypeId); |
| 137 | $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); | 137 | $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); |
| 138 | $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false)); | 138 | $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false)); |
| 139 | - | 139 | + |
| 140 | $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); | 140 | $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); |
| 141 | - return $fieldsets; | 141 | + return $fieldsets; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | function do_main() { | 144 | function do_main() { |
| 145 | $this->oPage->setBreadcrumbDetails(_kt("Add a document")); | 145 | $this->oPage->setBreadcrumbDetails(_kt("Add a document")); |
| 146 | $oForm = $this->form_initialdata(); | 146 | $oForm = $this->form_initialdata(); |
| 147 | return $oForm->renderPage(_kt('Add a document to: ') . $this->oFolder->getName()); | 147 | return $oForm->renderPage(_kt('Add a document to: ') . $this->oFolder->getName()); |
| 148 | - } | ||
| 149 | - | 148 | + } |
| 149 | + | ||
| 150 | function do_processInitialData() { | 150 | function do_processInitialData() { |
| 151 | $oForm = $this->form_initialdata(); | 151 | $oForm = $this->form_initialdata(); |
| 152 | $res = $oForm->validate(); | 152 | $res = $oForm->validate(); |
| 153 | if (!empty($res['errors'])) { | 153 | if (!empty($res['errors'])) { |
| 154 | return $oForm->handleError(); | 154 | return $oForm->handleError(); |
| 155 | - } | 155 | + } |
| 156 | $data = $res['results']; | 156 | $data = $res['results']; |
| 157 | $key = KTUtil::randomString(32); | 157 | $key = KTUtil::randomString(32); |
| 158 | 158 | ||
| 159 | - | ||
| 160 | - // joy joy, we need to store the file first, or PHP will (helpfully) | 159 | + |
| 160 | + // joy joy, we need to store the file first, or PHP will (helpfully) | ||
| 161 | // clean it up for us | 161 | // clean it up for us |
| 162 | 162 | ||
| 163 | $oKTConfig =& KTConfig::getSingleton(); | 163 | $oKTConfig =& KTConfig::getSingleton(); |
| 164 | - $sBasedir = $oKTConfig->get("urls/tmpDirectory"); | ||
| 165 | - | 164 | + $sBasedir = $oKTConfig->get("urls/tmpDirectory"); |
| 165 | + | ||
| 166 | $sFilename = tempnam($sBasedir, 'kt_storecontents'); | 166 | $sFilename = tempnam($sBasedir, 'kt_storecontents'); |
| 167 | - $oContents = new KTFSFileLike($data['file']['tmp_name']); | ||
| 168 | - $oOutputFile = new KTFSFileLike($sFilename); | ||
| 169 | - $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | ||
| 170 | - $data['file']['tmp_name'] = $sFilename; | ||
| 171 | 167 | ||
| 172 | - if (PEAR::isError($res)) { | ||
| 173 | - $oForm->handleError(sprintf(_kt("Failed to store file: %s"), $res->getMessage())); | ||
| 174 | - } | ||
| 175 | - $_SESSION['_add_data'] = array($key => $data); | ||
| 176 | - | 168 | +// $oContents = new KTFSFileLike($data['file']['tmp_name']); |
| 169 | +// $oOutputFile = new KTFSFileLike($sFilename); | ||
| 170 | +// $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); | ||
| 171 | +// | ||
| 172 | +// if (PEAR::isError($res)) { | ||
| 173 | +// $oForm->handleError(sprintf(_kt("Failed to store file: %s"), $res->getMessage())); | ||
| 174 | +// } | ||
| 175 | + | ||
| 176 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | ||
| 177 | + $oStorage->uploadTmpFile($data['file']['tmp_name'], $sFilename); | ||
| 178 | + | ||
| 179 | + $data['file']['tmp_name'] = $sFilename; | ||
| 180 | + $_SESSION['_add_data'] = array($key => $data); | ||
| 181 | + | ||
| 177 | // if we don't need metadata | 182 | // if we don't need metadata |
| 178 | $fieldsets = $this->getFieldsetsForType($data['document_type']); | 183 | $fieldsets = $this->getFieldsetsForType($data['document_type']); |
| 179 | if (empty($fieldsets)) { | 184 | if (empty($fieldsets)) { |
| 180 | - return $this->successRedirectTo('finalise', _kt("File uploaded successfully. Processing."), sprintf("fFileKey=%s", $key)); | 185 | + return $this->successRedirectTo('finalise', _kt("File uploaded successfully. Processing."), sprintf("fFileKey=%s", $key)); |
| 181 | } | 186 | } |
| 182 | - | 187 | + |
| 183 | // if we need metadata | 188 | // if we need metadata |
| 184 | - | 189 | + |
| 185 | $this->successRedirectTo('metadata', _kt("File uploaded successfully. Please fill in the metadata below."), sprintf("fFileKey=%s", $key)); | 190 | $this->successRedirectTo('metadata', _kt("File uploaded successfully. Please fill in the metadata below."), sprintf("fFileKey=%s", $key)); |
| 186 | } | 191 | } |
| 187 | - | 192 | + |
| 188 | function form_metadata($sess_key) { | 193 | function form_metadata($sess_key) { |
| 189 | $oForm = new KTForm; | 194 | $oForm = new KTForm; |
| 190 | $oForm->setOptions(array( | 195 | $oForm->setOptions(array( |
| @@ -197,49 +202,49 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -197,49 +202,49 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 197 | 'context' => &$this, | 202 | 'context' => &$this, |
| 198 | 'extraargs' => $this->meldPersistQuery("","",true), | 203 | 'extraargs' => $this->meldPersistQuery("","",true), |
| 199 | )); | 204 | )); |
| 200 | - | 205 | + |
| 201 | $oFReg =& KTFieldsetRegistry::getSingleton(); | 206 | $oFReg =& KTFieldsetRegistry::getSingleton(); |
| 202 | - | 207 | + |
| 203 | $doctypeid = $_SESSION['_add_data'][$sess_key]['document_type']; | 208 | $doctypeid = $_SESSION['_add_data'][$sess_key]['document_type']; |
| 204 | - | 209 | + |
| 205 | $widgets = array(); | 210 | $widgets = array(); |
| 206 | $validators = array(); | 211 | $validators = array(); |
| 207 | $fieldsets = $this->getFieldsetsForType($doctypeid); | 212 | $fieldsets = $this->getFieldsetsForType($doctypeid); |
| 208 | - | 213 | + |
| 209 | foreach ($fieldsets as $oFieldset) { | 214 | foreach ($fieldsets as $oFieldset) { |
| 210 | $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); | 215 | $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); |
| 211 | - $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); | 216 | + $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); |
| 212 | } | 217 | } |
| 213 | - | 218 | + |
| 214 | $oForm->setWidgets($widgets); | 219 | $oForm->setWidgets($widgets); |
| 215 | - $oForm->setValidators($validators); | ||
| 216 | - | 220 | + $oForm->setValidators($validators); |
| 221 | + | ||
| 217 | return $oForm; | 222 | return $oForm; |
| 218 | } | 223 | } |
| 219 | - | 224 | + |
| 220 | function do_metadata() { | 225 | function do_metadata() { |
| 221 | $this->persistParams(array('fFileKey')); | 226 | $this->persistParams(array('fFileKey')); |
| 222 | - | 227 | + |
| 223 | $oForm = $this->form_metadata($_REQUEST['fFileKey']); | 228 | $oForm = $this->form_metadata($_REQUEST['fFileKey']); |
| 224 | return $oForm->render(); | 229 | return $oForm->render(); |
| 225 | } | 230 | } |
| 226 | - | 231 | + |
| 227 | function do_finalise() { | 232 | function do_finalise() { |
| 228 | - $this->persistParams(array('fFileKey')); | 233 | + $this->persistParams(array('fFileKey')); |
| 229 | $sess_key = $_REQUEST['fFileKey']; | 234 | $sess_key = $_REQUEST['fFileKey']; |
| 230 | $oForm = $this->form_metadata($sess_key); | 235 | $oForm = $this->form_metadata($sess_key); |
| 231 | $res = $oForm->validate(); | 236 | $res = $oForm->validate(); |
| 232 | if (!empty($res['errors'])) { | 237 | if (!empty($res['errors'])) { |
| 233 | - return $oForm->handleError(); | 238 | + return $oForm->handleError(); |
| 234 | } | 239 | } |
| 235 | $data = $res['results']; | 240 | $data = $res['results']; |
| 236 | - | 241 | + |
| 237 | $extra_d = $_SESSION['_add_data'][$sess_key]; | 242 | $extra_d = $_SESSION['_add_data'][$sess_key]; |
| 238 | $doctypeid = $extra_d['document_type']; | 243 | $doctypeid = $extra_d['document_type']; |
| 239 | $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); | 244 | $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); |
| 240 | $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); | 245 | $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); |
| 241 | $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); | 246 | $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); |
| 242 | - | 247 | + |
| 243 | 248 | ||
| 244 | $MDPack = array(); | 249 | $MDPack = array(); |
| 245 | foreach ($fieldsets as $oFieldset) { | 250 | foreach ($fieldsets as $oFieldset) { |
| @@ -247,9 +252,9 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -247,9 +252,9 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 247 | $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); | 252 | $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); |
| 248 | 253 | ||
| 249 | foreach ($fields as $oField) { | 254 | foreach ($fields as $oField) { |
| 250 | - $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); | 255 | + $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); |
| 251 | // ALT.METADATA.LAYER.DIE.DIE.DIE | 256 | // ALT.METADATA.LAYER.DIE.DIE.DIE |
| 252 | - if (!is_null($val)) { | 257 | + if (!is_null($val)) { |
| 253 | $MDPack[] = array( | 258 | $MDPack[] = array( |
| 254 | $oField, | 259 | $oField, |
| 255 | $val | 260 | $val |
| @@ -258,14 +263,14 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -258,14 +263,14 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 258 | 263 | ||
| 259 | } | 264 | } |
| 260 | } | 265 | } |
| 261 | - // older code | 266 | + // older code |
| 262 | 267 | ||
| 263 | $mpo =& new JavascriptObserver($this); | 268 | $mpo =& new JavascriptObserver($this); |
| 264 | $oUploadChannel =& KTUploadChannel::getSingleton(); | 269 | $oUploadChannel =& KTUploadChannel::getSingleton(); |
| 265 | $oUploadChannel->addObserver($mpo); | 270 | $oUploadChannel->addObserver($mpo); |
| 266 | - | 271 | + |
| 267 | require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | 272 | require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); |
| 268 | - require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | 273 | + //require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); |
| 269 | require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); | 274 | require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); |
| 270 | require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); | 275 | require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); |
| 271 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | 276 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); |
| @@ -274,13 +279,14 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -274,13 +279,14 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 274 | 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())), | 279 | 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())), |
| 275 | 'max_str_len' => 200, | 280 | 'max_str_len' => 200, |
| 276 | ); | 281 | ); |
| 277 | - | 282 | + |
| 278 | $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions); | 283 | $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions); |
| 279 | $sTitle = sanitizeForSQL($extra_d['document_name']); | 284 | $sTitle = sanitizeForSQL($extra_d['document_name']); |
| 280 | - | 285 | + |
| 281 | $iFolderId = $this->oFolder->getId(); | 286 | $iFolderId = $this->oFolder->getId(); |
| 282 | $aOptions = array( | 287 | $aOptions = array( |
| 283 | - 'contents' => new KTFSFileLike($aFile['tmp_name']), | 288 | + //'contents' => new KTFSFileLike($aFile['tmp_name']), |
| 289 | + 'temp_file' => $aFile['tmp_name'], | ||
| 284 | 'documenttype' => DocumentType::get($extra_d['document_type']), | 290 | 'documenttype' => DocumentType::get($extra_d['document_type']), |
| 285 | 'metadata' => $MDPack, | 291 | 'metadata' => $MDPack, |
| 286 | 'description' => $sTitle, | 292 | 'description' => $sTitle, |
| @@ -302,7 +308,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -302,7 +308,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 302 | exit(0); | 308 | exit(0); |
| 303 | 309 | ||
| 304 | } | 310 | } |
| 305 | - | 311 | + |
| 306 | } | 312 | } |
| 307 | 313 | ||
| 308 | ?> | 314 | ?> |