Commit 1c2cc1a723001f9fdbe0f443f72ddcc0a5ab94a3

Authored by Megan Watson
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
lib/foldermanagement/compressionArchiveUtil.inc.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 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 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 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 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -79,10 +79,17 @@ class ZipFolder { @@ -79,10 +79,17 @@ class ZipFolder {
79 /** 79 /**
80 * Add a document to the zip file 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 $newDir = $this->sTmpPath; 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 foreach (split('/', $sFullPath) as $dirPart) { 93 foreach (split('/', $sFullPath) as $dirPart) {
87 $newDir = sprintf("%s/%s", $newDir, $dirPart); 94 $newDir = sprintf("%s/%s", $newDir, $dirPart);
88 if (!file_exists($newDir)) { 95 if (!file_exists($newDir)) {
@@ -91,11 +98,11 @@ class ZipFolder { @@ -91,11 +98,11 @@ class ZipFolder {
91 } 98 }
92 99
93 $sOrigFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $this->oStorage->temporaryFile($oDocument)))); 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 $sFilename = $this->_convertEncoding($sFilename, true); 102 $sFilename = $this->_convertEncoding($sFilename, true);
96 copy($sOrigFile, $sFilename); 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 $sPath = str_replace($this->aReplaceKeys, $this->aReplaceValues, $sPath); 106 $sPath = str_replace($this->aReplaceKeys, $this->aReplaceValues, $sPath);
100 $sPath = $this->_convertEncoding($sPath, true); 107 $sPath = $this->_convertEncoding($sPath, true);
101 108
plugins/ktcore/KTBulkActions.php
@@ -661,6 +661,9 @@ class KTBrowseBulkExportAction extends KTBulkAction { @@ -661,6 +661,9 @@ class KTBrowseBulkExportAction extends KTBulkAction {
661 parent_folder_ids LIKE '%,{$sFolderId}'"; 661 parent_folder_ids LIKE '%,{$sFolderId}'";
662 $aFolderList = $this->oFolder->getList($sWhereClause); 662 $aFolderList = $this->oFolder->getList($sWhereClause);
663 663
  664 + $aFolderObjects = array();
  665 + $aFolderObjects[$sFolderId] = $oFolder;
  666 +
664 // Export the folder structure to ensure the export of empty directories 667 // Export the folder structure to ensure the export of empty directories
665 if(!empty($aFolderList)){ 668 if(!empty($aFolderList)){
666 foreach($aFolderList as $k => $oFolderItem){ 669 foreach($aFolderList as $k => $oFolderItem){
@@ -673,6 +676,7 @@ class KTBrowseBulkExportAction extends KTBulkAction { @@ -673,6 +676,7 @@ class KTBrowseBulkExportAction extends KTBulkAction {
673 $aDocuments = array_merge($aDocuments, $aFolderDocs); 676 $aDocuments = array_merge($aDocuments, $aFolderDocs);
674 } 677 }
675 $this->oZip->addFolderToZip($oFolderItem); 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,6 +684,8 @@ class KTBrowseBulkExportAction extends KTBulkAction {
680 if(!empty($aDocuments)){ 684 if(!empty($aDocuments)){
681 foreach($aDocuments as $sDocumentId){ 685 foreach($aDocuments as $sDocumentId){
682 $oDocument = Document::get($sDocumentId); 686 $oDocument = Document::get($sDocumentId);
  687 + $sDocFolderId = $oDocument->getFolderID();
  688 + $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
683 689
684 if ($this->bNoisy) { 690 if ($this->bNoisy) {
685 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); 691 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
@@ -689,11 +695,10 @@ class KTBrowseBulkExportAction extends KTBulkAction { @@ -689,11 +695,10 @@ class KTBrowseBulkExportAction extends KTBulkAction {
689 // fire subscription alerts for the downloaded document 695 // fire subscription alerts for the downloaded document
690 if($this->bNotifications){ 696 if($this->bNotifications){
691 $oSubscriptionEvent = new SubscriptionEvent(); 697 $oSubscriptionEvent = new SubscriptionEvent();
692 - $oFolder = Folder::get($oDocument->getFolderID());  
693 $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); 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,6 +911,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction {
906 parent_folder_ids LIKE '%,{$sFolderId}'"; 911 parent_folder_ids LIKE '%,{$sFolderId}'";
907 $aFolderList = $this->oFolder->getList($sWhereClause); 912 $aFolderList = $this->oFolder->getList($sWhereClause);
908 913
  914 + $aFolderObjects = array();
  915 + $aFolderObjects[$sFolderId] = $oFolder;
  916 +
909 // Get the documents within the folder 917 // Get the documents within the folder
910 if(!empty($aFolderList)){ 918 if(!empty($aFolderList)){
911 foreach($aFolderList as $k => $oFolderItem){ 919 foreach($aFolderList as $k => $oFolderItem){
@@ -921,6 +929,7 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction { @@ -921,6 +929,7 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction {
921 // Add the folder to the zip file 929 // Add the folder to the zip file
922 if($this->bDownload){ 930 if($this->bDownload){
923 $this->oZip->addFolderToZip($oFolderItem); 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,7 +970,9 @@ class KTBrowseBulkCheckoutAction extends KTBulkAction {
961 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array()); 970 $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array());
962 $oDocumentTransaction->create(); 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,32 +5,32 @@
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 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 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 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 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -109,9 +109,24 @@ class KTBulkExportAction extends KTFolderAction { @@ -109,9 +109,24 @@ class KTBulkExportAction extends KTFolderAction {
109 $this->oPage->template = "kt3/minimal_page"; 109 $this->oPage->template = "kt3/minimal_page";
110 $this->handleOutput(""); 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 if(!empty($aDocumentIds)){ 124 if(!empty($aDocumentIds)){
113 foreach ($aDocumentIds as $iId) { 125 foreach ($aDocumentIds as $iId) {
114 $oDocument = Document::get($iId); 126 $oDocument = Document::get($iId);
  127 + $sFolderId = $oDocument->getFolderID();
  128 +
  129 + $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId);
115 130
116 if ($bNoisy) { 131 if ($bNoisy) {
117 $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array()); 132 $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
@@ -121,19 +136,13 @@ class KTBulkExportAction extends KTFolderAction { @@ -121,19 +136,13 @@ class KTBulkExportAction extends KTFolderAction {
121 // fire subscription alerts for the downloaded document 136 // fire subscription alerts for the downloaded document
122 if($bNotifications){ 137 if($bNotifications){
123 $oSubscriptionEvent = new SubscriptionEvent(); 138 $oSubscriptionEvent = new SubscriptionEvent();
124 - $oFolder = Folder::get($oDocument->getFolderID());  
125 $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); 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 $sExportCode = $this->oZip->createZipFile(TRUE); 146 $sExportCode = $this->oZip->createZipFile(TRUE);
138 147
139 $oTransaction = KTFolderTransaction::createFromArray(array( 148 $oTransaction = KTFolderTransaction::createFromArray(array(
@@ -168,7 +177,7 @@ class KTBulkExportAction extends KTFolderAction { @@ -168,7 +177,7 @@ class KTBulkExportAction extends KTFolderAction {
168 return $res; 177 return $res;
169 } 178 }
170 list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res; 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 $aWhere = array(); 181 $aWhere = array();
173 foreach ($aPotentialWhere as $sWhere) { 182 foreach ($aPotentialWhere as $sWhere) {
174 if (empty($sWhere)) { 183 if (empty($sWhere)) {
@@ -202,6 +211,7 @@ class KTBulkExportAction extends KTFolderAction { @@ -202,6 +211,7 @@ class KTBulkExportAction extends KTFolderAction {
202 array_shift($aParentFolderIds); 211 array_shift($aParentFolderIds);
203 } 212 }
204 $sParentFolderIds = join(',', $aParentFolderIds); 213 $sParentFolderIds = join(',', $aParentFolderIds);
  214 + $aParams[] = $this->oFolder->getId();
205 $aParams[] = $sParentFolderIds; 215 $aParams[] = $sParentFolderIds;
206 $aParams[] = $sParentFolderIds . ",%"; 216 $aParams[] = $sParentFolderIds . ",%";
207 return array($sQuery, $aParams); 217 return array($sQuery, $aParams);