From e21a7a769b346c1af7de6281988dfa47cbbcd934 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 5 Sep 2018 11:13:32 -0400 Subject: [PATCH 1/2] add ExportCompress --- web/lang/en_gb.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 0e22bbb54..5e407b074 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -323,6 +323,7 @@ $SLANG = array( 'Events' => 'Events', 'Exclude' => 'Exclude', 'Execute' => 'Execute', + 'ExportCompress' => 'Use Compression', 'ExportDetails' => 'Export Event Details', 'ExportMatches' => 'Export Matches', 'Exif' => 'Embed EXIF data into image', From 40292f3dad7bc2cf9ad764079014314efce1445d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 09:08:33 -0400 Subject: [PATCH 2/2] Add Compression flag --- web/ajax/event.php | 14 +++++++--- .../classic/includes/export_functions.php | 27 ++++++++++--------- web/skins/classic/views/export.php | 2 ++ web/views/archive.php | 6 ++++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/web/ajax/event.php b/web/ajax/event.php index cf8c59aa3..d0e229267 100644 --- a/web/ajax/event.php +++ b/web/ajax/event.php @@ -39,7 +39,8 @@ if ( canView('Events') ) { { require_once(ZM_SKIN_PATH.'/includes/export_functions.php'); -# We use session vars in here, so we need to restart the session because we stopped it in index.php to improve concurrency. + # We use session vars in here, so we need to restart the session + # because we stopped it in index.php to improve concurrency. session_start(); if ( !empty($_REQUEST['exportDetail']) ) @@ -72,6 +73,11 @@ if ( canView('Events') ) { else $exportFormat = ''; + if ( !empty($_REQUEST['exportCompress']) ) + $exportCompress = $_SESSION['export']['compress'] = $_REQUEST['exportCompress']; + else + $exportCompress = false; + session_write_close(); $exportIds = !empty($_REQUEST['eids'])?$_REQUEST['eids']:$_REQUEST['id']; @@ -83,7 +89,8 @@ if ( canView('Events') ) { $exportImages, $exportVideo, $exportMisc, - $exportFormat + $exportFormat, + $exportCompress ) ) ajaxResponse(array('exportFile'=>$exportFile)); else @@ -100,7 +107,8 @@ if ( canView('Events') ) { if ( $exportFile = exportEvents( $exportIds, (isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''), - false,false, false, $exportVideo, false, $exportFormat, $exportStructure ) ) + false,false, false, + $exportVideo, false, $exportFormat, $exportStructure ) ) ajaxResponse(array('exportFile'=>$exportFile)); else ajaxError('Export Failed'); diff --git a/web/skins/classic/includes/export_functions.php b/web/skins/classic/includes/export_functions.php index 4234709de..140b6a0fa 100644 --- a/web/skins/classic/includes/export_functions.php +++ b/web/skins/classic/includes/export_functions.php @@ -826,6 +826,7 @@ function exportEvents( $exportVideo, $exportMisc, $exportFormat, + $exportCompressed, $exportStructure = false ) { @@ -912,28 +913,30 @@ function exportEvents( chdir(ZM_DIR_EXPORTS); $archive = ''; if ( $exportFormat == 'tar' ) { - $archive = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:'').'.tar.gz'; - @unlink($archive); - $command = 'nice -10 tar --create --gzip --dereference --file='.escapeshellarg($archive).' zmExport_'.$connkey.'/'; - #$command = 'nice -10 tar --create --gzip --file='.escapeshellarg($archive).' --files-from='.escapeshellarg($listFile); + $archive = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:'').'.tar'; + $command = 'tar --create --dereference'; + if ( $exportCompressed ) { + $archive .= '.gz'; + $command .= ' --gzip'; + $exportFormat .= '.gz'; + } if ( $exportStructure == 'flat' ) { //strip file paths if we $command .= " --xform='s#^.+/##x'"; } + $command .= ' --file='.escapeshellarg($archive); } elseif ( $exportFormat == 'zip' ) { $archive = ZM_DIR_EXPORTS.'/'.$export_root.($connkey?'_'.$connkey:'').'.zip'; - @unlink($archive); - if ( $exportStructure == 'flat' ) { - $command = 'nice -10 zip -j '.escapeshellarg($archive).' zmExport_'.$connkey.'/'; - #$command = 'cat '.escapeshellarg($listFile).' | nice -10 zip -q -j '.escapeshellarg($archive).' -@'; - } else { - $command = 'nice -10 zip -r '.escapeshellarg($archive).' zmExport_' . $connkey.'/'; - #$command = 'cat '.escapeshellarg($listFile).' | nice -10 zip -q '.escapeshellarg($archive).' -@'; - } + $command = 'zip '; + $command = ($exportStructure == 'flat' ? ' -j ' : ' -r ' ).escapeshellarg($archive); + $command .= $exportCompressed ? ' -9' : ' -0'; } else { Error("No exportFormat specified."); return false; } // if $exportFormat + + @unlink($archive); + $command .= ' zmExport_' . $connkey.'/'; Logger::Debug("Command is $command"); exec($command, $output, $status); if ( $status ) { diff --git a/web/skins/classic/views/export.php b/web/skins/classic/views/export.php index b57957d23..1d205337d 100644 --- a/web/skins/classic/views/export.php +++ b/web/skins/classic/views/export.php @@ -36,6 +36,8 @@ if ( isset($_SESSION['export']) ) { $_REQUEST['exportMisc'] = $_SESSION['export']['misc']; if ( isset($_SESSION['export']['format']) ) $_REQUEST['exportFormat'] = $_SESSION['export']['format']; + if ( isset($_SESSION['export']['compress']) ) + $_REQUEST['exportCompress'] = $_SESSION['export']['compress']; } else { $_REQUEST['exportDetail'] = $_REQUEST['exportFrames'] = diff --git a/web/views/archive.php b/web/views/archive.php index 047c421a6..9b7035531 100644 --- a/web/views/archive.php +++ b/web/views/archive.php @@ -28,10 +28,14 @@ $connkey = isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''; if ( $archivetype ) { switch ($archivetype) { - case 'tar': + case 'tar.gz': $mimetype = 'gzip'; $file_ext = 'tar.gz'; break; + case 'tar': + $mimetype = 'tar'; + $file_ext = 'tar'; + break; case 'zip': $mimetype = 'zip'; $file_ext = 'zip';