Commit 547d7a2347a37489d09f55ae404c7c7651d07990
1 parent
5bcc790d
Non-Queue bulk downloads fails on all 64bit environments
Jira:KTS-4513 Updated Bulk Import and Export compression to use the KTPclZip class Committed by: Charl Joseph Mert
Showing
3 changed files
with
515 additions
and
7 deletions
lib/foldermanagement/compressionArchiveUtil.inc.php
| ... | ... | @@ -37,6 +37,7 @@ |
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | 39 | require_once('File/Archive.php'); |
| 40 | +require_once(KT_LIB_DIR . '/util/ktpclzip.inc.php'); | |
| 40 | 41 | |
| 41 | 42 | /** |
| 42 | 43 | * Class to create and download a zip file |
| ... | ... | @@ -207,6 +208,13 @@ class ZipFolder { |
| 207 | 208 | return PEAR::raiseError(_kt("No folders or documents found to compress")); |
| 208 | 209 | } |
| 209 | 210 | |
| 211 | + $sZipFile = sprintf("%s/%s.".$this->extension, $this->sTmpPath, $this->sZipFileName); | |
| 212 | + $sZipFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $sZipFile))); | |
| 213 | + | |
| 214 | + $archive = new KTPclZip($sZipFile); | |
| 215 | + $archive->createZipFile($this->sTmpPath.'/Root Folder'); | |
| 216 | + | |
| 217 | + /* | |
| 210 | 218 | $config = KTConfig::getSingleton(); |
| 211 | 219 | $useBinary = true; //$config->get('export/useBinary', false); |
| 212 | 220 | |
| ... | ... | @@ -259,7 +267,8 @@ class ZipFolder { |
| 259 | 267 | File_Archive::toArchive($this->sZipFileName.'.'.$this->extension, File_Archive::toFiles($this->sTmpPath), $this->extension) |
| 260 | 268 | ); |
| 261 | 269 | } |
| 262 | - | |
| 270 | + */ | |
| 271 | + | |
| 263 | 272 | // Save the zip file and path into session |
| 264 | 273 | $_SESSION['zipcompression'] = KTUtil::arrayGet($_SESSION, 'zipcompression', array()); |
| 265 | 274 | $sExportCode = $this->exportCode; | ... | ... |
lib/import/zipimportstorage.inc.php
| ... | ... | @@ -40,8 +40,8 @@ |
| 40 | 40 | require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); |
| 41 | 41 | require_once(KT_LIB_DIR . '/import/fsimportstorage.inc.php'); |
| 42 | 42 | |
| 43 | -require_once(KT_DIR.'/thirdparty/peclzip/pclzip.lib.php'); | |
| 44 | 43 | require_once('File/Archive.php'); |
| 44 | +require_once(KT_LIB_DIR . '/util/ktpclzip.inc.php'); | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | class KTZipImportStorage extends KTFSImportStorage { |
| ... | ... | @@ -137,11 +137,8 @@ class KTZipImportStorage extends KTFSImportStorage { |
| 137 | 137 | // todo: replace file archive for tar, etc |
| 138 | 138 | if($this->sExtension == 'zip'){ |
| 139 | 139 | |
| 140 | - $archive = new PclZip($this->sZipPath); | |
| 141 | - | |
| 142 | - if ($archive->extract(PCLZIP_OPT_PATH, $sTmpPath) == 0){ | |
| 143 | - die("<font color='red'>Error : Unable to unzip archive</font>"); | |
| 144 | - } | |
| 140 | + $archive = new KTPclZip($this->sZipPath); | |
| 141 | + $archive->extractZipFile($sTmpPath); | |
| 145 | 142 | |
| 146 | 143 | /* ** Original zip functionality using the unzip binary ** * |
| 147 | 144 | $sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip"); | ... | ... |
lib/util/ktpclzip.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Simple wrapper class for working with the pecl zip class | |
| 6 | + * | |
| 7 | + * KnowledgeTree Community Edition | |
| 8 | + * Document Management Made Simple | |
| 9 | + * Copyright (C) 2008, 2009 KnowledgeTree Inc. | |
| 10 | + * Portions copyright The Jam Warehouse Software (Pty) Limited | |
| 11 | + * | |
| 12 | + * This program is free software; you can redistribute it and/or modify it under | |
| 13 | + * the terms of the GNU General Public License version 3 as published by the | |
| 14 | + * Free Software Foundation. | |
| 15 | + * | |
| 16 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
| 17 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 18 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 19 | + * details. | |
| 20 | + * | |
| 21 | + * You should have received a copy of the GNU General Public License | |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 23 | + * | |
| 24 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 25 | + * California 94120-7775, or email info@knowledgetree.com. | |
| 26 | + * | |
| 27 | + * The interactive user interfaces in modified source and object code versions | |
| 28 | + * of this program must display Appropriate Legal Notices, as required under | |
| 29 | + * Section 5 of the GNU General Public License version 3. | |
| 30 | + * | |
| 31 | + * In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 32 | + * these Appropriate Legal Notices must retain the display of the "Powered by | |
| 33 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 34 | + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 35 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 36 | + * copyright notice. | |
| 37 | + * Contributor( s): ______________________________________ | |
| 38 | + */ | |
| 39 | + | |
| 40 | +require_once ('config/dmsDefaults.php'); | |
| 41 | +require_once (KT_DIR . '/thirdparty/peclzip/pclzip.lib.php'); | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * Class to create, extract and download a zip file using the pclzip library | |
| 45 | + * TODO: Class base was borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 46 | + * and currently only supports extractintg a zip archive. The other logic needs to be | |
| 47 | + * woven to work with pclzip and tested for relevancy. | |
| 48 | + */ | |
| 49 | + | |
| 50 | +class KTPclZip { | |
| 51 | + | |
| 52 | + var $sTmpPath = ''; | |
| 53 | + var $sZipFileName = ''; | |
| 54 | + var $sZipFile = ''; | |
| 55 | + var $sPattern = ''; | |
| 56 | + var $sFolderPattern = ''; | |
| 57 | + var $aPaths = array (); | |
| 58 | + var $aReplaceKeys = array (); | |
| 59 | + var $aReplaceValues = array (); | |
| 60 | + var $sOutputEncoding = 'UTF-8'; | |
| 61 | + var $extension = 'zip'; | |
| 62 | + var $exportCode = null; | |
| 63 | + var $_pclZip = null; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Constructor | |
| 67 | + * | |
| 68 | + * @param string $sZipFileName The name of the zip file. | |
| 69 | + * @param string $exportCode The code to use if a zip file has already been created. | |
| 70 | + */ | |
| 71 | + function KTPclZip($sZipFileName = 'kt_pclzip', $exportCode = null, $extension = 'zip') { | |
| 72 | + | |
| 73 | + //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 74 | + $this->oKTConfig = & KTConfig::getSingleton (); | |
| 75 | + $this->oStorage = & KTStorageManagerUtil::getSingleton (); | |
| 76 | + | |
| 77 | + $this->sOutputEncoding = $this->oKTConfig->get ( 'export/encoding', 'UTF-8' ); | |
| 78 | + $this->extension = $extension; | |
| 79 | + | |
| 80 | + $this->sPattern = "[\*|\%|\\\|\/|\<|\>|\+|\:|\?|\||\'|\"]"; | |
| 81 | + $this->sFolderPattern = "[\*|\%|\<|\>|\+|\:|\?|\||\'|\"]"; | |
| 82 | + | |
| 83 | + if (! empty ( $exportCode )) { | |
| 84 | + $this->exportCode = $exportCode; | |
| 85 | + } else { | |
| 86 | + $this->exportCode = KTUtil::randomString (); | |
| 87 | + } | |
| 88 | + | |
| 89 | + // Check if the temp directory has been created and stored in session | |
| 90 | + $aData = KTUtil::arrayGet ( $_SESSION ['zipcompression'], $exportCode ); | |
| 91 | + if (! empty ( $aData ) && isset ( $aData ['dir'] )) { | |
| 92 | + $sTmpPath = $aData ['dir']; | |
| 93 | + } else { | |
| 94 | + $sBasedir = $this->oKTConfig->get ( "urls/tmpDirectory" ); | |
| 95 | + $sTmpPath = tempnam ( $sBasedir, 'kt_compress_zip' ); | |
| 96 | + | |
| 97 | + unlink ( $sTmpPath ); | |
| 98 | + mkdir ( $sTmpPath, 0755 ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + $this->sTmpPath = $sTmpPath; | |
| 102 | + $this->sZipFileName = $sZipFileName; | |
| 103 | + $this->aPaths = array (); | |
| 104 | + | |
| 105 | + $this->_pclZip = new PclZip($sZipFileName); | |
| 106 | + | |
| 107 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 108 | + | |
| 109 | + $aReplace = array ("[" => "[[]", " " => "[ ]", "*" => "[*]", "?" => "[?]" ); | |
| 110 | + | |
| 111 | + $this->aReplaceKeys = array_keys ( $aReplace ); | |
| 112 | + $this->aReplaceValues = array_values ( $aReplace ); | |
| 113 | + */ | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Creates a zip archive using the sFolder contents | |
| 118 | + */ | |
| 119 | + function createZipFile($sFolder) { | |
| 120 | + //Overriding $this->aPaths with specified | |
| 121 | + if (!is_null($sFolder)) { | |
| 122 | + $this->aPaths = $sFolder; | |
| 123 | + } | |
| 124 | + | |
| 125 | + $excludePath = $this->getExcludePath($sFolder, DIRECTORY_SEPARATOR); | |
| 126 | + | |
| 127 | + // Create the zip archive using the PclZip Wrapper | |
| 128 | + if ($this->_pclZip->create ( $sFolder , PCLZIP_OPT_REMOVE_PATH, $excludePath) == 0) { | |
| 129 | + //( File_Archive::read ( $this->sTmpPath . '/Root Folder' ), File_Archive::toArchive ( $this->sZipFileName . '.' . $this->extension, File_Archive::toFiles ( $this->sTmpPath ), $this->extension ) ); | |
| 130 | + return PEAR::raiseError ( _kt ( "Error compressing files" ) ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + // Save the zip file and path into session | |
| 134 | + $_SESSION ['zipcompression'] = KTUtil::arrayGet ( $_SESSION, 'zipcompression', array () ); | |
| 135 | + $sExportCode = $this->exportCode; | |
| 136 | + $_SESSION ['zipcompression'] [$sExportCode] = array ('file' => $sZipFile, 'dir' => $this->sTmpPath ); | |
| 137 | + $_SESSION ['zipcompression'] ['exportcode'] = $sExportCode; | |
| 138 | + | |
| 139 | + $this->sZipFile = $sZipFile; | |
| 140 | + return $sExportCode; | |
| 141 | + } | |
| 142 | + | |
| 143 | + /* | |
| 144 | + * Returns the part of the folder to be excluded from the zip content structure | |
| 145 | + * | |
| 146 | + * @params: $sPath folder to start from. | |
| 147 | + * @params: $ds directory separator | |
| 148 | + */ | |
| 149 | + function getExcludePath($sPath, $ds = '/') { | |
| 150 | + //Will grab the part of the full path to exclude from the zip contents | |
| 151 | + if ($sPath[strlen($sPath)] == $ds) { | |
| 152 | + //Chopping the last ds to make the keepPath contain an actual folder name | |
| 153 | + $sPath = substr($sPath, 0, strlen($sPath) - 1); | |
| 154 | + } | |
| 155 | + $keepPath = end(explode($ds, $sPath)); | |
| 156 | + $excludePath = str_replace($keepPath, '', $sPath); | |
| 157 | + return $excludePath; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Extract/Unzip the temp folder | |
| 162 | + */ | |
| 163 | + function extractZipFile($tmpPath = null) { | |
| 164 | + | |
| 165 | + //Overriding $this->tmpPath if specified | |
| 166 | + if (!is_null($tmpPath)) { | |
| 167 | + $this->sTmpPath = $tmpPath; | |
| 168 | + } | |
| 169 | + | |
| 170 | + //Further checking that $tmpPath isn't empty | |
| 171 | + /* | |
| 172 | + if (empty ( $this->tmpPath )) { | |
| 173 | + return PEAR::raiseError ( _kt ( "No temporary path specified to extract to" ) ); | |
| 174 | + } | |
| 175 | + */ | |
| 176 | + | |
| 177 | + if ($this->_pclZip->extract ( PCLZIP_OPT_PATH, $this->sTmpPath ) == 0) { | |
| 178 | + return PEAR::raiseError ( _kt ( "<font color='red'>Error : Unable to unzip archive</font>" ) ); | |
| 179 | + } | |
| 180 | + | |
| 181 | + //Returning the sExportCode for uniformity. | |
| 182 | + return $this->sExportCode; | |
| 183 | + | |
| 184 | + // Save the zip file and path into session | |
| 185 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 186 | + | |
| 187 | + $_SESSION ['zipcompression'] = KTUtil::arrayGet ( $_SESSION, 'zipcompression', array () ); | |
| 188 | + $sExportCode = $this->exportCode; | |
| 189 | + $_SESSION ['zipcompression'] [$sExportCode] = array ('file' => $sZipFile, 'dir' => $this->sTmpPath ); | |
| 190 | + $_SESSION ['zipcompression'] ['exportcode'] = $sExportCode; | |
| 191 | + | |
| 192 | + $this->sZipFile = $sZipFile; | |
| 193 | + return $sExportCode; | |
| 194 | + */ | |
| 195 | + } | |
| 196 | + | |
| 197 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 198 | + static public function get($exportCode) { | |
| 199 | + static $zipFolder = null; | |
| 200 | + if (is_null ( $zipFolder )) { | |
| 201 | + $zipFolder = new KTPclZip ( 'kt_pclzip', $exportCode ); | |
| 202 | + } | |
| 203 | + return $zipFolder; | |
| 204 | + } | |
| 205 | + */ | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Return the full path | |
| 209 | + * | |
| 210 | + * @param mixed $oFolderOrDocument May be a Folder or Document | |
| 211 | + */ | |
| 212 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 213 | + | |
| 214 | + function getFullFolderPath($oFolder) { | |
| 215 | + static $sRootFolder = null; | |
| 216 | + | |
| 217 | + if (is_null ( $sRootFolder )) { | |
| 218 | + $oRootFolder = Folder::get ( 1 ); | |
| 219 | + $sRootFolder = $oRootFolder->getName (); | |
| 220 | + } | |
| 221 | + | |
| 222 | + $sFullPath = $sRootFolder . '/'; | |
| 223 | + $sFullPath .= $oFolder->getFullPath (); | |
| 224 | + | |
| 225 | + if (substr ( $sFullPath, - 1 ) == '/') | |
| 226 | + $sFullPath = substr ( $sFullPath, 0, - 1 ); | |
| 227 | + return $sFullPath; | |
| 228 | + } | |
| 229 | + */ | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * Add a document to the zip file | |
| 233 | + */ | |
| 234 | + function addDocumentToZip($oDocument, $oFolder = null) { | |
| 235 | + | |
| 236 | + if (empty ( $oFolder )) { | |
| 237 | + $oFolder = Folder::get ( $oDocument->getFolderID () ); | |
| 238 | + } | |
| 239 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 240 | + if (empty ( $oFolder )) { | |
| 241 | + $oFolder = Folder::get ( $oDocument->getFolderID () ); | |
| 242 | + } | |
| 243 | + | |
| 244 | + $sDocPath = $this->getFullFolderPath ( $oFolder ); | |
| 245 | + $sDocPath = preg_replace ( $this->sFolderPattern, '-', $sDocPath ); | |
| 246 | + $sDocPath = $this->_convertEncoding ( $sDocPath, true ); | |
| 247 | + | |
| 248 | + $sDocName = $oDocument->getFileName (); | |
| 249 | + $sDocName = preg_replace ( $this->sPattern, '-', $sDocName ); | |
| 250 | + $sDocName = $this->_convertEncoding ( $sDocName, true ); | |
| 251 | + | |
| 252 | + $sParentFolder = $this->sTmpPath . '/' . $sDocPath; | |
| 253 | + $newDir = $this->sTmpPath; | |
| 254 | + | |
| 255 | + $aFullPath = split ( '/', $sDocPath ); | |
| 256 | + foreach ( $aFullPath as $dirPart ) { | |
| 257 | + $newDir = sprintf ( "%s/%s", $newDir, $dirPart ); | |
| 258 | + if (! file_exists ( $newDir )) { | |
| 259 | + mkdir ( $newDir, 0700 ); | |
| 260 | + } | |
| 261 | + } | |
| 262 | + | |
| 263 | + $sOrigFile = $this->oStorage->temporaryFile ( $oDocument ); | |
| 264 | + $sFilename = $sParentFolder . '/' . $sDocName; | |
| 265 | + @copy ( $sOrigFile, $sFilename ); | |
| 266 | + | |
| 267 | + $this->aPaths [] = $sDocPath . '/' . $sDocName; | |
| 268 | + return true; | |
| 269 | + */ | |
| 270 | + } | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + /** | |
| 275 | + * Add a folder to the zip file | |
| 276 | + */ | |
| 277 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 278 | + | |
| 279 | + function addFolderToZip($oFolder) { | |
| 280 | + $sFolderPath = $this->getFullFolderPath ( $oFolder ) . '/'; | |
| 281 | + $sFolderPath = preg_replace ( $this->sFolderPattern, '-', $sFolderPath ); | |
| 282 | + $sFolderPath = $this->_convertEncoding ( $sFolderPath, true ); | |
| 283 | + | |
| 284 | + $newDir = $this->sTmpPath; | |
| 285 | + | |
| 286 | + $aFullPath = split ( '/', $sFolderPath ); | |
| 287 | + foreach ( $aFullPath as $dirPart ) { | |
| 288 | + $newDir = sprintf ( "%s/%s", $newDir, $dirPart ); | |
| 289 | + if (! file_exists ( $newDir )) { | |
| 290 | + mkdir ( $newDir, 0700 ); | |
| 291 | + } | |
| 292 | + } | |
| 293 | + | |
| 294 | + $this->aPaths [] = $sFolderPath; | |
| 295 | + return true; | |
| 296 | + } | |
| 297 | + */ | |
| 298 | + | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * Zip the temp folder | |
| 302 | + */ | |
| 303 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 304 | + | |
| 305 | + function createZipFile($bEchoStatus = FALSE) { | |
| 306 | + if (empty ( $this->aPaths )) { | |
| 307 | + return PEAR::raiseError ( _kt ( "No folders or documents found to compress" ) ); | |
| 308 | + } | |
| 309 | + | |
| 310 | + $config = KTConfig::getSingleton (); | |
| 311 | + $useBinary = false; //$config->get('export/useBinary', false); | |
| 312 | + | |
| 313 | + | |
| 314 | + // Set environment language to output character encoding | |
| 315 | + $loc = $this->sOutputEncoding; | |
| 316 | + putenv ( "LANG=$loc" ); | |
| 317 | + putenv ( "LANGUAGE=$loc" ); | |
| 318 | + $loc = setlocale ( LC_ALL, $loc ); | |
| 319 | + | |
| 320 | + if ($useBinary) { | |
| 321 | + $sManifest = sprintf ( "%s/%s", $this->sTmpPath, "MANIFEST" ); | |
| 322 | + file_put_contents ( $sManifest, join ( "\n", $this->aPaths ) ); | |
| 323 | + } | |
| 324 | + | |
| 325 | + $sZipFile = sprintf ( "%s/%s." . $this->extension, $this->sTmpPath, $this->sZipFileName ); | |
| 326 | + $sZipFile = str_replace ( '<', '', str_replace ( '</', '', str_replace ( '>', '', $sZipFile ) ) ); | |
| 327 | + | |
| 328 | + if ($useBinary) { | |
| 329 | + $sZipCommand = KTUtil::findCommand ( "export/zip", "zip" ); | |
| 330 | + $aCmd = array ($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST" ); | |
| 331 | + $sOldPath = getcwd (); | |
| 332 | + chdir ( $this->sTmpPath ); | |
| 333 | + | |
| 334 | + // Note that the popen means that pexec will return a file descriptor | |
| 335 | + $aOptions = array ('popen' => 'r' ); | |
| 336 | + $fh = KTUtil::pexec ( $aCmd, $aOptions ); | |
| 337 | + | |
| 338 | + if ($bEchoStatus) { | |
| 339 | + $last_beat = time (); | |
| 340 | + while ( ! feof ( $fh ) ) { | |
| 341 | + if ($i % 1000 == 0) { | |
| 342 | + $this_beat = time (); | |
| 343 | + if ($last_beat + 1 < $this_beat) { | |
| 344 | + $last_beat = $this_beat; | |
| 345 | + print " "; | |
| 346 | + } | |
| 347 | + } | |
| 348 | + $contents = fread ( $fh, 4096 ); | |
| 349 | + if ($contents) { | |
| 350 | + print nl2br ( $this->_convertEncoding ( $contents, false ) ); | |
| 351 | + } | |
| 352 | + $i ++; | |
| 353 | + } | |
| 354 | + } | |
| 355 | + pclose ( $fh ); | |
| 356 | + } else { | |
| 357 | + // Create the zip archive using the PEAR File_Archive | |
| 358 | + File_Archive::extract ( File_Archive::read ( $this->sTmpPath . '/Root Folder' ), File_Archive::toArchive ( $this->sZipFileName . '.' . $this->extension, File_Archive::toFiles ( $this->sTmpPath ), $this->extension ) ); | |
| 359 | + } | |
| 360 | + | |
| 361 | + // Save the zip file and path into session | |
| 362 | + $_SESSION ['zipcompression'] = KTUtil::arrayGet ( $_SESSION, 'zipcompression', array () ); | |
| 363 | + $sExportCode = $this->exportCode; | |
| 364 | + $_SESSION ['zipcompression'] [$sExportCode] = array ('file' => $sZipFile, 'dir' => $this->sTmpPath ); | |
| 365 | + $_SESSION ['zipcompression'] ['exportcode'] = $sExportCode; | |
| 366 | + | |
| 367 | + $this->sZipFile = $sZipFile; | |
| 368 | + return $sExportCode; | |
| 369 | + } | |
| 370 | + */ | |
| 371 | + | |
| 372 | + | |
| 373 | + /** | |
| 374 | + * Download the zip file | |
| 375 | + */ | |
| 376 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 377 | + | |
| 378 | + function downloadZipFile($exportCode = NULL) { | |
| 379 | + if (! (isset ( $exportCode ) && ! empty ( $exportCode ))) { | |
| 380 | + $exportCode = KTUtil::arrayGet ( $_SESSION ['zipcompression'], 'exportcode' ); | |
| 381 | + } | |
| 382 | + | |
| 383 | + $aData = KTUtil::arrayGet ( $_SESSION ['zipcompression'], $exportCode ); | |
| 384 | + | |
| 385 | + if (! empty ( $aData )) { | |
| 386 | + $sZipFile = $aData ['file']; | |
| 387 | + $sTmpPath = $aData ['dir']; | |
| 388 | + } else { | |
| 389 | + $sZipFile = $this->sZipFile; | |
| 390 | + $sTmpPath = $this->sTmpPath; | |
| 391 | + } | |
| 392 | + | |
| 393 | + if (! file_exists ( $sZipFile )) { | |
| 394 | + return PEAR::raiseError ( _kt ( 'The zip file has not been created, if you are downloading a large number of documents | |
| 395 | + or a large document then it may take a few minutes to finish.' ) ); | |
| 396 | + } | |
| 397 | + | |
| 398 | + $mimeType = 'application/zip; charset=utf-8;'; | |
| 399 | + $fileSize = filesize ( $sZipFile ); | |
| 400 | + $fileName = $this->sZipFileName . '.' . $this->extension; | |
| 401 | + | |
| 402 | + KTUtil::download ( $sZipFile, $mimeType, $fileSize, $fileName ); | |
| 403 | + KTUtil::deleteDirectory ( $sTmpPath ); | |
| 404 | + return true; | |
| 405 | + } | |
| 406 | + */ | |
| 407 | + | |
| 408 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 409 | + | |
| 410 | + function checkArchiveExists($exportCode = null) { | |
| 411 | + if (! (isset ( $exportCode ) && ! empty ( $exportCode ))) { | |
| 412 | + $exportCode = KTUtil::arrayGet ( $_SESSION ['zipcompression'], 'exportcode' ); | |
| 413 | + } | |
| 414 | + | |
| 415 | + $aData = KTUtil::arrayGet ( $_SESSION ['zipcompression'], $exportCode ); | |
| 416 | + | |
| 417 | + if (! empty ( $aData )) { | |
| 418 | + $sZipFile = $aData ['file']; | |
| 419 | + $sTmpPath = $aData ['dir']; | |
| 420 | + } else { | |
| 421 | + $sZipFile = $this->sZipFile; | |
| 422 | + $sTmpPath = $this->sTmpPath; | |
| 423 | + } | |
| 424 | + | |
| 425 | + if (! file_exists ( $sZipFile )) { | |
| 426 | + return false; | |
| 427 | + } | |
| 428 | + return true; | |
| 429 | + } | |
| 430 | + */ | |
| 431 | + | |
| 432 | + /** | |
| 433 | + * Check that iconv exists and that the selected encoding is supported. | |
| 434 | + */ | |
| 435 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 436 | + | |
| 437 | + function checkConvertEncoding() { | |
| 438 | + if (! function_exists ( "iconv" )) { | |
| 439 | + return PEAR::raiseError ( _kt ( 'IConv PHP extension not installed. The zip file compression could not handle output filename encoding conversion !' ) ); | |
| 440 | + } | |
| 441 | + $oKTConfig = $this->oKTConfig; | |
| 442 | + $this->sOutputEncoding = $oKTConfig->get ( 'export/encoding', 'UTF-8' ); | |
| 443 | + | |
| 444 | + // Test the specified encoding | |
| 445 | + if (iconv ( "UTF-8", $this->sOutputEncoding, "" ) === FALSE) { | |
| 446 | + return PEAR::raiseError ( _kt ( 'Specified output encoding for the zip files compression does not exists !' ) ); | |
| 447 | + } | |
| 448 | + return true; | |
| 449 | + } | |
| 450 | + | |
| 451 | + function _convertEncoding($sMystring, $bEncode) { | |
| 452 | + if (strcasecmp ( $this->sOutputEncoding, "UTF-8" ) === 0) { | |
| 453 | + return $sMystring; | |
| 454 | + } | |
| 455 | + if ($bEncode) { | |
| 456 | + return iconv ( "UTF-8", $this->sOutputEncoding, $sMystring ); | |
| 457 | + } else { | |
| 458 | + return iconv ( $this->sOutputEncoding, "UTF-8", $sMystring ); | |
| 459 | + } | |
| 460 | + } | |
| 461 | + */ | |
| 462 | + | |
| 463 | + /* //TODO: Cherry pick some of this logic borrowed from lib/foldremanagement/compressionArchiveUtil.inc.php | |
| 464 | + | |
| 465 | + static public function checkDownloadSize($object) { | |
| 466 | + return true; | |
| 467 | + | |
| 468 | + if ($object instanceof Document || $object instanceof DocumentProxy) { | |
| 469 | + } | |
| 470 | + | |
| 471 | + if ($object instanceof Folder || $object instanceof FolderProxy) { | |
| 472 | + $id = $object->iId; | |
| 473 | + | |
| 474 | + // If we're working with the root folder | |
| 475 | + if ($id = 1) { | |
| 476 | + $sql = 'SELECT count(*) as cnt FROM documents where folder_id = 1'; | |
| 477 | + } else { | |
| 478 | + $sql [] = "SELECT count(*) as cnt FROM documents where parent_folder_ids like '%,?' OR parent_folder_ids like '%,?,%' OR folder_id = ?"; | |
| 479 | + $sql [] = array ($id, $id, $id ); | |
| 480 | + } | |
| 481 | + | |
| 482 | + | |
| 483 | + //SELECT count(*) FROM documents d | |
| 484 | + //INNER JOIN document_metadata_version m ON d.metadata_version_id = m.id | |
| 485 | + //INNER JOIN document_content_version c ON m.content_version_id = c.id | |
| 486 | + //where (d.parent_folder_ids like '%,12' OR d.parent_folder_ids like '%,12,%' OR d.folder_id = 12) AND d.status_id < 3 AND size > 100000 | |
| 487 | + | |
| 488 | + | |
| 489 | + $result = DBUtil::getOneResult ( $sql ); | |
| 490 | + | |
| 491 | + if ($result ['cnt'] > 10) { | |
| 492 | + return true; | |
| 493 | + } | |
| 494 | + } | |
| 495 | + | |
| 496 | + return false; | |
| 497 | + } | |
| 498 | + */ | |
| 499 | + | |
| 500 | + | |
| 501 | +} | |
| 502 | +?> | ... | ... |