Commit 78072abe0ebea2a2f70f2336f20955c2feeca998

Authored by Conrad Vermeulen
1 parent bc6c5313

KTS-673

"The search algorithm needs some work"
Implemented. Index is cleared out when document is expunged.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7187 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/storage/ondiskhashedstoragemanager.inc.php
... ... @@ -288,7 +288,8 @@ class KTOnDiskHashedStorageManager extends KTStorageManager {
288 288 * return boolean true on successful expunge
289 289 */
290 290 function expunge($oDocument) {
291   - $oConfig =& KTConfig::getSingleton();
  291 + parent::expunge($oDocument);
  292 + $oConfig =& KTConfig::getSingleton();
292 293 $sCurrentPath = $this->getPath($oDocument);
293 294  
294 295 $sDocumentRoot = $oConfig->get('urls/documentRoot');
... ...
lib/storage/ondiskpathstoragemanager.inc.php
... ... @@ -6,7 +6,7 @@
6 6 * path on-disk as in the repository.
7 7 *
8 8 * WARNING:
9   - *
  9 + *
10 10 * This storage manager is _not_ transaction-safe, as on-disk paths need
11 11 * to update when the repository position changes, and this operation
12 12 * and the repository change in combination can't be atomic, even if
... ... @@ -16,7 +16,7 @@
16 16 * License Version 1.1.2 ("License"); You may not use this file except in
17 17 * compliance with the License. You may obtain a copy of the License at
18 18 * http://www.knowledgetree.com/KPL
19   - *
  19 + *
20 20 * Software distributed under the License is distributed on an "AS IS"
21 21 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
22 22 * See the License for the specific language governing rights and
... ... @@ -27,9 +27,9 @@
27 27 * (ii) the KnowledgeTree copyright notice
28 28 * in the same form as they appear in the distribution. See the License for
29 29 * requirements.
30   - *
  30 + *
31 31 * The Original Code is: KnowledgeTree Open Source
32   - *
  32 + *
33 33 * The Initial Developer of the Original Code is The Jam Warehouse Software
34 34 * (Pty) Ltd, trading as KnowledgeTree.
35 35 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -97,7 +97,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
97 97 function freeTemporaryFile($sPath) {
98 98 return;
99 99 }
100   -
  100 +
101 101 function download($oDocument) {
102 102 //get the path to the document on the server
103 103 $oConfig =& KTConfig::getSingleton();
... ... @@ -148,7 +148,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
148 148 $sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $oFolder->generateFolderPath($oFolder->getID()));
149 149 KTUtil::deleteDirectory($sPath);
150 150 }
151   -
  151 +
152 152 function downloadVersion($oDocument, $iVersionId) {
153 153 //get the document
154 154 $oContentVersion = KTDocumentContentVersion::get($iVersionId);
... ... @@ -170,7 +170,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
170 170 return false;
171 171 }
172 172 }
173   -
  173 +
174 174 /**
175 175 * Move a document to a new folder
176 176 *
... ... @@ -200,7 +200,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
200 200 }
201 201 return true;
202 202 }
203   -
  203 +
204 204 /**
205 205 * Move a file
206 206 *
... ... @@ -220,7 +220,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
220 220 }
221 221 } else {
222 222 return false;
223   - }
  223 + }
224 224 }
225 225  
226 226 function moveFolder($oFolder, $oDestFolder) {
... ... @@ -248,7 +248,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
248 248 if (PEAR::isError($res)) {
249 249 return $res;
250 250 }
251   -
  251 +
252 252 $oConfig =& KTConfig::getSingleton();
253 253 $sSrc = sprintf("%s/%s",
254 254 $oConfig->get('urls/documentRoot'),
... ... @@ -261,7 +261,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
261 261 );
262 262 return KTUtil::moveDirectory($sSrc, $sDst);
263 263 }
264   -
  264 +
265 265 function renameFolder($oFolder, $sNewName) {
266 266 $table = "document_content_version";
267 267 $sQuery = "UPDATE $table SET storage_path = CONCAT(?, SUBSTRING(storage_path FROM ?)) WHERE storage_path LIKE ?";
... ... @@ -283,7 +283,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
283 283 if (PEAR::isError($res)) {
284 284 return $res;
285 285 }
286   -
  286 +
287 287 $oConfig =& KTConfig::getSingleton();
288 288 $sSrc = sprintf("%s/%s",
289 289 $oConfig->get('urls/documentRoot'),
... ... @@ -294,59 +294,59 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
294 294 $sDestFolderPath
295 295 );
296 296 $res = @rename($sSrc, $sDst);
297   - if (PEAR::isError($res) || ($res == false)) {
  297 + if (PEAR::isError($res) || ($res == false)) {
298 298 print '<br /> -- unable to move ' . $sSrc . ' to ' . $sDst . ' ';
299 299 return false;
300   - // return PEAR::raiseError('unable to move directory to ' . $sDst);
301   - }
302   -
  300 + // return PEAR::raiseError('unable to move directory to ' . $sDst);
  301 + }
  302 +
303 303 return true;
304   - }
305   -
  304 + }
  305 +
306 306 /**
307 307 * Perform any storage changes necessary to account for a copied
308 308 * document object.
309 309 */
310 310 function copy($oSrcDocument, &$oNewDocument) {
311   - // we get the Folder object
  311 + // we get the Folder object
312 312 $oVersion = $oNewDocument->_oDocumentContentVersion;
313 313 $oConfig =& KTConfig::getSingleton();
314 314 $sDocumentRoot = $oConfig->get('urls/documentRoot');
315   -
  315 +
316 316 $sNewPath = $this->generateStoragePath($oNewDocument);
317 317 $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $this->generateStoragePath($oSrcDocument));
318 318 $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
319   -
  319 +
