Commit 699dceb24b1ec2a0c2d76dd148f34d944871a757
1 parent
4183ce65
KTS-2134
"Add @ in front of file functions such as unlink. There are cases that seem to break webservices because of warnings." Fixed. Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6855 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
45 additions
and
45 deletions
lib/documentmanagement/PhysicalDocumentManager.inc
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | * License Version 1.1.2 ("License"); You may not use this file except in | 9 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 10 | * compliance with the License. You may obtain a copy of the License at | 10 | * compliance with the License. You may obtain a copy of the License at |
| 11 | * http://www.knowledgetree.com/KPL | 11 | * http://www.knowledgetree.com/KPL |
| 12 | - * | 12 | + * |
| 13 | * Software distributed under the License is distributed on an "AS IS" | 13 | * Software distributed under the License is distributed on an "AS IS" |
| 14 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 14 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing rights and | 15 | * See the License for the specific language governing rights and |
| @@ -20,9 +20,9 @@ | @@ -20,9 +20,9 @@ | ||
| 20 | * (ii) the KnowledgeTree copyright notice | 20 | * (ii) the KnowledgeTree copyright notice |
| 21 | * in the same form as they appear in the distribution. See the License for | 21 | * in the same form as they appear in the distribution. See the License for |
| 22 | * requirements. | 22 | * requirements. |
| 23 | - * | 23 | + * |
| 24 | * The Original Code is: KnowledgeTree Open Source | 24 | * The Original Code is: KnowledgeTree Open Source |
| 25 | - * | 25 | + * |
| 26 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 26 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 27 | * (Pty) Ltd, trading as KnowledgeTree. | 27 | * (Pty) Ltd, trading as KnowledgeTree. |
| 28 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 28 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -69,7 +69,7 @@ class PhysicalDocumentManager { | @@ -69,7 +69,7 @@ class PhysicalDocumentManager { | ||
| 69 | return false; | 69 | return false; |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | - | 72 | + |
| 73 | /** | 73 | /** |
| 74 | * Stream a particular version of a document to a client over http | 74 | * Stream a particular version of a document to a client over http |
| 75 | * | 75 | * |
| @@ -98,7 +98,7 @@ class PhysicalDocumentManager { | @@ -98,7 +98,7 @@ class PhysicalDocumentManager { | ||
| 98 | return false; | 98 | return false; |
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | - | 101 | + |
| 102 | /** | 102 | /** |
| 103 | * Move a document to a new folder | 103 | * Move a document to a new folder |
| 104 | * | 104 | * |
| @@ -106,17 +106,17 @@ class PhysicalDocumentManager { | @@ -106,17 +106,17 @@ class PhysicalDocumentManager { | ||
| 106 | */ | 106 | */ |
| 107 | function moveDocument($sOldDocumentPath, $oDocument, $oFolder) { | 107 | function moveDocument($sOldDocumentPath, $oDocument, $oFolder) { |
| 108 | global $default; | 108 | global $default; |
| 109 | - | 109 | + |
| 110 | // current document path | 110 | // current document path |
| 111 | $sCurrentPath = $sOldDocumentPath; | 111 | $sCurrentPath = $sOldDocumentPath; |
| 112 | - | 112 | + |
| 113 | // the destination path | 113 | // the destination path |
| 114 | $sDestinationFolderPath = Folder::getFolderPath($oFolder->getID()) . $oDocument->getFileName(); | 114 | $sDestinationFolderPath = Folder::getFolderPath($oFolder->getID()) . $oDocument->getFileName(); |
| 115 | 115 | ||
| 116 | // find all the previous versions of this document and move them | 116 | // find all the previous versions of this document and move them |
| 117 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions | 117 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions |
| 118 | // FIXME: refactor array getOldVersionPaths($iDocumentID)?? | 118 | // FIXME: refactor array getOldVersionPaths($iDocumentID)?? |
| 119 | - | 119 | + |
| 120 | $sql = $default->db; | 120 | $sql = $default->db; |
| 121 | $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_id = ?";/*ok*/ | 121 | $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_id = ?";/*ok*/ |
| 122 | $aParams = array($oDocument->getID(), CHECKOUT); | 122 | $aParams = array($oDocument->getID(), CHECKOUT); |
| @@ -130,16 +130,16 @@ class PhysicalDocumentManager { | @@ -130,16 +130,16 @@ class PhysicalDocumentManager { | ||
| 130 | // move it to the new folder | 130 | // move it to the new folder |
| 131 | $default->log->info("PhysicalDocumentManager::moveDocument moving $sSourcePath to $sDestinationPath"); | 131 | $default->log->info("PhysicalDocumentManager::moveDocument moving $sSourcePath to $sDestinationPath"); |
| 132 | if (!PhysicalDocumentManager::move($sSourcePath, $sDestinationPath)) { | 132 | if (!PhysicalDocumentManager::move($sSourcePath, $sDestinationPath)) { |
| 133 | - // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors | 133 | + // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors |
| 134 | $default->log->error("PhysicalDocumentManager::moveDocument error moving $sSourcePath to $sDestinationPath; documentID=" . $oDocument->getID() . "; folderID=" . $oFolder->getID()); | 134 | $default->log->error("PhysicalDocumentManager::moveDocument error moving $sSourcePath to $sDestinationPath; documentID=" . $oDocument->getID() . "; folderID=" . $oFolder->getID()); |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | } else { | 138 | } else { |
| 139 | $default->log->error("PhysicalDocumentManager::moveDocument error looking up document versions, id=" . $oDocument->getID()); | 139 | $default->log->error("PhysicalDocumentManager::moveDocument error looking up document versions, id=" . $oDocument->getID()); |
| 140 | - } | 140 | + } |
| 141 | 141 | ||
| 142 | - // now move the current version | 142 | + // now move the current version |
| 143 | if (PhysicalDocumentManager::move($sCurrentPath, $sDestinationFolderPath)) { | 143 | if (PhysicalDocumentManager::move($sCurrentPath, $sDestinationFolderPath)) { |
| 144 | return true; | 144 | return true; |
| 145 | } else { | 145 | } else { |
| @@ -147,7 +147,7 @@ class PhysicalDocumentManager { | @@ -147,7 +147,7 @@ class PhysicalDocumentManager { | ||
| 147 | return false; | 147 | return false; |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | - | 150 | + |
| 151 | /** | 151 | /** |
| 152 | * Move a file | 152 | * Move a file |
| 153 | * | 153 | * |
| @@ -160,17 +160,17 @@ class PhysicalDocumentManager { | @@ -160,17 +160,17 @@ class PhysicalDocumentManager { | ||
| 160 | //copy the file to the new destination | 160 | //copy the file to the new destination |
| 161 | if (copy($sOldDocumentPath, $sNewDocumentPath)) { | 161 | if (copy($sOldDocumentPath, $sNewDocumentPath)) { |
| 162 | //delete the old one | 162 | //delete the old one |
| 163 | - unlink($sOldDocumentPath); | 163 | + @unlink($sOldDocumentPath); |
| 164 | return true; | 164 | return true; |
| 165 | } else { | 165 | } else { |
| 166 | return false; | 166 | return false; |
| 167 | } | 167 | } |
| 168 | } else { | 168 | } else { |
| 169 | return false; | 169 | return false; |
| 170 | - } | 170 | + } |
| 171 | } | 171 | } |
| 172 | - | ||
| 173 | - | 172 | + |
| 173 | + | ||
| 174 | /** | 174 | /** |
| 175 | * Deletes a document- moves it to the Deleted/ folder | 175 | * Deletes a document- moves it to the Deleted/ folder |
| 176 | * | 176 | * |
| @@ -180,13 +180,13 @@ class PhysicalDocumentManager { | @@ -180,13 +180,13 @@ class PhysicalDocumentManager { | ||
| 180 | global $default; | 180 | global $default; |
| 181 | // current document path | 181 | // current document path |
| 182 | $sCurrentPath = $oDocument->getPath(); | 182 | $sCurrentPath = $oDocument->getPath(); |
| 183 | - | 183 | + |
| 184 | // check if the deleted folder exists and create it if not | 184 | // check if the deleted folder exists and create it if not |
| 185 | $sDeletedPrefix = $default->documentRoot . "/Deleted"; | 185 | $sDeletedPrefix = $default->documentRoot . "/Deleted"; |
| 186 | if (!file_exists($sDeletedPrefix)) { | 186 | if (!file_exists($sDeletedPrefix)) { |
| 187 | mkdir($sDeletedPrefix, 0755); | 187 | mkdir($sDeletedPrefix, 0755); |
| 188 | } | 188 | } |
| 189 | - | 189 | + |
| 190 | // move the file to the deleted folder, prefixed by its document id | 190 | // move the file to the deleted folder, prefixed by its document id |
| 191 | $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); | 191 | $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); |
| 192 | 192 | ||
| @@ -196,8 +196,8 @@ class PhysicalDocumentManager { | @@ -196,8 +196,8 @@ class PhysicalDocumentManager { | ||
| 196 | $sql = $default->db; | 196 | $sql = $default->db; |
| 197 | $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_namespace = ?";/*ok*/ | 197 | $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_namespace = ?";/*ok*/ |
| 198 | $aParams = array($oDocument->getID(), 'ktcore.transactions.check_out'); | 198 | $aParams = array($oDocument->getID(), 'ktcore.transactions.check_out'); |
| 199 | - $result = $sql->query(array($sQuery, $aParams)); | ||
| 200 | - | 199 | + $result = $sql->query(array($sQuery, $aParams)); |
| 200 | + | ||
| 201 | if ($result) { | 201 | if ($result) { |
| 202 | while ($sql->next_record()) { | 202 | while ($sql->next_record()) { |
| 203 | $sVersion = $sql->f("version"); | 203 | $sVersion = $sql->f("version"); |
| @@ -214,11 +214,11 @@ class PhysicalDocumentManager { | @@ -214,11 +214,11 @@ class PhysicalDocumentManager { | ||
| 214 | } | 214 | } |
| 215 | } else { | 215 | } else { |
| 216 | $default->log->error("PhysicalDocumentManager::delete error looking up document versions, id=" . $oDocument->getID()); | 216 | $default->log->error("PhysicalDocumentManager::delete error looking up document versions, id=" . $oDocument->getID()); |
| 217 | - } | ||
| 218 | - | 217 | + } |
| 218 | + | ||
| 219 | + | ||
| 219 | 220 | ||
| 220 | - | ||
| 221 | - // now move the current version | 221 | + // now move the current version |
| 222 | if (PhysicalDocumentManager::move($sCurrentPath, $sDeletedPrefix)) { | 222 | if (PhysicalDocumentManager::move($sCurrentPath, $sDeletedPrefix)) { |
| 223 | return true; | 223 | return true; |
| 224 | } else { | 224 | } else { |
| @@ -231,12 +231,12 @@ class PhysicalDocumentManager { | @@ -231,12 +231,12 @@ class PhysicalDocumentManager { | ||
| 231 | * Completely remove a document from the Deleted/ folder | 231 | * Completely remove a document from the Deleted/ folder |
| 232 | * | 232 | * |
| 233 | * return boolean true on successful move, false otherwhise | 233 | * return boolean true on successful move, false otherwhise |
| 234 | - */ | 234 | + */ |
| 235 | function expunge($oDocument) { | 235 | function expunge($oDocument) { |
| 236 | global $default; | 236 | global $default; |
| 237 | // deleted document path | 237 | // deleted document path |
| 238 | $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); | 238 | $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); |
| 239 | - | 239 | + |
| 240 | // find all the previous versions of this document and delete them | 240 | // find all the previous versions of this document and delete them |
| 241 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions | 241 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions |
| 242 | // FIXME: refactor | 242 | // FIXME: refactor |
| @@ -252,7 +252,7 @@ class PhysicalDocumentManager { | @@ -252,7 +252,7 @@ class PhysicalDocumentManager { | ||
| 252 | // zap it | 252 | // zap it |
| 253 | $default->log->info("PhysicalDocumentManager::expunge rm'ing $sExpungePath"); | 253 | $default->log->info("PhysicalDocumentManager::expunge rm'ing $sExpungePath"); |
| 254 | if (file_exists($sExpungePath)) { | 254 | if (file_exists($sExpungePath)) { |
| 255 | - if (!unlink($sExpungePath)) { | 255 | + if (!@unlink($sExpungePath)) { |
| 256 | $default->log->error("PhysicalDocumentManager::expunge error deleting $sExpungePath; documentID=" . $oDocument->getID()); | 256 | $default->log->error("PhysicalDocumentManager::expunge error deleting $sExpungePath; documentID=" . $oDocument->getID()); |
| 257 | // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors | 257 | // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors |
| 258 | } | 258 | } |
| @@ -263,12 +263,12 @@ class PhysicalDocumentManager { | @@ -263,12 +263,12 @@ class PhysicalDocumentManager { | ||
| 263 | } | 263 | } |
| 264 | } else { | 264 | } else { |
| 265 | $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); | 265 | $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); |
| 266 | - } | 266 | + } |
| 267 | 267 | ||
| 268 | if (file_exists($sDeletedPrefix)) { | 268 | if (file_exists($sDeletedPrefix)) { |
| 269 | // now delete the current version | 269 | // now delete the current version |
| 270 | - if (unlink($sDeletedPrefix)) { | ||
| 271 | - $default->log->info("PhysicalDocumentManager::expunge unlinkied $sDeletedPrefix"); | 270 | + if (@unlink($sDeletedPrefix)) { |
| 271 | + $default->log->info("PhysicalDocumentManager::expunge unlinkied $sDeletedPrefix"); | ||
| 272 | return true; | 272 | return true; |
| 273 | } else { | 273 | } else { |
| 274 | $default->log->info("PhysicalDocumentManager::expunge couldn't unlink $sDeletedPrefix"); | 274 | $default->log->info("PhysicalDocumentManager::expunge couldn't unlink $sDeletedPrefix"); |
| @@ -283,25 +283,25 @@ class PhysicalDocumentManager { | @@ -283,25 +283,25 @@ class PhysicalDocumentManager { | ||
| 283 | return true; | 283 | return true; |
| 284 | } | 284 | } |
| 285 | } | 285 | } |
| 286 | - | 286 | + |
| 287 | /** | 287 | /** |
| 288 | * Restore a document from the Deleted/ folder to the specified folder | 288 | * Restore a document from the Deleted/ folder to the specified folder |
| 289 | * | 289 | * |
| 290 | * return boolean true on successful move, false otherwhise | 290 | * return boolean true on successful move, false otherwhise |
| 291 | - */ | 291 | + */ |
| 292 | function restore($oDocument) { | 292 | function restore($oDocument) { |
| 293 | global $default; | 293 | global $default; |
| 294 | - | 294 | + |
| 295 | // deleted document path (includes previous versions) | 295 | // deleted document path (includes previous versions) |
| 296 | $sDeletedPath = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); | 296 | $sDeletedPath = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); |
| 297 | - | 297 | + |
| 298 | // NEW FOLDER REALLY NEEDS TO BE / | 298 | // NEW FOLDER REALLY NEEDS TO BE / |
| 299 | - if (is_null($oDocument->getFolderID())) { | 299 | + if (is_null($oDocument->getFolderID())) { |
| 300 | $oDocument->setFolderID(1); | 300 | $oDocument->setFolderID(1); |
| 301 | } | 301 | } |
| 302 | //var_dump($oDocument->getFolderID()); | 302 | //var_dump($oDocument->getFolderID()); |
| 303 | $sRestorePath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $oDocument->getFileName(); | 303 | $sRestorePath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $oDocument->getFileName(); |
| 304 | - | 304 | + |
| 305 | // find all the previous versions of this document and move them | 305 | // find all the previous versions of this document and move them |
| 306 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions | 306 | // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions |
| 307 | // FIXME: refactor | 307 | // FIXME: refactor |
| @@ -326,17 +326,17 @@ class PhysicalDocumentManager { | @@ -326,17 +326,17 @@ class PhysicalDocumentManager { | ||
| 326 | } else { | 326 | } else { |
| 327 | $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); | 327 | $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); |
| 328 | } | 328 | } |
| 329 | - | ||
| 330 | - // now move the current version | 329 | + |
| 330 | + // now move the current version | ||
| 331 | if (PhysicalDocumentManager::move($sDeletedPath, $sRestorePath)) { | 331 | if (PhysicalDocumentManager::move($sDeletedPath, $sRestorePath)) { |
| 332 | return true; | 332 | return true; |
| 333 | } else { | 333 | } else { |
| 334 | $default->log->error("PhysicalDocumentManager::restore couldn't move $sDeletedPath to $sRestorePath, documentID=" . $oDocument->getID()); | 334 | $default->log->error("PhysicalDocumentManager::restore couldn't move $sDeletedPath to $sRestorePath, documentID=" . $oDocument->getID()); |
| 335 | return false; | 335 | return false; |
| 336 | - } | 336 | + } |
| 337 | } | 337 | } |
| 338 | - | ||
| 339 | - | 338 | + |
| 339 | + | ||
| 340 | /** | 340 | /** |
| 341 | * View a document using an inline viewer | 341 | * View a document using an inline viewer |
| 342 | * | 342 | * |
| @@ -348,7 +348,7 @@ class PhysicalDocumentManager { | @@ -348,7 +348,7 @@ class PhysicalDocumentManager { | ||
| 348 | */ | 348 | */ |
| 349 | function inlineViewPhysicalDocument($iDocumentID) { | 349 | function inlineViewPhysicalDocument($iDocumentID) { |
| 350 | //get the document | 350 | //get the document |
| 351 | - $oDocument = & Document::get($iDocumentID); | 351 | + $oDocument = & Document::get($iDocumentID); |
| 352 | //get the path to the document on the server | 352 | //get the path to the document on the server |
| 353 | $sDocumentFileSystemPath = $oDocument->getPath(); | 353 | $sDocumentFileSystemPath = $oDocument->getPath(); |
| 354 | if (file_exists($sDocumentFileSystemPath)) { | 354 | if (file_exists($sDocumentFileSystemPath)) { |
| @@ -365,7 +365,7 @@ class PhysicalDocumentManager { | @@ -365,7 +365,7 @@ class PhysicalDocumentManager { | ||
| 365 | return false; | 365 | return false; |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | - | 368 | + |
| 369 | /** | 369 | /** |
| 370 | * Get the uploaded file information and place it into a document object | 370 | * Get the uploaded file information and place it into a document object |
| 371 | * | 371 | * |
| @@ -375,9 +375,9 @@ class PhysicalDocumentManager { | @@ -375,9 +375,9 @@ class PhysicalDocumentManager { | ||
| 375 | * @return Document Document object containing uploaded file information | 375 | * @return Document Document object containing uploaded file information |
| 376 | */ | 376 | */ |
| 377 | function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { | 377 | function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { |
| 378 | - //get the uploaded document information and put it into a document object | 378 | + //get the uploaded document information and put it into a document object |
| 379 | $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], KTMime::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID); | 379 | $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], KTMime::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID); |
| 380 | - return $oDocument; | 380 | + return $oDocument; |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
| 383 | 383 |