Commit 1f0c45fd6b90bfee62ae05a5a3d0a7d488288f7a

Authored by Megan Watson
2 parents e58cd269 285212fc

Merge branch 'master' of git@github.com:ktgit/knowledgetree

ktapi/ktapi.inc.php
... ... @@ -320,6 +320,13 @@ class KTAPI
320 320 $user_ktapi->start_system_session($username);
321 321  
322 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 331 $permissions = $document->getPermissionAllocation();
325 332  
... ... @@ -4462,6 +4469,27 @@ class KTAPI
4462 4469 }
4463 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 786  
787 787 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions')));
788 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 795 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
794 796 $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');
795 797  
... ...
lib/import/bulkimport.inc.php
... ... @@ -40,6 +40,8 @@
40 40 require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
41 41 require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
42 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 46 class KTBulkImportManager {
45 47 var $oStorage;
... ... @@ -78,12 +80,18 @@ class KTBulkImportManager {
78 80 if (PEAR::isError($aDocPaths)) {
79 81 return $aDocPaths;
80 82 }
  83 + $oDocObjects = array();
81 84 foreach ($aDocPaths as $sDocumentPath) {
82 85 $res = $this->_importdocument($oFolder, $sDocumentPath);
83 86 if (PEAR::isError($res)) {
84 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 95 $aFolderPaths = $this->oStorage->listFolders($sPath);
88 96 if (PEAR::isError($aFolderPaths)) {
89 97 return $aFolderPaths;
... ...
lib/subscriptions/subscriptions.inc.php
... ... @@ -95,6 +95,72 @@ class SubscriptionEvent {
95 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 164 // alerts users who are subscribed to $iParentFolderId.
99 165 function AddFolder($oAddedFolder, $oParentFolder) {
100 166 $content = new SubscriptionContent(); // needed for i18n
... ...