Commit 1f0c45fd6b90bfee62ae05a5a3d0a7d488288f7a
Merge branch 'master' of git@github.com:ktgit/knowledgetree
Showing
4 changed files
with
108 additions
and
4 deletions
ktapi/ktapi.inc.php
| @@ -320,6 +320,13 @@ class KTAPI | @@ -320,6 +320,13 @@ class KTAPI | ||
| 320 | $user_ktapi->start_system_session($username); | 320 | $user_ktapi->start_system_session($username); |
| 321 | 321 | ||
| 322 | $document = KTAPI_Document::get($user_ktapi, $document_id); | 322 | $document = KTAPI_Document::get($user_ktapi, $document_id); |
| 323 | + | ||
| 324 | + if (get_class($document) == 'PEAR_Error') { | ||
| 325 | + return array( | ||
| 326 | + "status_code" => 0, | ||
| 327 | + "results" => null | ||
| 328 | + ); | ||
| 329 | + } | ||
| 323 | 330 | ||
| 324 | $permissions = $document->getPermissionAllocation(); | 331 | $permissions = $document->getPermissionAllocation(); |
| 325 | 332 | ||
| @@ -4462,6 +4469,27 @@ class KTAPI | @@ -4462,6 +4469,27 @@ class KTAPI | ||
| 4462 | } | 4469 | } |
| 4463 | return $response; | 4470 | return $response; |
| 4464 | } | 4471 | } |
| 4472 | + | ||
| 4473 | + public function is_latest_version($documentID, $contentID) | ||
| 4474 | + { | ||
| 4475 | + $sql = 'SELECT COUNT(document_content_version.id) AS newdocumentcount | ||
| 4476 | + FROM document_content_version | ||
| 4477 | + WHERE document_content_version.document_id ="'.$documentID.'" AND | ||
| 4478 | + document_content_version.id > "'.$contentID.'"'; | ||
| 4479 | + | ||
| 4480 | + $row = DBUtil::getOneResult($sql); | ||
| 4481 | + $row = (int)$row['newdocumentcount']; | ||
| 4482 | + | ||
| 4483 | + if ($row > 0) { | ||
| 4484 | + $response['is_latest'] = 'FALSE'; | ||
| 4485 | + } else { | ||
| 4486 | + $response['is_latest'] = 'TRUE'; | ||
| 4487 | + } | ||
| 4488 | + | ||
| 4489 | + $response['status_code'] = 0; | ||
| 4490 | + | ||
| 4491 | + return $response; | ||
| 4492 | + } | ||
| 4465 | } | 4493 | } |
| 4466 | 4494 | ||
| 4467 | 4495 |
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 |