Commit 4ab25e4f4368677857aeb70096d36e4e14a9840a
1 parent
a46e0c7d
KTS-4252: Bulk Upload Notication sends single email to subscribed user
Committed by: Jarrett Jordaan Reviewed by: Megan Watson
Showing
3 changed files
with
80 additions
and
4 deletions
lib/documentmanagement/documentutil.inc.php
| @@ -786,10 +786,12 @@ $sourceDocument->getName(), | @@ -786,10 +786,12 @@ $sourceDocument->getName(), | ||
| 786 | 786 | ||
| 787 | $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); | 787 | $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); |
| 788 | // fire subscription alerts for the checked in document | 788 | // fire subscription alerts for the checked in document |
| 789 | - $oSubscriptionEvent = new SubscriptionEvent(); | ||
| 790 | - $oFolder = Folder::get($oDocument->getFolderID()); | ||
| 791 | - $oSubscriptionEvent->AddDocument($oDocument, $oFolder); | ||
| 792 | - | 789 | + // TODO : better way of checking if its a bulk upload |
| 790 | + if($_SERVER['PATH_INFO'] != "ktcore.actions.folder.bulkUpload") { | ||
| 791 | + $oSubscriptionEvent = new SubscriptionEvent(); | ||
| 792 | + $oFolder = Folder::get($oDocument->getFolderID()); | ||
| 793 | + $oSubscriptionEvent->AddDocument($oDocument, $oFolder); | ||
| 794 | + } | ||
| 793 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | 795 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 794 | $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate'); | 796 | $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate'); |
| 795 | 797 |
lib/import/bulkimport.inc.php
| @@ -40,6 +40,8 @@ | @@ -40,6 +40,8 @@ | ||
| 40 | require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'); | 40 | require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'); |
| 41 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | 41 | require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); |
| 42 | require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php'); | 42 | require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php'); |
| 43 | +// // Jarrett Jordaan: Deal with bulk uploads | ||
| 44 | +require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php'); | ||
| 43 | 45 | ||
| 44 | class KTBulkImportManager { | 46 | class KTBulkImportManager { |
| 45 | var $oStorage; | 47 | var $oStorage; |
| @@ -78,12 +80,18 @@ class KTBulkImportManager { | @@ -78,12 +80,18 @@ class KTBulkImportManager { | ||
| 78 | if (PEAR::isError($aDocPaths)) { | 80 | if (PEAR::isError($aDocPaths)) { |
| 79 | return $aDocPaths; | 81 | return $aDocPaths; |
| 80 | } | 82 | } |
| 83 | + $oDocObjects = array(); | ||
| 81 | foreach ($aDocPaths as $sDocumentPath) { | 84 | foreach ($aDocPaths as $sDocumentPath) { |
| 82 | $res = $this->_importdocument($oFolder, $sDocumentPath); | 85 | $res = $this->_importdocument($oFolder, $sDocumentPath); |
| 83 | if (PEAR::isError($res)) { | 86 | if (PEAR::isError($res)) { |
| 84 | return $res; | 87 | return $res; |
| 85 | } | 88 | } |
| 89 | + $oDocObjects[] = $res; | ||
| 86 | } | 90 | } |
| 91 | + // Jarrett Jordaan: Deal with bulk uploads | ||
| 92 | + $oSubscriptionEvent = new SubscriptionEvent(); | ||
| 93 | + $oSubscriptionEvent->notifyBulkDocumentUpload($oDocObjects, $oFolder); | ||
| 94 | + | ||
| 87 | $aFolderPaths = $this->oStorage->listFolders($sPath); | 95 | $aFolderPaths = $this->oStorage->listFolders($sPath); |
| 88 | if (PEAR::isError($aFolderPaths)) { | 96 | if (PEAR::isError($aFolderPaths)) { |
| 89 | return $aFolderPaths; | 97 | return $aFolderPaths; |
lib/subscriptions/subscriptions.inc.php
| @@ -95,6 +95,72 @@ class SubscriptionEvent { | @@ -95,6 +95,72 @@ class SubscriptionEvent { | ||
| 95 | * Every attempt is made to be as explicit as possible. | 95 | * Every attempt is made to be as explicit as possible. |
| 96 | */ | 96 | */ |
| 97 | 97 | ||
| 98 | + /* | ||
| 99 | + * Notification of bulk upload | ||
| 100 | + * Author : Jarrett Jordaan | ||
| 101 | + * Date : 27/04/09 | ||
| 102 | + * | ||
| 103 | + * @params : KTDocumentUtil $oDocObjects | ||
| 104 | + * KTFolderUtil $oParentFolder | ||
| 105 | + */ | ||
| 106 | + function notifyBulkDocumentUpload($oDocObjects, $oParentFolder) { | ||
| 107 | + $content = new SubscriptionContent(); // needed for i18n | ||
| 108 | + $parentId = $oParentFolder->getId(); | ||
| 109 | + $aUsers = $this->_getSubscribers($parentId, $this->subscriptionTypes["Folder"]); | ||
| 110 | + $this->bulkNotification($aUsers, 'AddDocument', $oDocObjects, $parentId); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /* | ||
| 114 | + * Bulk upload email notification handler | ||
| 115 | + * Author : Jarrett Jordaan | ||
| 116 | + * Date : 27/04/09 | ||
| 117 | + * | ||
| 118 | + * @params : User $aUsers | ||
| 119 | + * string $eventType | ||
| 120 | + * KTDocumentUtil $oDocObjects | ||
| 121 | + * int $parentId | ||
| 122 | + */ | ||
| 123 | + function bulkNotification($aUsers, $eventType, $oDocObjects, $parentId) { | ||
| 124 | + $content = new SubscriptionContent(); // needed for i18n | ||
| 125 | + $locationName = Folder::generateFullFolderPath($parentId); | ||
| 126 | + $userId = $_SESSION['userID']; | ||
| 127 | + foreach ($aUsers as $oSubscriber) { | ||
| 128 | + $userNotifications = array(); | ||
| 129 | + $aNotificationOptions = array(); | ||
| 130 | + $userSubscriberId = $oSubscriber->getID(); | ||
| 131 | + $emailAddress = $oSubscriber->getEmail(); | ||
| 132 | + foreach($oDocObjects as $oDocObject) { | ||
| 133 | + $targetName = $oDocObject->getName(); | ||
| 134 | + $objectId = $oDocObject->getId(); | ||
| 135 | + $aNotificationOptions['target_user'] = $userSubscriberId; | ||
| 136 | + $aNotificationOptions['actor_id'] = $userId; | ||
| 137 | + $aNotificationOptions['target_name'] = $targetName; | ||
| 138 | + $aNotificationOptions['location_name'] = $locationName; | ||
| 139 | + $aNotificationOptions['object_id'] = $objectId; | ||
| 140 | + $aNotificationOptions['event_type'] = $eventType; | ||
| 141 | + $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions); | ||
| 142 | + $userNotifications[] = $oNotification; | ||
| 143 | + } | ||
| 144 | + $eContent = ''; | ||
| 145 | + $eSubject = ''; | ||
| 146 | + // now the email content. | ||
| 147 | + // might not be a good idea to notify on each file | ||
| 148 | + //foreach($userNotifications as $userNotification) { | ||
| 149 | + // $eContent .= $content->getEmailAlertContent($userNotification)."<br/><br/>"; | ||
| 150 | + // Might be an over kill subject | ||
| 151 | + //$eSubject .= $content->getEmailAlertSubject($userNotification)." "; | ||
| 152 | + //} | ||
| 153 | + // Better subject header with just the modified folder location | ||
| 154 | + $eSubject = "KnowledgeTree: Subscription notification for Bulk Upload In Folder \"$locationName\""; | ||
| 155 | + $eContent = "KnowledgeTree: Subscription notification for Bulk Upload In Folder \"$locationName\""; | ||
| 156 | + if($eContent != '' && $eSubject != '') { | ||
| 157 | + //echo $eContent; | ||
| 158 | + $oEmail = new EmailAlert($emailAddress, $eSubject, $eContent); | ||
| 159 | + $oEmail->send(); | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + | ||
| 98 | // alerts users who are subscribed to $iParentFolderId. | 164 | // alerts users who are subscribed to $iParentFolderId. |
| 99 | function AddFolder($oAddedFolder, $oParentFolder) { | 165 | function AddFolder($oAddedFolder, $oParentFolder) { |
| 100 | $content = new SubscriptionContent(); // needed for i18n | 166 | $content = new SubscriptionContent(); // needed for i18n |