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

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

Added 'colcfg' to packages included by script

  • 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 require colcfg;
82
83 my $oid = $gsdl_cgi->param('oid');
84 my $collect = $gsdl_cgi->param('collect');
85 my $site = $gsdl_cgi->param('site');
86
87 # sanity check
88 if (!defined $oid || !defined $collect) {
89 print STDOUT "Content-type:text/plain\n\n";
90 print STDOUT "ERROR: Malformed CGI argments. Need to specify 'oid' and 'collect'\n";
91 exit 0;
92 }
93
94 my $uniq_prefix = "$collect-$oid";
95
96 my $docxml_filename = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
97
98 my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
99
100 my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
101
102 my $response = $browser->post(
103 $talktoUploadURL,
104 [ 'yes_upload' => '1',
105 'process' => '1',
106 'oid' => $oid,
107 'collect' => $collect,
108 'uploadedfile' => [$docxml_filename, "$uniq_prefix-doc.xml"]
109 ],
110 'Content_Type' => 'form-data'
111 );
112
113 if ($response->is_success) {
114 print "Content-type:text/html\n\n";
115 print $response->content;
116 }
117 else {
118 print $response->error_as_HTML;
119 }
120
121}
122
123main();
124
Note: See TracBrowser for help on using the repository browser.