1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # explodeaction.pm --
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 2009 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistr te it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | package explodeaction;
|
---|
27 |
|
---|
28 | use strict;
|
---|
29 |
|
---|
30 | use cgiactions::baseaction;
|
---|
31 |
|
---|
32 | use dbutil;
|
---|
33 | use ghtml;
|
---|
34 |
|
---|
35 |
|
---|
36 | BEGIN {
|
---|
37 | # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
|
---|
38 | require XML::Rules;
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | @explodeaction::ISA = ('baseaction');
|
---|
43 |
|
---|
44 |
|
---|
45 | # 'a' for action, and 'c' for collection are also compulsorary, and
|
---|
46 | # added in automatically by baseaction
|
---|
47 |
|
---|
48 | my $action_table =
|
---|
49 | {
|
---|
50 | "explode" => { 'compulsory-args' => ["d"],
|
---|
51 | 'optional-args' => [] }
|
---|
52 | };
|
---|
53 |
|
---|
54 |
|
---|
55 | sub new
|
---|
56 | {
|
---|
57 | my $class = shift (@_);
|
---|
58 | my ($gsdl_cgi,$iis6_mode) = @_;
|
---|
59 |
|
---|
60 | my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
|
---|
61 |
|
---|
62 | return bless $self, $class;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | sub get_infodb_type
|
---|
67 | {
|
---|
68 | my ($opt_site,$collect_home,$collect) = @_;
|
---|
69 |
|
---|
70 | my $out = "STDERR";
|
---|
71 |
|
---|
72 | $collect = &colcfg::use_collection($opt_site, $collect, $collect_home);
|
---|
73 |
|
---|
74 | if ($collect eq "") {
|
---|
75 | print STDERR "Error: failed to find collection $collect in $collect_home\n";
|
---|
76 | print STDOUT "Content-type:text/plain\n\n";
|
---|
77 | print STDOUT "ERROR: Failed to find collection $collect\n";
|
---|
78 | exit 0;
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 | # Read in the collection configuration file.
|
---|
83 | my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
84 | my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
|
---|
85 |
|
---|
86 | return $collectcfg->{'infodbtype'};
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | sub oid_to_import_filenames
|
---|
91 | {
|
---|
92 | my $self = shift @_;
|
---|
93 |
|
---|
94 | my @docids = @_;
|
---|
95 |
|
---|
96 | my $infodb_type = $self->{'infodbtype'};
|
---|
97 |
|
---|
98 | # Derive the archives dir
|
---|
99 | my $archive_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"archives");
|
---|
100 |
|
---|
101 | my $arcinfo_doc_filename
|
---|
102 | = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
|
---|
103 | $archive_dir);
|
---|
104 |
|
---|
105 | print STDERR "**** arcinfo doc filename = $arcinfo_doc_filename\n";
|
---|
106 |
|
---|
107 | my @import_files = ();
|
---|
108 |
|
---|
109 | foreach my $docid (@docids) {
|
---|
110 | # Obtain the src and associated files specified docID
|
---|
111 |
|
---|
112 | print STDERR "*** looking up key \"$docid\"\n";
|
---|
113 |
|
---|
114 | my $doc_rec
|
---|
115 | = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
|
---|
116 | $docid);
|
---|
117 |
|
---|
118 | print STDERR "*** doc_rec = $doc_rec\n";
|
---|
119 |
|
---|
120 | my $src_files = $doc_rec->{'src-file'};
|
---|
121 | my $assoc_files = $doc_rec->{'assoc-file'};
|
---|
122 |
|
---|
123 | push(@import_files,@$src_files) if (defined $src_files);
|
---|
124 | push(@import_files,@$assoc_files) if (defined $assoc_files);
|
---|
125 | }
|
---|
126 |
|
---|
127 | return \@import_files;
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | sub import_filenames_to_oids
|
---|
132 | {
|
---|
133 | my $self = shift @_;
|
---|
134 |
|
---|
135 | my ($import_filenames) = @_;
|
---|
136 |
|
---|
137 | my $infodb_type = $self->{'infodbtype'};
|
---|
138 |
|
---|
139 | # Derive the archives dir
|
---|
140 | my $archive_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"archives");
|
---|
141 |
|
---|
142 | # Obtain the doc.xml path for the specified docID
|
---|
143 | my $arcinfo_doc_filename
|
---|
144 | = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-src",
|
---|
145 | $archive_dir);
|
---|
146 |
|
---|
147 | my %all_oid_keys = ();
|
---|
148 |
|
---|
149 | foreach my $if (@$import_filenames) {
|
---|
150 |
|
---|
151 | print STDERR "*** looking if key \"$if\"\n";
|
---|
152 |
|
---|
153 | my $src_rec
|
---|
154 | = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
|
---|
155 | $if);
|
---|
156 | my $oids = $src_rec->{'oid'};
|
---|
157 |
|
---|
158 | foreach my $o (@$oids) {
|
---|
159 | $all_oid_keys{$o} = 1;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | my @all_oids = keys %all_oid_keys;
|
---|
164 |
|
---|
165 | return \@all_oids;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 | sub explode
|
---|
171 | {
|
---|
172 | my $self = shift @_;
|
---|
173 |
|
---|
174 | my $username = $self->{'username'};
|
---|
175 | my $collect = $self->{'collect'};
|
---|
176 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
177 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
178 |
|
---|
179 | # Authenticate user if it is enabled
|
---|
180 | if ($baseaction::authentication_enabled) {
|
---|
181 | # Ensure the user is allowed to edit this collection
|
---|
182 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
183 | }
|
---|
184 |
|
---|
185 | # Obtain the collect dir
|
---|
186 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
187 |
|
---|
188 | # Make sure the collection isn't locked by someone else
|
---|
189 | $self->lock_collection($username, $collect);
|
---|
190 |
|
---|
191 | # look up additional args
|
---|
192 | my $docid = $self->{'d'};
|
---|
193 | if ((!defined $docid) || ($docid =~ m/^\s*$/)) {
|
---|
194 | $self->unlock_collection($username, $collect);
|
---|
195 | $gsdl_cgi->generate_error("No docid (d=...) specified.");
|
---|
196 | }
|
---|
197 |
|
---|
198 | my $orig_import_filenames = $self->oid_to_import_filenames($docid);
|
---|
199 | my $oid_keys = $self->import_filenames_to_oids($orig_import_filenames);
|
---|
200 | my $expanded_import_filenames = $self->oid_to_import_filenames(@$oid_keys);
|
---|
201 |
|
---|
202 |
|
---|
203 | # Release the lock once it is done
|
---|
204 | $self->unlock_collection($username, $collect);
|
---|
205 |
|
---|
206 | my $mess = "Base OID: $docid\n-----\n";
|
---|
207 | $mess .= join("\n",@$expanded_import_filenames);
|
---|
208 |
|
---|
209 | $gsdl_cgi->generate_ok_message($mess);
|
---|
210 |
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|
215 | 1;
|
---|