source: main/trunk/greenstone2/cgi-bin/talkback-transfer.pl@ 23144

Last change on this file since 23144 was 23144, checked in by davidb, 14 years ago

Script now correctly determines the infodb type by parsing the collect.cfg file

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4
5use LWP::UserAgent;
6use HTTP::Request::Common;
7
8use CGI::Carp qw(fatalsToBrowser);
9use CGI;
10
11eval('require "./gsdlCGI.pm"');
12if ($@)
13{
14 print STDOUT "Content-type:text/plain\n\n";
15 print STDOUT "ERROR: $@\n";
16 exit 0;
17}
18
19
20sub get_infodb_type
21{
22 my ($opt_site,$collect_home,$collect) = @_;
23
24 my $out = "STDERR";
25
26 $collect = &colcfg::use_collection($opt_site, $collect, $collect_home);
27
28 if ($collect eq "") {
29 print STDERR "Error: failed to find collection $collect in $collect_home\n";
30 print STDOUT "Content-type:text/plain\n\n";
31 print STDOUT "ERROR: Failed to find collection $collect\n";
32 exit 0;
33
34 }
35
36 # Read in the collection configuration file.
37 my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
38 my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
39
40 return $collectcfg->{'infodbtype'};
41}
42
43
44sub oid_to_docxml_filename
45{
46 my ($opt_site,$collect_home,$collect,$docid) = @_;
47
48 my $infodb_type = get_infodb_type($opt_site,$collect_home,$collect);
49
50 # Obtain the collect and archives dir
51 my $archives_dir = &util::filename_cat($collect_home,$collect,"archives");
52
53 # Obtain the doc.xml path for the specified docID
54 my $arcinfo_doc_filename
55 = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
56 $archives_dir);
57 my $doc_rec_string
58 = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
59 $docid);
60 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
61 my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
62
63 # The $doc_xml_file is relative to the archives, so now let's get the
64 # full path
65 my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file);
66
67 return $doc_xml_filename;
68}
69
70sub main
71{
72 # Setup greenstone Perl include paths so additional packages can be found
73 my $gsdl_cgi = gsdlCGI->new();
74 $gsdl_cgi->setup_gsdl();
75
76 my $gsdl_home = $gsdl_cgi->get_gsdl_home();
77 my $collect_home = &util::filename_cat($gsdl_home,"collect");
78
79 require dbutil;
80 require talkback;
81
82 my $oid = $gsdl_cgi->param('oid');
83 my $collect = $gsdl_cgi->param('collect');
84 my $site = $gsdl_cgi->param('site');
85
86 # sanity check
87 if (!defined $oid || !defined $collect) {
88 print STDOUT "Content-type:text/plain\n\n";
89 print STDOUT "ERROR: Malformed CGI argments. Need to specify 'oid' and 'collect'\n";
90 exit 0;
91 }
92
93 my $uniq_prefix = "$collect-$oid";
94
95 my $docxml_filename = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
96
97 my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
98
99 my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
100
101 my $response = $browser->post(
102 $talktoUploadURL,
103 [ 'yes_upload' => '1',
104 'process' => '1',
105 'oid' => $oid,
106 'collect' => $collect,
107 'uploadedfile' => [$docxml_filename, "$uniq_prefix-doc.xml"]
108 ],
109 'Content_Type' => 'form-data'
110 );
111
112 if ($response->is_success) {
113 print "Content-type:text/html\n\n";
114 print $response->content;
115 }
116 else {
117 print $response->error_as_HTML;
118 }
119
120}
121
122main();
123
Note: See TracBrowser for help on using the repository browser.