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 | 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 | 261 | // doesn't actually do checks, as they have to be performed per-entity |
| 215 | 262 | function check() { | ... | ... |
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -229,7 +229,7 @@ class KTDocumentUtil { |
| 229 | 229 | |
| 230 | 230 | //send an email to the owner of the shortcut |
| 231 | 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 | 233 | 'url'=>KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), |
| 234 | 234 | 'title' =>$oShortcutDocument->getName())); |
| 235 | 235 | $email = new EmailAlert($oOwnerUser->getEmail(),_kt("KnowledgeTree Notification"),$emailTemplate->getBody()); | ... | ... |
plugins/ktcore/KTBulkActions.php
| ... | ... | @@ -684,6 +684,12 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 684 | 684 | if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) { |
| 685 | 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 | 693 | return parent::check_entity($oEntity); |
| 688 | 694 | } |
| 689 | 695 | |
| ... | ... | @@ -768,6 +774,10 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 768 | 774 | }else if(is_a($oEntity, 'Folder')) { |
| 769 | 775 | $aDocuments = array(); |
| 770 | 776 | $oFolder = $oEntity; |
| 777 | + | |
| 778 | + if($oFolder->isSymbolicLink()){ | |
| 779 | + $oFolder = $oFolder->getLinkedFolder(); | |
| 780 | + } | |
| 771 | 781 | $sFolderId = $oFolder->getId(); |
| 772 | 782 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); |
| 773 | 783 | |
| ... | ... | @@ -784,6 +794,8 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 784 | 794 | parent_folder_ids LIKE '%,{$sFolderId},%' OR |
| 785 | 795 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 786 | 796 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 797 | + $aLinkingFolders = $this->getLinkingEntities($aFolderList); | |
| 798 | + $aFolderList = array_merge($aFolderList,$aLinkingFolders); | |
| 787 | 799 | |
| 788 | 800 | $aFolderObjects = array(); |
| 789 | 801 | $aFolderObjects[$sFolderId] = $oFolder; |
| ... | ... | @@ -791,16 +803,21 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 791 | 803 | // Export the folder structure to ensure the export of empty directories |
| 792 | 804 | if(!empty($aFolderList)){ |
| 793 | 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 | 825 | if(!empty($aDocuments)){ |
| 809 | 826 | foreach($aDocuments as $sDocumentId){ |
| 810 | 827 | $oDocument = Document::get($sDocumentId); |
| 828 | + if($oDocument->isSymbolicLink()){ | |
| 829 | + $oDocument->switchToLinkedCore(); | |
| 830 | + } | |
| 811 | 831 | $sDocFolderId = $oDocument->getFolderID(); |
| 812 | 832 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); |
| 813 | 833 | |
| ... | ... | @@ -874,6 +894,12 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 874 | 894 | }else if(!is_a($oEntity, 'Folder')) { |
| 875 | 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 | 903 | return parent::check_entity($oEntity); |
| 878 | 904 | } |
| 879 | 905 | |
| ... | ... | @@ -1053,6 +1079,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 1053 | 1079 | $aDocuments = array(); |
| 1054 | 1080 | $oFolder = $oEntity; |
| 1055 | 1081 | |
| 1082 | + if($oFolder->isSymbolicLink()){ | |
| 1083 | + $oFolder = $oFolder->getLinkedFolder(); | |
| 1084 | + } | |
| 1056 | 1085 | $sFolderId = $oFolder->getId(); |
| 1057 | 1086 | $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); |
| 1058 | 1087 | |
| ... | ... | @@ -1067,28 +1096,36 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 1067 | 1096 | parent_folder_ids LIKE '%,{$sFolderId},%' OR |
| 1068 | 1097 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 1069 | 1098 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 1099 | + $aLinkingFolders = $this->getLinkingEntities($aFolderList); | |
| 1100 | + $aFolderList = array_merge($aFolderList,$aLinkingFolders); | |
| 1101 | + | |
| 1070 | 1102 | |
| 1071 | 1103 | $aFolderObjects = array(); |
| 1072 | 1104 | $aFolderObjects[$sFolderId] = $oFolder; |
| 1073 | 1105 | |
| 1074 | 1106 | // Get the documents within the folder |
| 1075 | 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 | 1131 | // Checkout each document within the folder structure |
| ... | ... | @@ -1100,6 +1137,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 1100 | 1137 | $this->addErrorMessage($oDocument->getName().': '.$oDocument->getMessage()); |
| 1101 | 1138 | continue; |
| 1102 | 1139 | } |
| 1140 | + if($oDocument->isSymbolicLink()){ | |
| 1141 | + $oDocument->switchToLinkedCore(); | |
| 1142 | + } | |
| 1103 | 1143 | |
| 1104 | 1144 | // Check if the action is restricted by workflow on the document |
| 1105 | 1145 | if(!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')){ |
| ... | ... | @@ -1150,8 +1190,6 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 1150 | 1190 | } |
| 1151 | 1191 | } |
| 1152 | 1192 | |
| 1153 | - $oDocument->setFileName('innerfile.pdf'); | |
| 1154 | - | |
| 1155 | 1193 | $sDocFolderId = $oDocument->getFolderID(); |
| 1156 | 1194 | $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); |
| 1157 | 1195 | $this->oZip->addDocumentToZip($oDocument, $oFolder); | ... | ... |