Commit 1eddb324d3fc9e6d796fff4d37f6749f7dde9a32
1 parent
bb56fd0b
Merged in from STABLE trunk...
KTC-575 "Bulk checkout and export not working on folder shortcuts" Fixed. All contained documents are now downloaded and checked out correctly. Committed by: Aart-Jan Boor Reviewed by: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.3-Release-Branch@8784 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
114 additions
and
29 deletions
lib/actions/bulkaction.php
| @@ -210,6 +210,53 @@ class KTBulkAction extends KTStandardDispatcher { | @@ -210,6 +210,53 @@ class KTBulkAction extends KTStandardDispatcher { | ||
| 210 | return $symlinksPresent; | 210 | return $symlinksPresent; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | +/** | ||
| 214 | + * checks a folderList for shortcuts and queries the repositories for all folders | ||
| 215 | + * that are somehow connected to these folders. | ||
| 216 | + */ | ||
| 217 | + function getLinkingEntities($aFolderList){ | ||
| 218 | + $aSearchFolders = array(); | ||
| 219 | + if(!empty($aFolderList)){ | ||
| 220 | + foreach($aFolderList as $oFolderItem){ | ||
| 221 | + if(Permission::userHasFolderReadPermission($oFolderItem)){ | ||
| 222 | + // If it is a shortcut, we should do some more searching | ||
| 223 | + if($oFolderItem->isSymbolicLink()){ | ||
| 224 | + $oFolderItem = $oFolderItem->getLinkedFolder(); | ||
| 225 | + $aSearchFolders[] = $oFolderItem->getID(); | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + } | ||
| 230 | + $aLinkingFolders = array(); | ||
| 231 | + $aSearchCompletedFolders = array(); | ||
| 232 | + $count = 0; | ||
| 233 | + while(count($aSearchFolders)>0){ | ||
| 234 | + $count++; | ||
| 235 | + $oFolder = Folder::get(array_pop($aSearchFolders)); | ||
| 236 | + $sFolderId = $oFolder->getId(); | ||
| 237 | + // Get all the folders within the current folder | ||
| 238 | + $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR | ||
| 239 | + parent_folder_ids LIKE '{$sFolderId},%' OR | ||
| 240 | + parent_folder_ids LIKE '%,{$sFolderId},%' OR | ||
| 241 | + parent_folder_ids LIKE '%,{$sFolderId}'"; | ||
| 242 | + $aFolderList = $this->oFolder->getList($sWhereClause); | ||
| 243 | + foreach($aFolderList as $oFolderItem){ | ||
| 244 | + if($oFolderItem->isSymbolicLink()){ | ||
| 245 | + $oFolderItem = $oFolderItem->getLinkedFolder(); | ||
| 246 | + } | ||
| 247 | + if(Permission::userHasFolderReadPermission($oFolderItem)){ | ||
| 248 | + if($aSearchCompletedFolders[$oFolderItem->getID()] != true){ | ||
| 249 | + $aSearchFolders[] = $oFolderItem->getID(); | ||
| 250 | + $aSearchCompletedFolders[$oFolderItem->getID()] = true; | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + if(!isset($aLinkingFolders[$oFolder->getId()])){ | ||
| 255 | + $aLinkingFolders[$oFolder->getId()] = $oFolder; | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + return $aLinkingFolders; | ||
| 259 | + } | ||
| 213 | 260 | ||
| 214 | // doesn't actually do checks, as they have to be performed per-entity | 261 | // doesn't actually do checks, as they have to be performed per-entity |
| 215 | function check() { | 262 | function check() { |
lib/documentmanagement/documentutil.inc.php
| @@ -229,7 +229,7 @@ class KTDocumentUtil { | @@ -229,7 +229,7 @@ class KTDocumentUtil { | ||
| 229 | 229 | ||
| 230 | //send an email to the owner of the shortcut | 230 | //send an email to the owner of the shortcut |
| 231 | if($oOwnerUser->getEmail()!=null && $oOwnerUser->getEmailNotification() == true){ | 231 | if($oOwnerUser->getEmail()!=null && $oOwnerUser->getEmailNotification() == true){ |
| 232 | - $emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkDeleted",array('user_name'=>$this->oUser->getName(), | 232 | + $emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkArchived",array('user_name'=>$this->oUser->getName(), |
| 233 | 'url'=>KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), | 233 | 'url'=>KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), |
| 234 | 'title' =>$oShortcutDocument->getName())); | 234 | 'title' =>$oShortcutDocument->getName())); |
| 235 | $email = new EmailAlert($oOwnerUser->getEmail(),_kt("KnowledgeTree Notification"),$emailTemplate->getBody()); | 235 | $email = new EmailAlert($oOwnerUser->getEmail(),_kt("KnowledgeTree Notification"),$emailTemplate->getBody()); |
plugins/ktcore/KTBulkActions.php
| @@ -684,6 +684,12 @@ class KTBrowseBulkExportAction extends KTBulkAction { | @@ -684,6 +684,12 @@ class KTBrowseBulkExportAction extends KTBulkAction { | ||
| 684 | if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) { | 684 | if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) { |
| 685 | return PEAR::raiseError(_kt('Document cannot be exported')); | 685 | return PEAR::raiseError(_kt('Document cannot be exported')); |
| 686 | } | 686 | } |
| 687 | + //we need to do an extra folder permission check in case of a shortcut | ||
| 688 | + if(is_a($oEntity,'Folder') && $oEntity->isSymbolicLink()){ | ||
| 689 | + if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $this->_sPermission, $oEntity->getLinkedFolder())) { | ||
| 690 | + return PEAR::raiseError(_kt('You do not have the required permissions')); | ||
| 691 | + } | ||
| 692 | + } | ||
| 687 | return parent::check_entity($oEntity); | 693 | return parent::check_entity($oEntity); |
| 688 | } | 694 | } |
| 689 | 695 | ||
| @@ -768,6 +774,10 @@ class KTBrowseBulkExportAction extends KTBulkAction { | @@ -768,6 +774,10 @@ class KTBrowseBulkExportAction extends KTBulkAction { | ||
| 768 | }else if(is_a($oEntity, 'Folder')) { | 774 | }else if(is_a($oEntity, 'Folder')) { |
| 769 | $aDocuments = array(); | 775 | $aDocuments = array(); |
| 770 | $oFolder = $oEntity; | 776 | $oFolder = $oEntity; |
| 777 | + | ||
| 778 | + if($oFolder->isSymbolicLink()){ | ||
| 779 | + $oFolder = $oFolder->getLinkedFolder(); | ||
| 780 | + } | ||
| 771 | $sFolderId = $oFolder->getId(); | 781 | $sFolderId = $oFolder->getId(); |
| 772 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); | 782 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); |
| 773 | 783 | ||
| @@ -784,6 +794,8 @@ class KTBrowseBulkExportAction extends KTBulkAction { | @@ -784,6 +794,8 @@ class KTBrowseBulkExportAction extends KTBulkAction { | ||
| 784 | parent_folder_ids LIKE '%,{$sFolderId},%' OR | 794 | parent_folder_ids LIKE '%,{$sFolderId},%' OR |
| 785 | parent_folder_ids LIKE '%,{$sFolderId}'"; | 795 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 786 | $aFolderList = $this->oFolder->getList($sWhereClause); | 796 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 797 | + $aLinkingFolders = $this->getLinkingEntities($aFolderList); | ||
| 798 | + $aFolderList = array_merge($aFolderList,$aLinkingFolders); | ||
| 787 | 799 | ||
| 788 | $aFolderObjects = array(); | 800 | $aFolderObjects = array(); |
| 789 | $aFolderObjects[$sFolderId] = $oFolder; | 801 | $aFolderObjects[$sFolderId] = $oFolder; |
| @@ -791,16 +803,21 @@ class KTBrowseBulkExportAction extends KTBulkAction { | @@ -791,16 +803,21 @@ class KTBrowseBulkExportAction extends KTBulkAction { | ||
| 791 | // Export the folder structure to ensure the export of empty directories | 803 | // Export the folder structure to ensure the export of empty directories |
| 792 | if(!empty($aFolderList)){ | 804 | if(!empty($aFolderList)){ |
| 793 | foreach($aFolderList as $k => $oFolderItem){ | 805 | foreach($aFolderList as $k => $oFolderItem){ |
| 794 | - // Get documents for each folder | ||
| 795 | - $sFolderItemId = $oFolderItem->getID(); | ||
| 796 | - $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); | ||
| 797 | - | ||
| 798 | - if(!empty($sFolderItemDocs)){ | ||
| 799 | - $aFolderDocs = explode(',', $sFolderItemDocs); | ||
| 800 | - $aDocuments = array_merge($aDocuments, $aFolderDocs); | ||
| 801 | - } | ||
| 802 | - $this->oZip->addFolderToZip($oFolderItem); | ||
| 803 | - $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | 806 | + if(Permission::userHasFolderReadPermission($oFolderItem)){ |
| 807 | + // Get documents for each folder | ||
| 808 | + if($oFolderItem->isSymbolicLink()){ | ||
| 809 | + $oFolderItem = $oFolderItem->getLinkedFolder(); | ||
| 810 | + } | ||
| 811 | + $sFolderItemId = $oFolderItem->getID(); | ||
| 812 | + $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); | ||
| 813 | + | ||
| 814 | + if(!empty($sFolderItemDocs)){ | ||
| 815 | + $aFolderDocs = explode(',', $sFolderItemDocs); | ||
| 816 | + $aDocuments = array_merge($aDocuments, $aFolderDocs); | ||
| 817 | + } | ||
| 818 | + $this->oZip->addFolderToZip($oFolderItem); | ||
| 819 | + $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | ||
| 820 | + } | ||
| 804 | } | 821 | } |
| 805 | } | 822 | } |
| 806 | 823 | ||
| @@ -808,6 +825,9 @@ class KTBrowseBulkExportAction extends KTBulkAction { | @@ -808,6 +825,9 @@ class KTBrowseBulkExportAction extends KTBulkAction { | ||
| 808 | if(!empty($aDocuments)){ | 825 | if(!empty($aDocuments)){ |
| 809 | foreach($aDocuments as $sDocumentId){ | 826 | foreach($aDocuments as $sDocumentId){ |
| 810 | $oDocument = Document::get($sDocumentId); | 827 | $oDocument = Document::get($sDocumentId); |
| 828 | + if($oDocument->isSymbolicLink()){ | ||
| 829 | + $oDocument->switchToLinkedCore(); | ||
| 830 | + } | ||
| 811 | $sDocFolderId = $oDocument->getFolderID(); | 831 | $sDocFolderId = $oDocument->getFolderID(); |
| 812 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); | 832 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); |
| 813 | 833 | ||
| @@ -874,6 +894,12 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | @@ -874,6 +894,12 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | ||
| 874 | }else if(!is_a($oEntity, 'Folder')) { | 894 | }else if(!is_a($oEntity, 'Folder')) { |
| 875 | return PEAR::raiseError(_kt('Document cannot be checked out')); | 895 | return PEAR::raiseError(_kt('Document cannot be checked out')); |
| 876 | } | 896 | } |
| 897 | + //we need to do an extra folder permission check in case of a shortcut | ||
| 898 | + if(is_a($oEntity,'Folder') && $oEntity->isSymbolicLink()){ | ||
| 899 | + if(!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $this->_sPermission, $oEntity->getLinkedFolder())) { | ||
| 900 | + return PEAR::raiseError(_kt('You do not have the required permissions')); | ||
| 901 | + } | ||
| 902 | + } | ||
| 877 | return parent::check_entity($oEntity); | 903 | return parent::check_entity($oEntity); |
| 878 | } | 904 | } |
| 879 | 905 | ||
| @@ -1053,6 +1079,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | @@ -1053,6 +1079,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | ||
| 1053 | $aDocuments = array(); | 1079 | $aDocuments = array(); |
| 1054 | $oFolder = $oEntity; | 1080 | $oFolder = $oEntity; |
| 1055 | 1081 | ||
| 1082 | + if($oFolder->isSymbolicLink()){ | ||
| 1083 | + $oFolder = $oFolder->getLinkedFolder(); | ||
| 1084 | + } | ||
| 1056 | $sFolderId = $oFolder->getId(); | 1085 | $sFolderId = $oFolder->getId(); |
| 1057 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); | 1086 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); |
| 1058 | 1087 | ||
| @@ -1067,28 +1096,36 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | @@ -1067,28 +1096,36 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | ||
| 1067 | parent_folder_ids LIKE '%,{$sFolderId},%' OR | 1096 | parent_folder_ids LIKE '%,{$sFolderId},%' OR |
| 1068 | parent_folder_ids LIKE '%,{$sFolderId}'"; | 1097 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 1069 | $aFolderList = $this->oFolder->getList($sWhereClause); | 1098 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 1099 | + $aLinkingFolders = $this->getLinkingEntities($aFolderList); | ||
| 1100 | + $aFolderList = array_merge($aFolderList,$aLinkingFolders); | ||
| 1101 | + | ||
| 1070 | 1102 | ||
| 1071 | $aFolderObjects = array(); | 1103 | $aFolderObjects = array(); |
| 1072 | $aFolderObjects[$sFolderId] = $oFolder; | 1104 | $aFolderObjects[$sFolderId] = $oFolder; |
| 1073 | 1105 | ||
| 1074 | // Get the documents within the folder | 1106 | // Get the documents within the folder |
| 1075 | if(!empty($aFolderList)){ | 1107 | if(!empty($aFolderList)){ |
| 1076 | - foreach($aFolderList as $k => $oFolderItem){ | ||
| 1077 | - // Get documents for each folder | ||
| 1078 | - $sFolderItemId = $oFolderItem->getID(); | ||
| 1079 | - $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); | ||
| 1080 | - | ||
| 1081 | - if(!empty($sFolderItemDocs)){ | ||
| 1082 | - $aFolderDocs = explode(',', $sFolderItemDocs); | ||
| 1083 | - $aDocuments = array_merge($aDocuments, $aFolderDocs); | ||
| 1084 | - } | ||
| 1085 | - | ||
| 1086 | - // Add the folder to the zip file | ||
| 1087 | - if($this->bDownload){ | ||
| 1088 | - $this->oZip->addFolderToZip($oFolderItem); | ||
| 1089 | - $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | ||
| 1090 | - } | ||
| 1091 | - } | 1108 | + foreach($aFolderList as $k => $oFolderItem){ |
| 1109 | + if(Permission::userHasFolderReadPermission($oFolderItem)){ | ||
| 1110 | + // Get documents for each folder | ||
| 1111 | + if($oFolderItem->isSymbolicLink()){ | ||
| 1112 | + $oFolderItem = $oFolderItem->getLinkedFolder(); | ||
| 1113 | + } | ||
| 1114 | + $sFolderItemId = $oFolderItem->getID(); | ||
| 1115 | + $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); | ||
| 1116 | + | ||
| 1117 | + if(!empty($sFolderItemDocs)){ | ||
| 1118 | + $aFolderDocs = explode(',', $sFolderItemDocs); | ||
| 1119 | + $aDocuments = array_merge($aDocuments, $aFolderDocs); | ||
| 1120 | + } | ||
| 1121 | + | ||
| 1122 | + // Add the folder to the zip file | ||
| 1123 | + if($this->bDownload){ | ||
| 1124 | + $this->oZip->addFolderToZip($oFolderItem); | ||
| 1125 | + $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | ||
| 1126 | + } | ||
| 1127 | + } | ||
| 1128 | + } | ||
| 1092 | } | 1129 | } |
| 1093 | 1130 | ||
| 1094 | // Checkout each document within the folder structure | 1131 | // Checkout each document within the folder structure |
| @@ -1100,6 +1137,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | @@ -1100,6 +1137,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | ||
| 1100 | $this->addErrorMessage($oDocument->getName().': '.$oDocument->getMessage()); | 1137 | $this->addErrorMessage($oDocument->getName().': '.$oDocument->getMessage()); |
| 1101 | continue; | 1138 | continue; |
| 1102 | } | 1139 | } |
| 1140 | + if($oDocument->isSymbolicLink()){ | ||
| 1141 | + $oDocument->switchToLinkedCore(); | ||
| 1142 | + } | ||
| 1103 | 1143 | ||
| 1104 | // Check if the action is restricted by workflow on the document | 1144 | // Check if the action is restricted by workflow on the document |
| 1105 | if(!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')){ | 1145 | if(!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')){ |
| @@ -1150,8 +1190,6 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | @@ -1150,8 +1190,6 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { | ||
| 1150 | } | 1190 | } |
| 1151 | } | 1191 | } |
| 1152 | 1192 | ||
| 1153 | - $oDocument->setFileName('innerfile.pdf'); | ||
| 1154 | - | ||
| 1155 | $sDocFolderId = $oDocument->getFolderID(); | 1193 | $sDocFolderId = $oDocument->getFolderID(); |
| 1156 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); | 1194 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); |
| 1157 | $this->oZip->addDocumentToZip($oDocument, $oFolder); | 1195 | $this->oZip->addDocumentToZip($oDocument, $oFolder); |