320 320 $res = KTUtil::copyFile($sFullOldPath, $sFullNewPath);
321 321 if (PEAR::isError($res)) { return $res; }
322 322 $oVersion->setStoragePath($sNewPath);
323   - $oVersion->update();
  323 + $oVersion->update();
324 324 }
325   -
  325 +
326 326 /**
327 327 * Perform any storage changes necessary to account for a renamed
328 328 * document object.
329 329 * someone else _must_ call the update on $oDocument
330 330 */
331 331 function renameDocument(&$oDocument, $oOldContentVersion, $sNewFilename) {
332   - // we get the Folder object
333   - $oVersion =& $oDocument->_oDocumentContentVersion;
  332 + // we get the Folder object
  333 + $oVersion =& $oDocument->_oDocumentContentVersion;
334 334 $oConfig =& KTConfig::getSingleton();
335 335 $sDocumentRoot = $oConfig->get('urls/documentRoot');
336   -
  336 +
337 337 $sOldPath = sprintf("%s/%s-%s", Folder::generateFolderPath($oDocument->getFolderID()), $oOldContentVersion->getId(), $oOldContentVersion->getFileName());
338 338 $sNewPath = sprintf("%s/%s-%s", Folder::generateFolderPath($oDocument->getFolderID()), $oDocument->_oDocumentContentVersion->getId(), $sNewFilename);
339 339 $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
340 340 $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
341   -
  341 +
342 342 $res = KTUtil::copyFile($sFullOldPath, $sFullNewPath);
343 343 if (PEAR::isError($res)) { return $res; }
344   -
  344 +
345 345 $oVersion->setStoragePath($sNewPath);
346 346 // someone else _must_ call the update.
347 347 return true; // RES ?= PEAR::raiseError('.');
348 348 }
349   -
  349 +
350 350 /**
351 351 * Deletes a document- moves it to the Deleted/ folder
352 352 *
... ... @@ -355,7 +355,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
355 355 function delete($oDocument) {
356 356 $oConfig =& KTConfig::getSingleton();
357 357 $sCurrentPath = $this->getPath($oDocument);
358   -
  358 +
359 359 // check if the deleted folder exists and create it if not
360 360 $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
361 361 if (!file_exists($sDeletedPrefix)) {
... ... @@ -379,11 +379,12 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
379 379 * Completely remove a document from the Deleted/ folder
380 380 *
381 381 * return boolean true on successful expunge
382   - */
  382 + */
383 383 function expunge($oDocument) {
  384 + parent::expunge($oDocument);
384 385 $oConfig =& KTConfig::getSingleton();
385 386 $sCurrentPath = $this->getPath($oDocument);
386   -
  387 +
387 388 // check if the deleted folder exists and create it if not
388 389 $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
389 390 $sDocumentRoot = $oConfig->get('urls/documentRoot');
... ... @@ -398,16 +399,16 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
398 399 }
399 400 return true;
400 401 }
401   -
  402 +
402 403 /**
403 404 * Restore a document from the Deleted/ folder to the specified folder
404 405 *
405 406 * return boolean true on successful move, false otherwhise
406   - */
  407 + */
407 408 function restore($oDocument) {
408 409 $oConfig =& KTConfig::getSingleton();
409 410 $sCurrentPath = $this->getPath($oDocument);
410   -
  411 +
411 412 // check if the deleted folder exists and create it if not
412 413 $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
413 414 $sDocumentRoot = $oConfig->get('urls/documentRoot');
... ... @@ -422,12 +423,12 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
422 423 $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
423 424 KTUtil::moveFile($sFullOldPath, $sFullNewPath);
424 425 $oVersion->update();
425   -
  426 +
426 427 }
427 428 return true;
428 429 }
429   -
430   -
  430 +
  431 +
431 432 /**
432 433 * View a document using an inline viewer
433 434 *
... ... @@ -439,7 +440,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
439 440 */
440 441 function inlineViewPhysicalDocument($iDocumentID) {
441 442 //get the document
442   - $oDocument = & Document::get($iDocumentID);
  443 + $oDocument = & Document::get($iDocumentID);
443 444 //get the path to the document on the server
444 445 $sDocumentFileSystemPath = $oDocument->getPath();
445 446 if (file_exists($sDocumentFileSystemPath)) {
... ... @@ -456,7 +457,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
456 457 return false;
457 458 }
458 459 }
459   -
  460 +
