Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 0bd1ff7

Browse files
committed
Added ability to download all MARC records in tar.gz format
1 parent 863b117 commit 0bd1ff7

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

classes/class.import.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* Class to import files into app
44
*
55
* @author Jared Howland <[email protected]@gmail.com>
6-
* @version 2013-02-23
6+
* @version 2013-03-05
7+
* @since 2013-02-23
78
*/
89

9-
require_once 'lib/Archive_Tar/Archive/Tar.php';
10+
// require_once 'lib/Archive_Tar/Archive/Tar.php';
1011

1112
class import {
1213
/**
@@ -21,9 +22,11 @@ public function upload( $resource_id, $frequency, $num_records, $file ) {
2122
$filename = $resource_id . '.xml';
2223
$tmp_name = $file['marc_records']['tmp_name'];
2324
if(move_uploaded_file($tmp_name, config::UPLOAD_DIRECTORY . '/' . $filename)) {
24-
$tar = new Archive_Tar(config::UPLOAD_DIRECTORY . '/' . $filename . '.tar.gz', 'gz');
25-
$files = array($filename);
26-
$compressed_tar = $tar->create($files) or die('Could not create archive. Please go back and try again.');
25+
// Tar and gzip files as they are uploaded
26+
// $tar = new Archive_Tar(config::UPLOAD_DIRECTORY . '/' . $filename . '.tar.gz', 'gz');
27+
// $files = array(config::UPLOAD_DIRECTORY . '/' . $filename);
28+
// $compressed_tar = $tar->create($files) or die('Could not create archive. Please go back and try again.');
29+
// unlink(config::UPLOAD_DIRECTORY . '/' . $filename);
2730
$today = date('Y-m-d');
2831
switch ($frequency) {
2932
case 'Once':

download.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Compress and download all files
44
*
55
* @author Jared Howland <[email protected]>
6-
* @version 2013-03-04
6+
* @version 2013-03-05
77
* @since 2013-03-04
88
*
99
*/
@@ -18,15 +18,25 @@
1818
$marc_record_loads = $query->fetchAll(PDO::FETCH_ASSOC);
1919
$db = null;
2020

21-
$tar = new Archive_Tar(config::UPLOAD_DIRECTORY . '/ALL.tar.gz', 'gz');
21+
$tar = new Archive_Tar(config::UPLOAD_DIRECTORY . '/All.tar.gz', 'gz');
2222
$files = array();
2323
foreach($marc_record_loads as $resource) {
2424
$resource_id = $resource['id'];
25-
$filename = $resource_id . '.xml';
25+
$filename = config::UPLOAD_DIRECTORY . '/' . $resource_id . '.xml';
2626
$files[] = $filename;
2727
}
2828

29-
// $files = array($filename);
3029
$compressed_tar = $tar->create($files) or die('Could not create archive. Please go back and try again.');
3130

31+
if(rename(config::UPLOAD_DIRECTORY . '/All.tar.gz', 'download_all/All.tar.gz')){
32+
download('download_all/All.tar.gz', 'All.tar.gz');
33+
}
34+
35+
function download($f_location, $f_name){
36+
header('Content-Description: File Transfer');
37+
header('Content-Type: application/x-tar');
38+
header('Content-Disposition: attachment; filename=' . basename($f_name));
39+
readfile($f_location);
40+
}
41+
3242
?>

download_all/All.tar.gz

26.8 MB
Binary file not shown.

templates/_body.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ul><br/>
1212

1313
<p style="clear:both;">{{ stats.num_up_to_date_resources|number_format }} out of {{ stats.num_resources|number_format }} resources are up to date.</p>
14-
<p><strong>Number of MARC Records</strong>: {{ stats.num_records|number_format }}</p>
14+
<p><strong>Number of MARC Records</strong>: {{ stats.num_records|number_format }} (<a href="download.php">download all records</a>)</p>
1515

1616
<table id="resources" class="tablesorter">
1717
<thead><tr><th></th><th class="w15">583 (Vendor-Resource Name)<br/>Username :: Password</th><th class="w6">Frequency</th><th class="w6">Last load</th><th class="w6">Next load</th><th>Load records</th><th>Notes</th></tr></thead>

0 commit comments

Comments
 (0)