Changeset 23147


Ignore:
Timestamp:
2010-10-17T23:54:21+13:00 (14 years ago)
Author:
davidb
Message:

Added routine for zipping up doc_xml and its associated files from the archives directory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/cgi-bin/talkback-transfer.pl

    r23146 r23147  
    88use CGI::Carp qw(fatalsToBrowser);
    99use CGI;
     10
     11use File::Basename;
    1012
    1113BEGIN {
     
    5658    my $infodb_type = get_infodb_type($opt_site,$collect_home,$collect);
    5759
    58     # Obtain the collect and archives dir   
    59     my $archives_dir = &util::filename_cat($collect_home,$collect,"archives");
     60    # Derive the archives dir   
     61    my $archive_dir = &util::filename_cat($collect_home,$collect,"archives");
    6062
    6163    # Obtain the doc.xml path for the specified docID
    6264    my $arcinfo_doc_filename
    6365    = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
    64                     $archives_dir);
     66                    $archive_dir);
    6567    my $doc_rec_string
    6668    = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
     
    6870    my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);   
    6971    my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
    70    
     72    my $assoc_path = dirname($doc_xml_file);
     73
    7174    # The $doc_xml_file is relative to the archives, so now let's get the
    7275    # full path
    73     my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file);
     76    my $doc_xml_filename = &util::filename_cat($archive_dir,$doc_xml_file);
    7477
    75     return $doc_xml_filename;
     78    return ($doc_xml_filename,$assoc_path);
     79}
     80
     81sub zip_up_archives_doc
     82{
     83    my ($gsdl_cgi,$collect_home,$collect,$doc_xml_filename,$assoc_path) = @_;
     84
     85    my $timestamp = time();
     86    my $lang_env = $gsdl_cgi->clean_param("lr") || "";
     87
     88    my $archive_dir = &util::filename_cat($collect_home,$collect,"archives");
     89
     90    # Zip up the doc_xml file and all the files associated with it
     91    my $java = $gsdl_cgi->get_java_path();
     92    my $jar_dir= &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java");
     93    my $java_classpath = &util::filename_cat($jar_dir,"GLIServer.jar");
     94
     95    my $zip_file = "$collect-$timestamp.zip";
     96    my $zip_file_path = &util::filename_cat($archive_dir,$zip_file);
     97
     98    my $java_args = "\"$zip_file_path\" \"$archive_dir\" \"$assoc_path\"";
     99    if($gsdl_cgi->greenstone_version() != 2) {
     100    $java_args .= " gsdl3";
     101    }
     102
     103    $ENV{'LANG'} = $lang_env;
     104    my $java_command = "\"$java\" -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipCollectionShell $java_args";
     105
     106    my $java_output = `$java_command`;
     107    my $java_status = $?;
     108    if ($java_status > 0) {
     109    $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
     110    }
     111
     112    # Check that the zip file was created successfully
     113    if (!-e $zip_file_path || -z $zip_file_path) {
     114    $gsdl_cgi->generate_error("Collection zip file $zip_file_path could not be created.");
     115    }
     116
     117    return $zip_file_path;
     118
    76119}
    77120
     
    102145    my $uniq_prefix = "$collect-$oid";
    103146
    104     my $docxml_filename = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
     147    my ($docxml_filename,$assoc_path)
     148    = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
     149
     150    my $zip_filename
     151    = zip_up_archives_doc($gsdl_cgi,$collect_home,$collect,
     152                  $docxml_filename,$assoc_path);
    105153
    106154    my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
     
    114162         'oid'          => $oid,
    115163         'collect'      => $collect,
    116          'uploadedfile' => [$docxml_filename, "$uniq_prefix-doc.xml"]
     164         'uploadedfile' => [$zip_filename, "$uniq_prefix-doc.xml"]
    117165         ],
    118166       'Content_Type' => 'form-data'
Note: See TracChangeset for help on using the changeset viewer.