460 461 /**
461 462 * Get the uploaded file information and place it into a document object
462 463 *
... ... @@ -466,9 +467,9 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
466 467 * @return Document Document object containing uploaded file information
467 468 */
468 469 function & createDocumentFromUploadedFile($aFileArray, $iFolderID) {
469   - //get the uploaded document information and put it into a document object
470   - $oDocument = & new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
471   - return $oDocument;
  470 + //get the uploaded document information and put it into a document object
  471 + $oDocument = new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID);
  472 + return $oDocument;
472 473 }
473 474 }
474 475  
... ...
lib/storage/storagemanager.inc.php
... ... @@ -6,7 +6,7 @@
6 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 7 * compliance with the License. You may obtain a copy of the License at
8 8 * http://www.knowledgetree.com/KPL
9   - *
  9 + *
10 10 * Software distributed under the License is distributed on an "AS IS"
11 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 12 * See the License for the specific language governing rights and
... ... @@ -17,9 +17,9 @@
17 17 * (ii) the KnowledgeTree copyright notice
18 18 * in the same form as they appear in the distribution. See the License for
19 19 * requirements.
20   - *
  20 + *
21 21 * The Original Code is: KnowledgeTree Open Source
22   - *
  22 + *
23 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 24 * (Pty) Ltd, trading as KnowledgeTree.
25 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -34,6 +34,7 @@
34 34 * The Document Manager may only use setDiskPath on the oDocument
35 35 * object, and should not update the document object.
36 36 */
  37 +require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php');
37 38  
38 39 class KTStorageManager {
39 40 /**
... ... @@ -72,7 +73,7 @@ class KTStorageManager {
72 73  
73 74 /**
74 75 * Performs any storage changes necessary to account for a changed
75   - * repository path.
  76 + * repository path.
76 77 *
77 78 * The info arrays must contain the following information:
78 79 * "names" => an array of the names of the folders in the path
... ... @@ -93,7 +94,7 @@ class KTStorageManager {
93 94 function moveFolder ($oFolder, $oDestFolder) {
94 95 return PEAR::raiseError(_kt("Not implemented"));
95 96 }
96   -
  97 +
97 98 function renameFolder($oFolder, $sNewName) {
98 99 return PEAR::raiseError(_kt("Not implemented"));
99 100 }
... ... @@ -103,7 +104,7 @@ class KTStorageManager {
103 104 * document object.
104 105 */
105 106 function copy ($oSrcDocument, &$oNewDocument) {
106   - return PEAR::raiseError(_kt("Not implemented"));
  107 + return PEAR::raiseError(_kt("Not implemented"));
107 108 }
108 109  
109 110 /**
... ... @@ -119,7 +120,9 @@ class KTStorageManager {
119 120 * storage.
120 121 */
121 122 function expunge (&$oDocument) {
122   - return PEAR::raiseError(_kt("Not implemented"));
  123 + $documentid = $oDocument->getId();
  124 + $indexer = Indexer::get();
  125 + $indexer->deleteDocument($documentid);
123 126 }
124 127  
125 128 /**
... ... @@ -145,24 +148,30 @@ class KTStorageManager {
145 148 function createFolder($sFolderPath) {
146 149 return PEAR::raiseError(_kt("Not implemented"));
147 150 }
148   -
  151 +
149 152 function renameDocument(&$oDocument, $oOldContentVersion, $sNewFilename) {
150 153 return PEAR::raiseError(_kt("Not implemented"));
151 154 }
152 155 }
153 156  
154 157 class KTStorageManagerUtil {
155   - function &getSingleton() {
156   - $oConfig =& KTConfig::getSingleton();
157   - $sDefaultManager = 'KTOnDiskHashedStorageManager';
158   - $klass = $oConfig->get('storage/manager', $sDefaultManager);
159   - if (!class_exists($klass)) {
160   - $klass = $sDefaultManager;
161   - }
162   - if (!KTUtil::arrayGet($GLOBALS, 'KTStorageManager')) {
163   - $GLOBALS['KTStorageManager'] =& new $klass;
164   - }
165   - return $GLOBALS['KTStorageManager'];
  158 + static function &getSingleton() {
  159 +
  160 +
  161 + static $singleton = null;
  162 +
  163 + if (is_null($singleton))
  164 + {
  165 + $oConfig =& KTConfig::getSingleton();
  166 + $sDefaultManager = 'KTOnDiskHashedStorageManager';
  167 + $klass = $oConfig->get('storage/manager', $sDefaultManager);
  168 + if (!class_exists($klass)) {
  169 + $klass = $sDefaultManager;
  170 + }
  171 + $singleton = new $klass;
  172 + }
  173 +
  174 + return $singleton;
166 175 }
167 176 }
168 177  
... ...