Commit 51e54f1da3385d1a1806b0b3e1f98c13322c8b14

Authored by megan_w
1 parent 8f657296

KTS-2521

"No notifications when you are subscribed to a folder"
Fixed. Added notifications to the functions in document util. Refactored archive into documentutil. Added notifications to export.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7440 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
... ... @@ -178,13 +178,52 @@ class KTDocumentUtil {
178 178 $oDocumentTransaction = new DocumentTransaction($oDocument, $sCheckoutComment, 'ktcore.transactions.check_out');
179 179 $oDocumentTransaction->create();
180 180  
181   - // fire subscription alerts for the checked in document
  181 + // fire subscription alerts for the downloaded document
182 182 $oSubscriptionEvent = new SubscriptionEvent();
183 183 $oFolder = Folder::get($oDocument->getFolderID());
184 184 $oSubscriptionEvent->CheckOutDocument($oDocument, $oFolder);
185 185  
186 186 return true;
187 187 }
  188 +
  189 + function archive($oDocument, $sReason) {
  190 +
  191 + $this->startTransaction();
  192 + $oDocument->setStatusID(ARCHIVED);
  193 + $res = $oDocument->update();
  194 +
  195 + if (PEAR::isError($res) || ($res === false)) {
  196 + return PEAR::raiseError(_kt('There was a database error while trying to archive this file'));
  197 + }
  198 +
  199 + $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt('Document archived: %s'), $sReason), 'ktcore.transactions.update');
  200 + $oDocumentTransaction->create();
  201 +
  202 + $this->commitTransaction();
  203 +
  204 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  205 + $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate');
  206 + foreach ($aTriggers as $aTrigger) {
  207 + $sTrigger = $aTrigger[0];
  208 + $oTrigger = new $sTrigger;
  209 + $aInfo = array(
  210 + 'document' => $oDocument,
  211 + );
  212 + $oTrigger->setInfo($aInfo);
  213 + $ret = $oTrigger->postValidate();
  214 + if (PEAR::isError($ret)) {
  215 + $oDocument->delete();
  216 + return $ret;
  217 + }
  218 + }
  219 +
  220 + // fire subscription alerts for the archived document
  221 + $oSubscriptionEvent = new SubscriptionEvent();
  222 + $oFolder = Folder::get($oDocument->getFolderID());
  223 + $oSubscriptionEvent->ArchivedDocument($oDocument, $oFolder);
  224 +
  225 + return true;
  226 + }
188 227  
189 228 function &_add($oFolder, $sFilename, $oUser, $aOptions) {
190 229 global $default;
... ... @@ -922,6 +961,11 @@ class KTDocumentUtil {
922 961 return $ret;
923 962 }
924 963 }
  964 +
  965 + // fire subscription alerts for the copied document
  966 + $oSubscriptionEvent = new SubscriptionEvent();
  967 + $oFolder = Folder::get($oDocument->getFolderID());
  968 + $oSubscriptionEvent->MoveDocument($oDocument, $oDestinationFolder, $oSrcFolder, 'CopiedDocument');
925 969  
926 970 return $oNewDocument;
927 971 }
... ... @@ -1027,6 +1071,10 @@ class KTDocumentUtil {
1027 1071 return $ret;
1028 1072 }
1029 1073 }
  1074 +
  1075 + // fire subscription alerts for the moved document
  1076 + $oSubscriptionEvent = new SubscriptionEvent();
  1077 + $oSubscriptionEvent->MoveDocument($oDocument, $oFolder, $oOriginalFolder);
