Commit ec5cdebb764c04523047b5cfb854c3f8530d5b6b

Authored by michael
1 parent e4715463

notify users that requested archived document restoration when its restored


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2091 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php
... ... @@ -2,7 +2,9 @@
2 2  
3 3 require_once("../../../../../config/dmsDefaults.php");
4 4 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
5   -
  5 +require_once("$default->fileSystemRoot/lib/archiving/ArchiveRestorationRequest.inc");
  6 +require_once("$default->fileSystemRoot/lib/email/Email.inc");
  7 +require_once("$default->fileSystemRoot/lib/users/User.inc");
6 8 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
7 9 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
8 10 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
... ... @@ -63,10 +65,7 @@ if (checkSession()) {
63 65 $aErrorDocuments = array();
64 66 $aSuccessDocuments = array();
65 67 for ($i = 0; $i < count($aDocuments); $i++) {
66   - if ($aDocuments[$i]) {
67   - // TODO: check if there are requests for this document to be archived
68   - // and email them
69   - // FIXME: refactor notification
  68 + if ($aDocuments[$i]) {
70 69  
71 70 // set the status to live
72 71 $aDocuments[$i]->setStatusID(lookupStatusID("Live"));
... ... @@ -74,6 +73,31 @@ if (checkSession()) {
74 73 // success
75 74 $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]);
76 75 $aSuccessDocuments[] = $aDocuments[$i];
  76 +
  77 + // check if there are requests for this document to be archived
  78 + $aRequests = ArchiveRestorationRequest::getList("document_id=" . $aDocuments[$i]->getID());
  79 + $default->log->info("manageArchivedDocumentsBL.php about to send notification for " . count($aRequests) . " restoration requests for document id " . $aDocuments[$i]->getID());
  80 + for ($j=0; $j<count($aRequests); $j++) {
  81 + // email the users
  82 + // FIXME: refactor notification
  83 + // TODO: check email notification and valid email address
  84 + $oRequestUser = User::get($aRequests[$j]->getRequestUserID());
  85 + $sBody = "The document '" . generateControllerLink("viewDocument", "fDocumentID=" . $aDocuments[$i]->getID(), $aDocuments[$i]->getName()) . "'";
  86 + $sBody .= " has been restored from the archive.";
  87 + $oEmail = & new Email();
  88 + if ($oEmail->send($oRequestUser->getEmail(), "Archived Document Restored", $sBody)) {
  89 + $default->log->info("manageArchivedDocumentsBL.php sent email to " . $oRequestUser->getEmail());
  90 + // now delete the request
  91 + $iRequestID = $aRequests[$j]->getID();
  92 + if ($aRequests[$j]->delete()) {
  93 + $default->log->info("manageArchivedDocumentsBL.php removing restoration request $iRequestID");
  94 + } else {
  95 + $default->log->error("manageArchivedDocumentsBL.php error removing request $iRequestID");
  96 + }
  97 + } else {
  98 + $default->log->error("manageArchivedDocumentsBL.php error notifying " . arrayToString($oEmail) . " for document id " . $aDocuments[$i]->getID() . " restoration");
  99 + }
  100 + }
77 101 } else{
78 102 // error updating status change
79 103 $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
... ...