diff --git a/ktapi/ktapi.inc.php b/ktapi/ktapi.inc.php
index 2292c94..f308a73 100644
--- a/ktapi/ktapi.inc.php
+++ b/ktapi/ktapi.inc.php
@@ -320,6 +320,13 @@ class KTAPI
$user_ktapi->start_system_session($username);
$document = KTAPI_Document::get($user_ktapi, $document_id);
+
+ if (get_class($document) == 'PEAR_Error') {
+ return array(
+ "status_code" => 0,
+ "results" => null
+ );
+ }
$permissions = $document->getPermissionAllocation();
@@ -4462,6 +4469,27 @@ class KTAPI
}
return $response;
}
+
+ public function is_latest_version($documentID, $contentID)
+ {
+ $sql = 'SELECT COUNT(document_content_version.id) AS newdocumentcount
+ FROM document_content_version
+ WHERE document_content_version.document_id ="'.$documentID.'" AND
+ document_content_version.id > "'.$contentID.'"';
+
+ $row = DBUtil::getOneResult($sql);
+ $row = (int)$row['newdocumentcount'];
+
+ if ($row > 0) {
+ $response['is_latest'] = 'FALSE';
+ } else {
+ $response['is_latest'] = 'TRUE';
+ }
+
+ $response['status_code'] = 0;
+
+ return $response;
+ }
}
diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php
index a58b414..8089fe6 100644
--- a/lib/documentmanagement/documentutil.inc.php
+++ b/lib/documentmanagement/documentutil.inc.php
@@ -786,10 +786,12 @@ $sourceDocument->getName(),
$oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions')));
// fire subscription alerts for the checked in document
- $oSubscriptionEvent = new SubscriptionEvent();
- $oFolder = Folder::get($oDocument->getFolderID());
- $oSubscriptionEvent->AddDocument($oDocument, $oFolder);
-
+ // TODO : better way of checking if its a bulk upload
+ if($_SERVER['PATH_INFO'] != "ktcore.actions.folder.bulkUpload") {
+ $oSubscriptionEvent = new SubscriptionEvent();
+ $oFolder = Folder::get($oDocument->getFolderID());
+ $oSubscriptionEvent->AddDocument($oDocument, $oFolder);
+ }
$oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
$aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');
diff --git a/lib/import/bulkimport.inc.php b/lib/import/bulkimport.inc.php
index d6d823c..76a2d10 100644
--- a/lib/import/bulkimport.inc.php
+++ b/lib/import/bulkimport.inc.php
@@ -40,6 +40,8 @@
require_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php');
require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
require_once(KT_LIB_DIR . '/filelike/filelikeutil.inc.php');
+// // Jarrett Jordaan: Deal with bulk uploads
+require_once(KT_LIB_DIR . '/subscriptions/subscriptions.inc.php');
class KTBulkImportManager {
var $oStorage;
@@ -78,12 +80,18 @@ class KTBulkImportManager {
if (PEAR::isError($aDocPaths)) {
return $aDocPaths;
}
+ $oDocObjects = array();
foreach ($aDocPaths as $sDocumentPath) {
$res = $this->_importdocument($oFolder, $sDocumentPath);
if (PEAR::isError($res)) {
return $res;
}
+ $oDocObjects[] = $res;
}
+ // Jarrett Jordaan: Deal with bulk uploads
+ $oSubscriptionEvent = new SubscriptionEvent();
+ $oSubscriptionEvent->notifyBulkDocumentUpload($oDocObjects, $oFolder);
+
$aFolderPaths = $this->oStorage->listFolders($sPath);
if (PEAR::isError($aFolderPaths)) {
return $aFolderPaths;
diff --git a/lib/subscriptions/subscriptions.inc.php b/lib/subscriptions/subscriptions.inc.php
index e56bb80..d9766b8 100644
--- a/lib/subscriptions/subscriptions.inc.php
+++ b/lib/subscriptions/subscriptions.inc.php
@@ -95,6 +95,72 @@ class SubscriptionEvent {
* Every attempt is made to be as explicit as possible.
*/
+ /*
+ * Notification of bulk upload
+ * Author : Jarrett Jordaan
+ * Date : 27/04/09
+ *
+ * @params : KTDocumentUtil $oDocObjects
+ * KTFolderUtil $oParentFolder
+ */
+ function notifyBulkDocumentUpload($oDocObjects, $oParentFolder) {
+ $content = new SubscriptionContent(); // needed for i18n
+ $parentId = $oParentFolder->getId();
+ $aUsers = $this->_getSubscribers($parentId, $this->subscriptionTypes["Folder"]);
+ $this->bulkNotification($aUsers, 'AddDocument', $oDocObjects, $parentId);
+ }
+
+ /*
+ * Bulk upload email notification handler
+ * Author : Jarrett Jordaan
+ * Date : 27/04/09
+ *
+ * @params : User $aUsers
+ * string $eventType
+ * KTDocumentUtil $oDocObjects
+ * int $parentId
+ */
+ function bulkNotification($aUsers, $eventType, $oDocObjects, $parentId) {
+ $content = new SubscriptionContent(); // needed for i18n
+ $locationName = Folder::generateFullFolderPath($parentId);
+ $userId = $_SESSION['userID'];
+ foreach ($aUsers as $oSubscriber) {
+ $userNotifications = array();
+ $aNotificationOptions = array();
+ $userSubscriberId = $oSubscriber->getID();
+ $emailAddress = $oSubscriber->getEmail();
+ foreach($oDocObjects as $oDocObject) {
+ $targetName = $oDocObject->getName();
+ $objectId = $oDocObject->getId();
+ $aNotificationOptions['target_user'] = $userSubscriberId;
+ $aNotificationOptions['actor_id'] = $userId;
+ $aNotificationOptions['target_name'] = $targetName;
+ $aNotificationOptions['location_name'] = $locationName;
+ $aNotificationOptions['object_id'] = $objectId;
+ $aNotificationOptions['event_type'] = $eventType;
+ $oNotification =& KTSubscriptionNotification::generateSubscriptionNotification($aNotificationOptions);
+ $userNotifications[] = $oNotification;
+ }
+ $eContent = '';
+ $eSubject = '';
+ // now the email content.
+ // might not be a good idea to notify on each file
+ //foreach($userNotifications as $userNotification) {
+ // $eContent .= $content->getEmailAlertContent($userNotification)."
";
+ // Might be an over kill subject
+ //$eSubject .= $content->getEmailAlertSubject($userNotification)." ";
+ //}
+ // Better subject header with just the modified folder location
+ $eSubject = "KnowledgeTree: Subscription notification for Bulk Upload In Folder \"$locationName\"";
+ $eContent = "KnowledgeTree: Subscription notification for Bulk Upload In Folder \"$locationName\"";
+ if($eContent != '' && $eSubject != '') {
+ //echo $eContent;
+ $oEmail = new EmailAlert($emailAddress, $eSubject, $eContent);
+ $oEmail->send();
+ }
+ }
+ }
+
// alerts users who are subscribed to $iParentFolderId.
function AddFolder($oAddedFolder, $oParentFolder) {
$content = new SubscriptionContent(); // needed for i18n