1030 1078  
1031 1079 return KTPermissionUtil::updatePermissionLookup($oDocument);
1032 1080 }
... ...
lib/subscriptions/subscriptions.inc.php
... ... @@ -57,8 +57,10 @@ class SubscriptionEvent {
57 57 "CheckInDocument",
58 58 "CheckOutDocument",
59 59 "MovedDocument",
  60 + "CopiedDocument",
60 61 "ArchivedDocument",
61 62 "RestoredArchivedDocument",
  63 + "DownloadDocument",
62 64 );
63 65  
64 66 var $subscriptionTypes = array(
... ... @@ -480,82 +482,83 @@ class SubscriptionEvent {
480 482 }
481 483 }
482 484  
483   - function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder) {
  485 + function MoveDocument($oMovedDocument, $oToFolder, $oFromFolder, $moveOrCopy = "MovedDocument") {
484 486 $content = new SubscriptionContent(); // needed for i18n
485   - // OK: two actions: document registrants, folder registrants.
  487 + // OK: two actions: document registrants, folder registrants.
486 488 $aUsers = $this->_getSubscribers($oMovedDocument->getId(), $this->subscriptionTypes["Document"]);
487   - $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
488   -
489   - foreach ($aUsers as $oSubscriber) {
490   - // notification object first.
491   - $aNotificationOptions = array();
492   - $aNotificationOptions['target_user'] = $oSubscriber->getID();
493   - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
494   - $aNotificationOptions['target_name'] = $oMovedDocument->getName();
495   - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId());
496   - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
497   - $aNotificationOptions['event_type'] = "MovedDocument";
498   - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
499   -
500   - // now the email content.
501   - // FIXME this needs to be handled entirely within notifications from now on.
502   - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
503   - $emailContent = $content->getEmailAlertContent($oNotification);
504   - $emailSubject = $content->getEmailAlertSubject($oNotification);
505   - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
506   - $oEmail->send();
507   - }
508   - }
  489 + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
  490 +
  491 + foreach ($aUsers as $oSubscriber) {
  492 + // notification object first.
  493 + $aNotificationOptions = array();
  494 + $aNotificationOptions['target_user'] = $oSubscriber->getID();
  495 + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
  496 + $aNotificationOptions['target_name'] = $oMovedDocument->getName();
  497 + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId());
  498 + $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
  499 + $aNotificationOptions['event_type'] = $moveOrCopy;
  500 + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
  501 +
  502 + // now the email content.
  503 + // FIXME this needs to be handled entirely within notifications from now on.
  504 + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
  505 + $emailContent = $content->getEmailAlertContent($oNotification);
  506 + $emailSubject = $content->getEmailAlertSubject($oNotification);
  507 + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
  508 + $oEmail->send();
  509 + }
  510 + }
509 511  
510 512  
511 513 $aUsers = $this->_getSubscribers($oFromFolder->getId(), $this->subscriptionTypes["Folder"]);
512   - $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
513   - foreach ($aUsers as $oSubscriber) {
514   -
515   - // notification object first.
516   - $aNotificationOptions = array();
517   - $aNotificationOptions['target_user'] = $oSubscriber->getID();
518   - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
519   - $aNotificationOptions['target_name'] = $oMovedDocument->getName();
520   - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId());
521   - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
522   - $aNotificationOptions['event_type'] = "MovedDocument";
523   - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
524   -
525   - // now the email content.
526   - // FIXME this needs to be handled entirely within notifications from now on.
527   - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
528   - $emailContent = $content->getEmailAlertContent($oNotification);
529   - $emailSubject = $content->getEmailAlertSubject($oNotification);
530   - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
531   - $oEmail->send();
532   - }
533   - }
  514 + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
  515 + foreach ($aUsers as $oSubscriber) {
  516 +
  517 + // notification object first.
  518 + $aNotificationOptions = array();
  519 + $aNotificationOptions['target_user'] = $oSubscriber->getID();
  520 + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
  521 + $aNotificationOptions['target_name'] = $oMovedDocument->getName();
  522 + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId());
  523 + $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
  524 + $aNotificationOptions['event_type'] = $moveOrCopy;
  525 + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
  526 +
  527 + // now the email content.
  528 + // FIXME this needs to be handled entirely within notifications from now on.
  529 + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
  530 + $emailContent = $content->getEmailAlertContent($oNotification);
  531 + $emailSubject = $content->getEmailAlertSubject($oNotification);
  532 + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
  533 + $oEmail->send();
  534 + }
  535 + }
