Commit 699dceb24b1ec2a0c2d76dd148f34d944871a757

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