Commit 30a08752a1000fae6f53cef00c6f0a48fbf4e81c
1 parent
85ac0eb0
Add a channel for messages about document addition, in case anyone is
interested in the process. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4407 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
58 additions
and
0 deletions
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -176,11 +176,14 @@ class KTDocumentUtil { |
| 176 | 176 | $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype'); |
| 177 | 177 | $sDescription = KTUtil::arrayGet($aOptions, 'description', $sFilename); |
| 178 | 178 | |
| 179 | + $oUploadChannel =& KTUploadChannel::getSingleton(); | |
| 180 | + | |
| 179 | 181 | if ($oDocumentType) { |
| 180 | 182 | $iDocumentTypeId = KTUtil::getId($oDocumentType); |
| 181 | 183 | } else { |
| 182 | 184 | $iDocumentTypeId = 1; |
| 183 | 185 | } |
| 186 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Creating database entry"))); | |
| 184 | 187 | $oDocument =& Document::createFromArray(array( |
| 185 | 188 | 'name' => $sDescription, |
| 186 | 189 | 'description' => $sDescription, |
| ... | ... | @@ -200,6 +203,7 @@ class KTDocumentUtil { |
| 200 | 203 | return $res; |
| 201 | 204 | } |
| 202 | 205 | } else { |
| 206 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Storing contents"))); | |
| 203 | 207 | $res = KTDocumentUtil::storeContents($oDocument, $oContents, $aOptions); |
| 204 | 208 | if (PEAR::isError($res)) { |
| 205 | 209 | $oDocument->delete(); |
| ... | ... | @@ -214,6 +218,7 @@ class KTDocumentUtil { |
| 214 | 218 | return $res; |
| 215 | 219 | } |
| 216 | 220 | } else { |
| 221 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Saving metadata"))); | |
| 217 | 222 | $res = KTDocumentUtil::saveMetadata($oDocument, $aMetadata); |
| 218 | 223 | if (PEAR::isError($res)) { |
| 219 | 224 | $oDocument->delete(); |
| ... | ... | @@ -377,17 +382,23 @@ class KTDocumentUtil { |
| 377 | 382 | if (KTDocumentUtil::exists($oFolder, $sFilename)) { |
| 378 | 383 | return PEAR::raiseError("File already exists"); |
| 379 | 384 | } |
| 385 | + $oUploadChannel =& KTUploadChannel::getSingleton(); | |
| 386 | + $oUploadChannel->sendMessage(new KTUploadNewFile($sFilename)); | |
| 380 | 387 | $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions); |
| 388 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Document created"))); | |
| 381 | 389 | if (PEAR::isError($oDocument)) { |
| 382 | 390 | return $oDocument; |
| 383 | 391 | } |
| 384 | 392 | |
| 393 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Scanning file"))); | |
| 385 | 394 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 386 | 395 | $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan'); |
| 396 | + $iTrigger = 0; | |
| 387 | 397 | foreach ($aTriggers as $aTrigger) { |
| 388 | 398 | $sTrigger = $aTrigger[0]; |
| 389 | 399 | $oTrigger = new $sTrigger; |
| 390 | 400 | $oTrigger->setDocument($oDocument); |
| 401 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_(" (trigger %s)"), $sTrigger))); | |
| 391 | 402 | $ret = $oTrigger->scan(); |
| 392 | 403 | if (PEAR::isError($ret)) { |
| 393 | 404 | $oDocument->delete(); |
| ... | ... | @@ -395,6 +406,7 @@ class KTDocumentUtil { |
| 395 | 406 | } |
| 396 | 407 | } |
| 397 | 408 | |
| 409 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Transforming file"))); | |
| 398 | 410 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 399 | 411 | $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform'); |
| 400 | 412 | foreach ($aTriggers as $aTrigger) { |
| ... | ... | @@ -404,9 +416,11 @@ class KTDocumentUtil { |
| 404 | 416 | } |
| 405 | 417 | $oTrigger = new $sTrigger; |
| 406 | 418 | $oTrigger->setDocument($oDocument); |
| 419 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_(" (trigger %s)"), $sTrigger))); | |
| 407 | 420 | $oTrigger->transform(); |
| 408 | 421 | } |
| 409 | 422 | |
| 423 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Creating transaction"))); | |
| 410 | 424 | $aOptions = array('user' => $oUser); |
| 411 | 425 | //create the document transaction record |
| 412 | 426 | $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE, $aOptions); |
| ... | ... | @@ -416,11 +430,14 @@ class KTDocumentUtil { |
| 416 | 430 | return $res; |
| 417 | 431 | } |
| 418 | 432 | |
| 433 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Sending subscriptions"))); | |
| 419 | 434 | // fire subscription alerts for the checked in document |
| 420 | 435 | $oSubscriptionEvent = new SubscriptionEvent(); |
| 421 | 436 | $oFolder = Folder::get($oDocument->getFolderID()); |
| 422 | 437 | $oSubscriptionEvent->AddDocument($oDocument, $oFolder); |
| 423 | 438 | |
| 439 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("All done..."))); | |
| 440 | + | |
| 424 | 441 | return $oDocument; |
| 425 | 442 | } |
| 426 | 443 | // }}} |
| ... | ... | @@ -513,4 +530,45 @@ class KTMetadataValidationError extends PEAR_Error { |
| 513 | 530 | } |
| 514 | 531 | } |
| 515 | 532 | |
| 533 | +class KTUploadChannel { | |
| 534 | + var $observers = array(); | |
| 535 | + | |
| 536 | + function &getSingleton() { | |
| 537 | + if (!KTUtil::arrayGet($GLOBALS, 'KT_UploadChannel')) { | |
| 538 | + $GLOBALS['KT_UploadChannel'] = new KTUploadChannel; | |
| 539 | + } | |
| 540 | + return $GLOBALS['KT_UploadChannel']; | |
| 541 | + } | |
| 542 | + | |
| 543 | + function sendMessage(&$msg) { | |
| 544 | + foreach ($this->observers as $oObserver) { | |
| 545 | + $oObserver->receiveMessage($msg); | |
| 546 | + } | |
| 547 | + } | |
| 548 | + | |
| 549 | + function addObserver(&$obs) { | |
| 550 | + array_push($this->observers, $obs); | |
| 551 | + } | |
| 552 | +} | |
| 553 | + | |
| 554 | +class KTUploadGenericMessage { | |
| 555 | + function KTUploadGenericMessage($sMessage) { | |
| 556 | + $this->sMessage = $sMessage; | |
| 557 | + } | |
| 558 | + | |
| 559 | + function getString() { | |
| 560 | + return $this->sMessage; | |
| 561 | + } | |
| 562 | +} | |
| 563 | + | |
| 564 | +class KTUploadNewFile { | |
| 565 | + function KTUploadNewFile($sFilename) { | |
| 566 | + $this->sFilename = $sFilename; | |
| 567 | + } | |
| 568 | + | |
| 569 | + function getString() { | |
| 570 | + return $this->sFilename; | |
| 571 | + } | |
| 572 | +} | |
| 573 | + | |
| 516 | 574 | ?> | ... | ... |