534 536  
535 537 $aUsers = $this->_getSubscribers($oToFolder->getId(), $this->subscriptionTypes["Folder"]);
536   - $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
537   - foreach ($aUsers as $oSubscriber) {
538   -
539   - // notification object first.
540   - $aNotificationOptions = array();
541   - $aNotificationOptions['target_user'] = $oSubscriber->getID();
542   - $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
543   - $aNotificationOptions['target_name'] = $oMovedDocument->getName();
544   - $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId());
545   - $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
546   - $aNotificationOptions['event_type'] = "MovedDocument";
547   - $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
548   -
549   - // now the email content.
550   - // FIXME this needs to be handled entirely within notifications from now on.
551   - if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
552   - $emailContent = $content->getEmailAlertContent($oNotification);
553   - $emailSubject = $content->getEmailAlertSubject($oNotification);
554   - $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
555   - $oEmail->send();
556   - }
557   - }
  538 + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
  539 + foreach ($aUsers as $oSubscriber) {
  540 +
  541 + // notification object first.
  542 + $aNotificationOptions = array();
  543 + $aNotificationOptions['target_user'] = $oSubscriber->getID();
  544 + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
  545 + $aNotificationOptions['target_name'] = $oMovedDocument->getName();
  546 + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oToFolder->getId());
  547 + $aNotificationOptions['object_id'] = $oToFolder->getId(); // parent folder_id, in this case.
  548 + $aNotificationOptions['event_type'] = $moveOrCopy;
  549 + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
  550 +
  551 + // now the email content.
  552 + // FIXME this needs to be handled entirely within notifications from now on.
  553 + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
  554 + $emailContent = $content->getEmailAlertContent($oNotification);
  555 + $emailSubject = $content->getEmailAlertSubject($oNotification);
  556 + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
  557 + $oEmail->send();
  558 + }
  559 + }
558 560 }
  561 +
559 562 function ArchivedDocument($oModifiedDocument, $oParentFolder) {
560 563 $content = new SubscriptionContent(); // needed for i18n
561 564 // OK: two actions: document registrants, folder registrants.
... ... @@ -662,6 +665,59 @@ class SubscriptionEvent {
662 665 }
663 666 }
664 667  
  668 + function DownloadDocument($oDocument, $oParentFolder) {
  669 + $content = new SubscriptionContent(); // needed for i18n
  670 + // OK: two actions: document registrants, folder registrants.
  671 + $aUsers = $this->_getSubscribers($oDocument->getId(), $this->subscriptionTypes["Document"]);
  672 + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
  673 + foreach ($aUsers as $oSubscriber) {
  674 +
  675 + // notification object first.
  676 + $aNotificationOptions = array();
  677 + $aNotificationOptions['target_user'] = $oSubscriber->getID();
  678 + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
  679 + $aNotificationOptions['target_name'] = $oDocument->getName();
  680 + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId());
  681 + $aNotificationOptions['object_id'] = $oDocument->getId(); // parent folder_id, in this case.
  682 + $aNotificationOptions['event_type'] = "DownloadDocument";
  683 + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
  684 +
  685 + // now the email content.
  686 + // FIXME this needs to be handled entirely within notifications from now on.
  687 + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
  688 + $emailContent = $content->getEmailAlertContent($oNotification);
  689 + $emailSubject = $content->getEmailAlertSubject($oNotification);
  690 + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
  691 + $oEmail->send();
  692 + }
  693 + }
  694 +
  695 +
  696 + $aUsers = $this->_getSubscribers($oParentFolder->getId(), $this->subscriptionTypes["Folder"]);
  697 + $aUsers = $this->_pruneAlertedUsers($aUsers); // setup the alerted users. _might_ be a singleton.
  698 + foreach ($aUsers as $oSubscriber) {
  699 +
  700 + // notification object first.
  701 + $aNotificationOptions = array();
  702 + $aNotificationOptions['target_user'] = $oSubscriber->getID();
  703 + $aNotificationOptions['actor_id'] = KTUtil::arrayGet($_SESSION,"userID", null); // _won't_ be null.
  704 + $aNotificationOptions['target_name'] = $oDocument->getName();
  705 + $aNotificationOptions['location_name'] = Folder::generateFullFolderPath($oParentFolder->getId());
  706 + $aNotificationOptions['object_id'] = $oDocument->getId(); // parent folder_id, in this case.
  707 + $aNotificationOptions['event_type'] = "DownloadDocument";
  708 + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
  709 +
  710 + // now the email content.
  711 + // FIXME this needs to be handled entirely within notifications from now on.
  712 + if ($oSubscriber->getEmailNotification() && (strlen($oSubscriber->getEmail()) > 0)) {
  713 + $emailContent = $content->getEmailAlertContent($oNotification);
  714 + $emailSubject = $content->getEmailAlertSubject($oNotification);
  715 + $oEmail = new EmailAlert($oSubscriber->getEmail(), $emailSubject, $emailContent);
  716 + $oEmail->send();
  717 + }
  718 + }
  719 + }
  720 +
