Commit 1c2cc1a723001f9fdbe0f443f72ddcc0a5ab94a3
1 parent
a4991af5
KTC-296
"Bulk Download scrambles the folder hierarchy and only exports the first non-empty subfolder." Fixed. The document paths were missing the last folder in the path and being added to the one below. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7807 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
62 additions
and
34 deletions
lib/foldermanagement/compressionArchiveUtil.inc.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -79,10 +79,17 @@ class ZipFolder { |
| 79 | 79 | /** |
| 80 | 80 | * Add a document to the zip file |
| 81 | 81 | */ |
| 82 | - function addDocumentToZip($oDocument) { | |
| 83 | - $sParentFolder = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf('%s/%s', $this->sTmpPath, $oDocument->getFullPath())))); | |
| 82 | + function addDocumentToZip($oDocument, $oFolder = null) { | |
| 83 | + if(empty($oFolder)){ | |
| 84 | + $oFolder = Folder::get($oDocument->getFolderID()); | |
| 85 | + } | |
| 86 | + | |
| 87 | + $sDocPath = $oFolder->getFullPath().'/'.$oFolder->getName(); | |
| 88 | + $sDocName = $oDocument->getFileName(); | |
| 89 | + | |
| 90 | + $sParentFolder = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf('%s/%s', $this->sTmpPath, $sDocPath)))); | |
| 84 | 91 | $newDir = $this->sTmpPath; |
| 85 | - $sFullPath = str_replace('<', '', str_replace('</', '', str_replace('>', '', $this->_convertEncoding($oDocument->getFullPath(), true)))); | |
| 92 | + $sFullPath = str_replace('<', '', str_replace('</', '', str_replace('>', '', $this->_convertEncoding($sDocPath, true)))); | |
| 86 | 93 | foreach (split('/', $sFullPath) as $dirPart) { |
| 87 | 94 | $newDir = sprintf("%s/%s", $newDir, $dirPart); |
| 88 | 95 | if (!file_exists($newDir)) { |
| ... | ... | @@ -91,11 +98,11 @@ class ZipFolder { |
| 91 | 98 | } |
| 92 | 99 | |
| 93 | 100 | $sOrigFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $this->oStorage->temporaryFile($oDocument)))); |
| 94 | - $sFilename = sprintf("%s/%s", $sParentFolder, str_replace('<', '', str_replace('</', '', str_replace('>', '', $oDocument->getFileName())))); | |
| 101 | + $sFilename = sprintf("%s/%s", $sParentFolder, str_replace('<', '', str_replace('</', '', str_replace('>', '', $sDocName)))); | |
| 95 | 102 | $sFilename = $this->_convertEncoding($sFilename, true); |
| 96 | 103 | copy($sOrigFile, $sFilename); |
| 97 | 104 | |
| 98 | - $sPath = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf("%s/%s", $oDocument->getFullPath(), $oDocument->getFileName())))); | |
| 105 | + $sPath = str_replace('<', '', str_replace('</', '', str_replace('>', '', sprintf("%s/%s", $sDocPath, $sDocName)))); | |
| 99 | 106 | $sPath = str_replace($this->aReplaceKeys, $this->aReplaceValues, $sPath); |
| 100 | 107 | $sPath = $this->_convertEncoding($sPath, true); |
| 101 | 108 | ... | ... |
plugins/ktcore/KTBulkActions.php
| ... | ... | @@ -661,6 +661,9 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 661 | 661 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 662 | 662 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 663 | 663 | |
| 664 | + $aFolderObjects = array(); | |
| 665 | + $aFolderObjects[$sFolderId] = $oFolder; | |
| 666 | + | |
| 664 | 667 | // Export the folder structure to ensure the export of empty directories |
| 665 | 668 | if(!empty($aFolderList)){ |
| 666 | 669 | foreach($aFolderList as $k => $oFolderItem){ |
| ... | ... | @@ -673,6 +676,7 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 673 | 676 | $aDocuments = array_merge($aDocuments, $aFolderDocs); |
| 674 | 677 | } |
| 675 | 678 | $this->oZip->addFolderToZip($oFolderItem); |
| 679 | + $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | |
| 676 | 680 | } |
| 677 | 681 | } |
| 678 | 682 | |
| ... | ... | @@ -680,6 +684,8 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 680 | 684 | if(!empty($aDocuments)){ |
| 681 | 685 | foreach($aDocuments as $sDocumentId){ |
| 682 | 686 | $oDocument = Document::get($sDocumentId); |
| 687 | + $sDocFolderId = $oDocument->getFolderID(); | |
| 688 | + $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); | |
| 683 | 689 | |
| 684 | 690 | if ($this->bNoisy) { |
| 685 | 691 | $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); |
| ... | ... | @@ -689,11 +695,10 @@ class KTBrowseBulkExportAction extends KTBulkAction { |
| 689 | 695 | // fire subscription alerts for the downloaded document |
| 690 | 696 | if($this->bNotifications){ |
| 691 | 697 | $oSubscriptionEvent = new SubscriptionEvent(); |
| 692 | - $oFolder = Folder::get($oDocument->getFolderID()); | |
| 693 | 698 | $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); |
| 694 | 699 | } |
| 695 | 700 | |
| 696 | - $this->oZip->addDocumentToZip($oDocument); | |
| 701 | + $this->oZip->addDocumentToZip($oDocument, $oFolder); | |
| 697 | 702 | } |
| 698 | 703 | } |
| 699 | 704 | } |
| ... | ... | @@ -906,6 +911,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 906 | 911 | parent_folder_ids LIKE '%,{$sFolderId}'"; |
| 907 | 912 | $aFolderList = $this->oFolder->getList($sWhereClause); |
| 908 | 913 | |
| 914 | + $aFolderObjects = array(); | |
| 915 | + $aFolderObjects[$sFolderId] = $oFolder; | |
| 916 | + | |
| 909 | 917 | // Get the documents within the folder |
| 910 | 918 | if(!empty($aFolderList)){ |
| 911 | 919 | foreach($aFolderList as $k => $oFolderItem){ |
| ... | ... | @@ -921,6 +929,7 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 921 | 929 | // Add the folder to the zip file |
| 922 | 930 | if($this->bDownload){ |
| 923 | 931 | $this->oZip->addFolderToZip($oFolderItem); |
| 932 | + $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | |
| 924 | 933 | } |
| 925 | 934 | } |
| 926 | 935 | } |
| ... | ... | @@ -961,7 +970,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { |
| 961 | 970 | $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array()); |
| 962 | 971 | $oDocumentTransaction->create(); |
| 963 | 972 | } |
| 964 | - $this->oZip->addDocumentToZip($oDocument); | |
| 973 | + $sDocFolderId = $oDocument->getFolderID(); | |
| 974 | + $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); | |
| 975 | + $this->oZip->addDocumentToZip($oDocument, $oFolder); | |
| 965 | 976 | } |
| 966 | 977 | } |
| 967 | 978 | } | ... | ... |
plugins/ktstandard/KTBulkExportPlugin.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -109,9 +109,24 @@ class KTBulkExportAction extends KTFolderAction { |
| 109 | 109 | $this->oPage->template = "kt3/minimal_page"; |
| 110 | 110 | $this->handleOutput(""); |
| 111 | 111 | |
| 112 | + // Create associative array of folder items for use by the contained documents | |
| 113 | + $aFolderObjects = array(); | |
| 114 | + $aFolderObjects[$sCurrentFolderId] = $this->oFolder; | |
| 115 | + | |
| 116 | + // Export the folder structure to ensure the export of empty directories | |
| 117 | + if(!empty($aFolderList)){ | |
| 118 | + foreach($aFolderList as $k => $oFolderItem){ | |
| 119 | + $this->oZip->addFolderToZip($oFolderItem); | |
| 120 | + $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 112 | 124 | if(!empty($aDocumentIds)){ |
| 113 | 125 | foreach ($aDocumentIds as $iId) { |
| 114 | 126 | $oDocument = Document::get($iId); |
| 127 | + $sFolderId = $oDocument->getFolderID(); | |
| 128 | + | |
| 129 | + $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId); | |
| 115 | 130 | |
| 116 | 131 | if ($bNoisy) { |
| 117 | 132 | $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); |
| ... | ... | @@ -121,19 +136,13 @@ class KTBulkExportAction extends KTFolderAction { |
| 121 | 136 | // fire subscription alerts for the downloaded document |
| 122 | 137 | if($bNotifications){ |
| 123 | 138 | $oSubscriptionEvent = new SubscriptionEvent(); |
| 124 | - $oFolder = Folder::get($oDocument->getFolderID()); | |
| 125 | 139 | $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); |
| 126 | 140 | } |
| 127 | 141 | |
| 128 | - $this->oZip->addDocumentToZip($oDocument); | |
| 142 | + $this->oZip->addDocumentToZip($oDocument, $oFolder); | |
| 129 | 143 | } |
| 130 | 144 | } |
| 131 | 145 | |
| 132 | - // Export the folder structure to ensure the export of empty directories | |
| 133 | - foreach($aFolderList as $k => $oFolderItem){ | |
| 134 | - $this->oZip->addFolderToZip($oFolderItem); | |
| 135 | - } | |
| 136 | - | |
| 137 | 146 | $sExportCode = $this->oZip->createZipFile(TRUE); |
| 138 | 147 | |
| 139 | 148 | $oTransaction = KTFolderTransaction::createFromArray(array( |
| ... | ... | @@ -168,7 +177,7 @@ class KTBulkExportAction extends KTFolderAction { |
| 168 | 177 | return $res; |
| 169 | 178 | } |
| 170 | 179 | list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res; |
| 171 | - $aPotentialWhere = array($sPermissionString, 'D.parent_folder_ids = ? OR D.parent_folder_ids LIKE ?', 'D.status_id = 1'); | |
| 180 | + $aPotentialWhere = array($sPermissionString, 'D.folder_id = ? OR D.parent_folder_ids = ? OR D.parent_folder_ids LIKE ?', 'D.status_id = 1'); | |
| 172 | 181 | $aWhere = array(); |
| 173 | 182 | foreach ($aPotentialWhere as $sWhere) { |
| 174 | 183 | if (empty($sWhere)) { |
| ... | ... | @@ -202,6 +211,7 @@ class KTBulkExportAction extends KTFolderAction { |
| 202 | 211 | array_shift($aParentFolderIds); |
| 203 | 212 | } |
| 204 | 213 | $sParentFolderIds = join(',', $aParentFolderIds); |
| 214 | + $aParams[] = $this->oFolder->getId(); | |
| 205 | 215 | $aParams[] = $sParentFolderIds; |
| 206 | 216 | $aParams[] = $sParentFolderIds . ",%"; |
| 207 | 217 | return array($sQuery, $aParams); | ... | ... |