665 721 // small helper function to assist in identifying the numeric id.
666 722 function _getKeyForType($sEventType) {
667 723 foreach ($this->eventTypes as $key => $val) {
... ... @@ -733,7 +789,9 @@ class SubscriptionContent {
733 789 "CheckInDocument" => _kt('Document checked in'),
734 790 "CheckOutDocument" => _kt('Document checked out'),
735 791 "MovedDocument" => _kt('Document moved'),
  792 + "CopiedDocument" => _kt('Document copied'),
736 793 "ArchivedDocument" => _kt('Document archived'), // can go through and request un-archival (?)
  794 + "DownloadDocument" => _kt('Document downloaded'),
737 795 "RestoredArchivedDocument" => _kt('Document restored'),
738 796 "DiscussDocument" => _kt('Document Discussions updated'),
739 797 );
... ... @@ -786,7 +844,9 @@ class SubscriptionContent {
786 844 "CheckInDocument" => 'document',
787 845 "CheckOutDocument" => 'document',
788 846 "MovedDocument" => 'document',
  847 + "CopiedDocument" => 'document',
789 848 "ArchivedDocument" => 'document', // can go through and request un-archival (?)
  849 + "DownloadDocument" => 'document',
790 850 "RestoredArchivedDocument" => 'document',
791 851 "DiscussDocument" => 'document');
792 852  
... ...
plugins/ktcore/KTBulkActions.php
... ... @@ -32,6 +32,7 @@
32 32 require_once(KT_LIB_DIR . '/actions/bulkaction.php');
33 33 require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
34 34 require_once(KT_LIB_DIR . '/foldermanagement/compressionArchiveUtil.inc.php');
  35 +require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc');
35 36  
36 37  
37 38 class KTBulkDeleteAction extends KTBulkAction {
... ... @@ -477,25 +478,14 @@ class KTBulkArchiveAction extends KTBulkAction {
477 478  
478 479 function perform_action($oEntity) {
479 480 if(is_a($oEntity, 'Document')) {
480   - DBUtil::startTransaction();
481   -
482   - $document = $oEntity;
483   -
484   - $document->setStatusID(ARCHIVED);
485   - $res = $document->update();
486   - if (($res === false) || PEAR::isError($res)) {
487   - DBUtil::rollback();
488   - return false;
  481 +
  482 + $res = KTDocumentUtil::archive($oEntity, $this->sReason);
  483 +
  484 + if(PEAR::isError($res)){
  485 + return $res;
489 486 }
490   -
491   - $oDocumentTransaction = & new DocumentTransaction($document, sprintf(_kt('Document archived: %s'), $this->sReason), 'ktcore.transactions.update');
492   - $oDocumentTransaction->create();
493   -
494   - DBUtil::commit();
495 487 return true;
496 488 }else if(is_a($oEntity, 'Folder')) {
497   - DBUtil::startTransaction();
498   -
499 489 $aDocuments = array();
500 490 $aChildFolders = array();
501 491 $oFolder = $oEntity;
... ... @@ -520,7 +510,6 @@ class KTBulkArchiveAction extends KTBulkAction {
520 510 $sChildId = $oChild->getID();
521 511 $sChildDocs = $oChild->getDocumentIDs($sChildId);
522 512 if (PEAR::isError($res)) {
523   - DBUtil::rollback();
524 513 return false;
525 514 }
526 515  
... ... @@ -535,19 +524,14 @@ class KTBulkArchiveAction extends KTBulkAction {
535 524 if(!empty($aDocuments)){
536 525 foreach($aDocuments as $sDocumentId){
537 526 $oDocument = Document::get($sDocumentId);
538   -
539   - $oDocument->setStatusID(ARCHIVED);
540   - $res = $oDocument->update();
541   - if (($res === false) || PEAR::isError($res)) {
542   - DBUtil::rollback();
543   - return false;
  527 +
  528 + $res = KTDocumentUtil::archive($oEntity, $this->sReason);
  529 +
  530 + if(PEAR::isError($res)){
  531 + return $res;
544 532 }
545   -
546   - $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt('Document archived: %s'), $this->sReason), 'ktcore.transactions.update');
547   - $oDocumentTransaction->create();
548 533 }
549 534 }
550   - DBUtil::commit();
551 535 return true;
552 536 }
553 537 }
... ... @@ -557,7 +541,8 @@ class KTBrowseBulkExportAction extends KTBulkAction {
557 541 var $sName = 'ktcore.actions.bulk.export';
558 542 var $_sPermission = 'ktcore.permissions.read';
559 543 var $_bMutator = true;
560   -
  544 + var $bNotifications = true;
  545 +
561 546 function getDisplayName() {
562 547 return _kt('Export');
563 548 }
... ... @@ -589,6 +574,8 @@ class KTBrowseBulkExportAction extends KTBulkAction {
589 574 $this->startTransaction();
590 575 $oKTConfig =& KTConfig::getSingleton();
591 576 $this->bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");
  577 +
  578 + $this->bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;
592 579  
593 580 $result = parent::do_performaction();
594 581 $sExportCode = $this->oZip->createZipFile();
... ... @@ -634,6 +621,14 @@ class KTBrowseBulkExportAction extends KTBulkAction {
634 621 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
635 622 $oDocumentTransaction->create();
636 623 }
  624 +
  625 + // fire subscription alerts for the downloaded document - if global config is set
  626 + if($this->bNotifications){
  627 + $oSubscriptionEvent = new SubscriptionEvent();
  628 + $oFolder = Folder::get($oDocument->getFolderID());
  629 + $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
  630 + }
  631 +
637 632 $this->oZip->addDocumentToZip($oDocument);
638 633  
639 634 }else if(is_a($oEntity, 'Folder')) {
... ... @@ -677,6 +672,14 @@ class KTBrowseBulkExportAction extends KTBulkAction {
677 672 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
678 673 $oDocumentTransaction->create();
679 674 }
  675 +
  676 + // fire subscription alerts for the downloaded document
  677 + if($this->bNotifications){
  678 + $oSubscriptionEvent = new SubscriptionEvent();
  679 + $oFolder = Folder::get($oDocument->getFolderID());
  680 + $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
  681 + }
  682 +
680 683 $this->oZip->addDocumentToZip($oDocument);
681 684 }
682 685 }
... ...
plugins/ktcore/KTDocumentActions.php
... ... @@ -296,6 +296,16 @@ class KTDocumentViewAction extends KTDocumentAction {
296 296  
297 297 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions);
298 298 $oDocumentTransaction->create();
  299 +
  300 + // fire subscription alerts for the downloaded document
  301 + $oKTConfig =& KTConfig::getSingleton();
  302 + $bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;
  303 + if($bNotifications){
  304 + $oSubscriptionEvent = new SubscriptionEvent();
  305 + $oFolder = Folder::get($this->oDocument->getFolderID());
  306 + $oSubscriptionEvent->DownloadDocument($this->oDocument, $oFolder);
  307 + }
  308 +
299 309 exit(0);
300 310 }
301 311 }
... ... @@ -1319,34 +1329,13 @@ class KTDocumentArchiveAction extends KTDocumentAction {
1319 1329  
1320 1330 $sReason = $data['reason'];
1321 1331  
1322   - $this->startTransaction();
1323   - $this->oDocument->setStatusID(ARCHIVED);
1324   - $res = $this->oDocument->update();
1325   - if (PEAR::isError($res) || ($res === false)) {
1326   - $_SESSION['KTErrorMessage'][] = _kt('There was a database error while trying to archive this file');
  1332 + $res = KTDocumentUtil::archive($this->oDocument, $sReason);
  1333 +
  1334 + if(PEAR::isError($res)){
  1335 + $_SESSION['KTErrorMessage'][] = $res->getMessage();
1327 1336 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
1328 1337 exit(0);
1329 1338 }
1330   - $oDocumentTransaction = & new DocumentTransaction($this->oDocument, sprintf(_kt('Document archived: %s'), $sReason), 'ktcore.transactions.update');
1331   - $oDocumentTransaction->create();
1332   -
1333   - $this->commitTransaction();
1334   -
1335   - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
1336   - $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate');
1337   - foreach ($aTriggers as $aTrigger) {
1338   - $sTrigger = $aTrigger[0];
1339   - $oTrigger = new $sTrigger;
1340   - $aInfo = array(
1341   - 'document' => $this->oDocument,
1342   - );
1343   - $oTrigger->setInfo($aInfo);
1344   - $ret = $oTrigger->postValidate();
1345   - if (PEAR::isError($ret)) {
1346   - $this->oDocument->delete();
1347   - return $ret;
1348   - }
1349   - }
1350 1339  
1351 1340 $_SESSION['KTInfoMessage'][] = _kt('Document archived.');
1352 1341 controllerRedirect('browse', 'fFolderId=' . $this->oDocument->getFolderID());
... ...
plugins/ktstandard/KTBulkExportPlugin.php
... ... @@ -32,6 +32,7 @@
32 32 require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
33 33 require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
34 34 require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
  35 +require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc');
35 36  
36 37 require_once(KT_LIB_DIR . '/config/config.inc.php');
37 38 require_once(KT_LIB_DIR . '/foldermanagement/compressionArchiveUtil.inc.php');
... ... @@ -90,6 +91,7 @@ class KTBulkExportAction extends KTFolderAction {
90 91  
91 92 $oKTConfig =& KTConfig::getSingleton();
92 93 $bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");
  94 + $bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;
93 95  
94 96 // Redirect if there are no documents and no folders to export
95 97 if (empty($aDocumentIds) && empty($aFolderList)) {
... ... @@ -112,6 +114,13 @@ class KTBulkExportAction extends KTFolderAction {
112 114 $oDocumentTransaction->create();
113 115 }
114 116  
  117 + // fire subscription alerts for the downloaded document
  118 + if($bNotifications){
  119 + $oSubscriptionEvent = new SubscriptionEvent();
  120 + $oFolder = Folder::get($oDocument->getFolderID());
  121 + $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
  122 + }
  123 +
115 124 $this->oZip->addDocumentToZip($oDocument);
116 125 }
117 126 }
... ...