source: gsdl/trunk/bin/script/export.pl@ 20616

Last change on this file since 20616 was 20616, checked in by kjdon, 15 years ago

first step at bring export into line with import regarding incremental export

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# export.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2004 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28
29# This program will export a particular collection into a specific Format (e.g. METS or DSpace) by importing then saving as a different format.
30
31package export;
32
33BEGIN {
34 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
35 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
39 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
40 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
41
42 if (defined $ENV{'GSDLEXTS'}) {
43 my @extensions = split(/:/,$ENV{'GSDLEXTS'});
44 foreach my $e (@extensions) {
45 my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
46
47 unshift (@INC, "$ext_prefix/perllib");
48 unshift (@INC, "$ext_prefix/perllib/cpan");
49 unshift (@INC, "$ext_prefix/perllib/plugins");
50 unshift (@INC, "$ext_prefix/perllib/plugouts");
51 }
52 }
53}
54
55use strict;
56no strict 'refs'; # allow filehandles to be variables and vice versa
57no strict 'subs'; # allow barewords (eg STDERR) as function arguments
58
59use arcinfo;
60use colcfg;
61use plugin;
62use plugout;
63use manifest;
64use inexport;
65use util;
66use scriptutil;
67use FileHandle;
68use gsprintf 'gsprintf';
69use printusage;
70use parse2;
71
72
73my $oidtype_list =
74 [ { 'name' => "hash",
75 'desc' => "{import.OIDtype.hash}" },
76 { 'name' => "assigned",
77 'desc' => "{import.OIDtype.assigned}" },
78 { 'name' => "incremental",
79 'desc' => "{import.OIDtype.incremental}" },
80 { 'name' => "dirname",
81 'desc' => "{import.OIDtype.dirname}" } ];
82
83# what format to export as
84my $saveas_list =
85 [ { 'name' => "GreenstoneMETS",
86 'desc' => "{export.saveas.GreenstoneMETS}"},
87 { 'name' => "FedoraMETS",
88 'desc' => "{export.saveas.FedoraMETS}"},
89 { 'name' => "MARCXML",
90 'desc' => "{export.saveas.MARCXML}"},
91 { 'name' => "DSpace",
92 'desc' => "{export.saveas.DSpace}" }
93 ];
94
95
96# Possible attributes for each argument
97# name: The name of the argument
98# desc: A description (or more likely a reference to a description) for this argument
99# type: The type of control used to represent the argument. Options include: string, int, flag, regexp, metadata, language, enum etc
100# reqd: Is this argument required?
101# hiddengli: Is this argument hidden in GLI?
102# modegli: The lowest detail mode this argument is visible at in GLI
103
104my $saveas_argument =
105 { 'name' => "saveas",
106 'desc' => "{export.saveas}",
107 'type' => "enum",
108 'list' => $saveas_list,
109 'deft' => "GreenstoneMETS",
110 'reqd' => "no",
111 'modegli' => "3" };
112
113
114my $arguments =
115 [
116 $saveas_argument,
117 { 'name' => "exportdir",
118 'desc' => "{export.exportdir}",
119 'type' => "string",
120 'reqd' => "no",
121 'hiddengli' => "yes" },
122 { 'name' => "importdir",
123 'desc' => "{import.importdir}",
124 'type' => "string",
125 'reqd' => "no",
126 'hiddengli' => "yes" },
127 { 'name' => "collectdir",
128 'desc' => "{export.collectdir}",
129 'type' => "string",
130 # parsearg left "" as default
131 #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
132 'deft' => "",
133 'reqd' => "no",
134 'hiddengli' => "yes" },
135 { 'name' => "site",
136 'desc' => "{import.site}",
137 'type' => "string",
138 'deft' => "",
139 'reqd' => "no",
140 'hiddengli' => "yes" },
141 { 'name' => "manifest",
142 'desc' => "{import.manifest}",
143 'type' => "string",
144 'deft' => "",
145 'reqd' => "no",
146 'hiddengli' => "yes" },
147 { 'name' => "debug",
148 'desc' => "{export.debug}",
149 'type' => "flag",
150 'reqd' => "no",
151 'hiddengli' => "yes" },
152 { 'name' => "faillog",
153 'desc' => "{export.faillog}",
154 'type' => "string",
155 'deft' => "",
156 'reqd' => "no",
157 'modegli' => "3" },
158 # does this make sense?
159 { 'name' => "incremental",
160 'desc' => "{import.incremental}",
161 'type' => "flag",
162 'hiddengli' => "yes" },
163 { 'name' => "keepold",
164 'desc' => "{export.keepold}",
165 'type' => "flag",
166 'reqd' => "no",
167 'hiddengli' => "yes" },
168 { 'name' => "removeold",
169 'desc' => "{export.removeold}",
170 'type' => "flag",
171 'reqd' => "no",
172 'hiddengli' => "yes" },
173 { 'name' => "language",
174 'desc' => "{scripts.language}",
175 'type' => "string",
176 'reqd' => "no",
177 'hiddengli' => "yes" },
178 { 'name' => "maxdocs",
179 'desc' => "{export.maxdocs}",
180 'type' => "int",
181 'reqd' => "no",
182 'range' => "1,",
183 'modegli' => "1" },
184 { 'name' => "OIDtype",
185 'desc' => "{import.OIDtype}",
186 'type' => "enum",
187 'list' => $oidtype_list,
188 # parsearg left "" as default
189 #'deft' => "hash",
190 'reqd' => "no",
191 'modegli' => "2" },
192 { 'name' => "OIDmetadata",
193 'desc' => "{import.OIDmetadata}",
194 'type' => "string",
195 #'type' => "metadata", #doesn't work properly in GLI
196 'deft' => "dc.Identifier",
197 'reqd' => "no",
198 'modegli' => "2" },
199 { 'name' => "out",
200 'desc' => "{export.out}",
201 'type' => "string",
202 'deft' => "STDERR",
203 'reqd' => "no",
204 'hiddengli' => "yes" },
205 { 'name' => "statsfile",
206 'desc' => "{export.statsfile}",
207 'type' => "string",
208 'deft' => "STDERR",
209 'reqd' => "no",
210 'hiddengli' => "yes" },
211 { 'name' => "xsltfile",
212 'desc' => "{BasPlugout.xslt_file}",
213 'type' => "string",
214 'reqd' => "no",
215 'hiddengli' => "yes" },
216 { 'name' => "xslt_txt",
217 'desc' => "{METSPlugout.xslt_txt}",
218 'type' => "string",
219 'reqd' => "no",
220 'hiddengli' => "no" },
221 { 'name' => "xslt_mets",
222 'desc' => "{METSPlugout.xslt_mets}",
223 'type' => "string",
224 'reqd' => "no",
225 'hiddengli' => "no" },
226 { 'name' => "fedora_namespace",
227 'desc' => "{FedoraMETSPlugout.fedora_namespace}",
228 'type' => "string",
229 'deft' => "greenstone",
230 'reqd' => "no",
231 'hiddengli' => "no" },
232 { 'name' => "mapping_file",
233 'desc' => "{MARCXMLPlugout.mapping_file}",
234 'type' => "string",
235 'reqd' => "no",
236 'hiddengli' => "no" },
237 { 'name' => "group_marc",
238 'desc' => "{MARCXMLPlugout.group}",
239 'type' => "flag",
240 'reqd' => "no",
241 'hiddengli' => "no" },
242 { 'name' => "verbosity",
243 'desc' => "{export.verbosity}",
244 'type' => "int",
245 'range' => "0,3",
246 'deft' => "2",
247 'reqd' => "no",
248 'modegli' => "3" },
249 { 'name' => "gli",
250 'desc' => "{scripts.gli}",
251 'type' => "flag",
252 'reqd' => "no",
253 'hiddengli' => "yes" },
254 { 'name' => "listall",
255 'desc' => "{export.listall}",
256 'type' => "flag",
257 'reqd' => "no" },
258 { 'name' => "xml",
259 'desc' => "{scripts.xml}",
260 'type' => "flag",
261 'reqd' => "no",
262 'hiddengli' => "yes" }
263 ];
264
265my $options = { 'name' => "export.pl",
266 'desc' => "{export.desc}",
267 'args' => $arguments };
268
269my $listall_options = { 'name' => "export.pl",
270 'desc' => "{export.desc}",
271 'args' => [ $saveas_argument ] };
272
273
274&main();
275
276sub main {
277 # params
278 my ($language, $verbosity, $debug,
279 $collectdir, $importdir, $exportdir, $site, $manifest,
280 $incremental, $incremental_mode, $keepold, $removeold,
281 $saveas,
282 $OIDtype, $OIDmetadata,
283 $maxdocs, $statsfile,
284 $gzip,
285 $out, $faillog, $gli, $listall,
286 # plugout specific ones
287 $mapping_file, $xsltfile,
288 $xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
289
290 my $xml = 0;
291
292 # other vars
293 my ($configfilename, $collection, $collectcfg,
294 $expinfo_doc_filename, $expinfo_src_filename, $export_info,
295 $gs_mode,
296 $processor, $pluginfo);
297
298 my $service = "export";
299
300 my $hashParsingResult = {};
301 # general options available to all plugins
302 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
303
304 # If parse returns -1 then something has gone wrong
305 if ($intArgLeftinAfterParsing == -1)
306 {
307 &PrintUsage::print_txt_usage($options, "{export.params}");
308 die "\n";
309 }
310
311 foreach my $strVariable (keys %$hashParsingResult)
312 {
313 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
314 }
315
316
317 # If $language has been specified, load the appropriate resource bundle
318 # (Otherwise, the default resource bundle will be loaded automatically)
319 if ($language && $language =~ /\S/) {
320 &gsprintf::load_language_specific_resource_bundle($language);
321 }
322
323 if ($listall) {
324 if ($xml) {
325 &PrintUsage::print_xml_usage($listall_options);
326 }
327 else
328 {
329 &PrintUsage::print_txt_usage($listall_options,"{export.params}");
330 }
331 die "\n";
332 }
333
334 if ($xml) {
335 &PrintUsage::print_xml_usage($options);
336 die "\n";
337 }
338
339 if ($gli) { # the gli wants strings to be in UTF-8
340 &gsprintf::output_strings_in_UTF8;
341 }
342
343 # now check that we had exactly one leftover arg, which should be
344 # the collection name. We don't want to do this earlier, cos
345 # -xml arg doesn't need a collection name
346 # Or if the user specified -h, then we output the usage also
347 if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
348 {
349 &PrintUsage::print_txt_usage($options, "{export.params}");
350 die "\n";
351 }
352
353 my $close_out = 0;
354 if ($out !~ /^(STDERR|STDOUT)$/i) {
355 open (OUT, ">$out") ||
356 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
357 $out = 'export::OUT';
358 $close_out = 1;
359 }
360 $out->autoflush(1);
361
362 # get and check the collection name
363 if (($collection = &colcfg::use_collection($site, @ARGV, $collectdir)) eq "") {
364 &PrintUsage::print_txt_usage($options, "{export.params}");
365 die "\n";
366 }
367 # add collection's perllib dir into include path in
368 # case we have collection specific modules
369 unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
370
371 # check that we can open the faillog
372 if ($faillog eq "") {
373 $faillog = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "etc", "fail.log");
374 }
375 open (FAILLOG, ">$faillog") ||
376 (&gsprintf(STDERR, "{export.cannot_open_fail_log}\n", $faillog) && die);
377 my $faillogname = $faillog;
378 $faillog = 'export::FAILLOG';
379 $faillog->autoflush(1);
380
381 # Read in the collection configuration file.
382 ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
383 $collectcfg = &colcfg::read_collection_cfg ($configfilename, $gs_mode);
384
385 if (defined $collectcfg->{'importdir'} && $importdir eq "") {
386 $importdir = $collectcfg->{'importdir'};
387 }
388 if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
389 $exportdir = $collectcfg->{'exportdir'};
390 }
391
392 # fill in the default import and export directories if none
393 # were supplied, turn all \ into / and remove trailing /
394 $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
395 $importdir =~ s/[\\\/]+/\//g;
396 $importdir =~ s/\/$//;
397 if (!-e $importdir) {
398 &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
399 die "\n";
400 }
401
402 $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
403 $exportdir =~ s/[\\\/]+/\//g;
404 $exportdir =~ s/\/$//;
405
406 my $plugins = [];
407 if (defined $collectcfg->{'plugin'}) {
408 $plugins = $collectcfg->{'plugin'};
409 }
410 # some global options for the plugins
411 my @global_opts = ();
412
413 if ($verbosity !~ /\d+/) {
414 if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
415 $verbosity = $collectcfg->{'verbosity'};
416 } else {
417 $verbosity = 2; # the default
418 }
419 }
420
421 if (defined $collectcfg->{'manifest'} && $manifest eq "") {
422 $manifest = $collectcfg->{'manifest'};
423 }
424 if (defined $collectcfg->{'gzip'} && !$gzip) {
425 if ($collectcfg->{'gzip'} =~ /^true$/i) {
426 $gzip = 1;
427 }
428 }
429 if ($maxdocs !~ /\-?\d+/) {
430 if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
431 $maxdocs = $collectcfg->{'maxdocs'};
432 } else {
433 $maxdocs = -1; # the default
434 }
435 }
436
437 # groupsize is in import - does it make sense here??
438
439 if (!defined $OIDtype || ($OIDtype !~ /^(hash|incremental|assigned|dirname)$/)) {
440 if (defined $collectcfg->{'OIDtype'} && $collectcfg->{'OIDtype'} =~ /^(hash|incremental|assigned|dirname)$/) {
441 $OIDtype = $collectcfg->{'OIDtype'};
442 } else {
443 $OIDtype = "hash"; # the default
444 }
445 }
446
447 if ((!defined $OIDmetadata) || ($OIDmetadata eq "")) {
448 if (defined $collectcfg->{'OIDmetadata'}) {
449 $OIDmetadata = $collectcfg->{'OIDmetadata'};
450 } else {
451 $OIDmetadata = "dc.Identifier"; # the default
452 }
453 }
454
455 if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
456 $debug = 1;
457 }
458 if (defined $collectcfg->{'gli'} && $collectcfg->{'gli'} =~ /^true$/i) {
459 $gli = 1;
460 }
461 $gli = 0 unless defined $gli;
462
463 # check keepold and removeold
464 ($removeold, $keepold, $incremental, $incremental_mode)
465 = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
466 $incremental, "export",
467 $collectcfg);
468
469 print STDERR "<export>\n" if $gli;
470
471 my $manifest_lookup = new manifest();
472 if ($manifest ne "") {
473 my $manifest_filename = $manifest;
474
475 if ($manifest_filename !~ m/^[\\\/]/) {
476 $manifest_filename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, $manifest_filename);
477 }
478
479 $manifest =~ s/[\\\/]+/\//g;
480 $manifest =~ s/\/$//;
481
482 $manifest_lookup->parse($manifest_filename);
483 }
484
485 # load all the plugins
486 $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts, $incremental_mode);
487
488 if (scalar(@$pluginfo) == 0) {
489 &gsprintf($out, "{import.no_plugins_loaded}\n");
490 die "\n";
491 }
492
493 # remove the old contents of the export directory if needed
494 if ($removeold && -e $exportdir) {
495 &gsprintf($out, "{export.removing_export}\n");
496 &util::rm_r ($exportdir);
497 }
498
499 # create the export dir if needed
500 &util::mk_all_dir($exportdir);
501
502 # read the export information file
503 # If saveas=DSpace, a "contents" file will be created, otherwise "export.inf"
504
505 # the plugouts should be doing this!!
506 if ($saveas eq "DSpace"){
507 $expinfo_doc_filename = &util::filename_cat ($exportdir, "contents");
508 } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "MARCXML" ) {
509## $expinfo_doc_filename = &util::filename_cat ($exportdir, "export.inf");
510 $expinfo_doc_filename = &util::filename_cat ($exportdir,"archiveinf-doc" );
511 &util::rename_gdbm_file($expinfo_doc_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
512 $expinfo_doc_filename .= ".gdb";
513
514 $expinfo_src_filename = &util::filename_cat ($exportdir,"archiveinf-src" );
515 &util::rename_gdbm_file($expinfo_src_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
516 $expinfo_src_filename .= ".gdb";
517
518 }
519
520 $export_info = new arcinfo();
521 $export_info -> load_info ($expinfo_doc_filename);
522
523 if ($manifest eq "") {
524 # Load in list of files in export folder from last export (if present)
525 $export_info->load_prev_import_filelist ($expinfo_src_filename);
526 }
527
528 my ($plugout);
529 if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
530 $plugout = $collectcfg->{'plugout'};
531 }
532 else{
533 if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
534 push @$plugout,"GreenstoneMETSPlugout";
535 }
536 else{
537 push @$plugout,$saveas."Plugout";
538 }
539 }
540
541 my $plugout_name = $plugout->[0];
542
543 push @$plugout,("-output_info",$export_info) if (defined $export_info);
544 push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
545 push @$plugout,("-debug") if ($debug);
546 push @$plugout,("-gzip_output") if ($gzip);
547 push @$plugout,("-output_handle",$out) if (defined $out);
548 push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile && $xsltfile ne "");
549 push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
550 push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "" && $plugout_name =~ m/^MARCXMLPlugout$/);
551 push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $xslt_mets ne "" && $plugout_name =~ m/^.*METSPlugout$/);
552 push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $xslt_txt ne "" && $plugout_name =~ m/^.*METSPlugout$/);
553 push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "" && $plugout_name eq "FedoraMETSPlugout");
554
555 $processor = &plugout::load_plugout($plugout);
556 $processor->setoutputdir ($exportdir);
557
558 $processor->set_OIDtype ($OIDtype, $OIDmetadata);
559
560 &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
561
562 if ($manifest eq "") {
563 # process the import directory
564 my $block_hash = {};
565 my $metadata = {};
566 # gobal blocking pass may set up some metadata
567 &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
568 #&plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
569 ### section below copied from import.pl
570 if ($incremental) {
571 # equivalent to saying ($keepold && ($incremental_mode eq "all"))
572
573 &inexport::prime_doc_oid_count($exportdir);
574
575
576 # Can now work out which files were new, already existed, and have
577 # been deleted
578
579 &inexport::new_vs_old_import_diff($export_info,$block_hash,$importdir,
580 $exportdir,$verbosity,$incremental_mode);
581
582 my @deleted_files = sort keys %{$block_hash->{'deleted_files'}};
583 # Filter out any in gsdl/tmp area
584 my @filtered_deleted_files = ();
585 my $gsdl_tmp_area = &util::filename_cat($ENV{'GSDLHOME'}, "tmp");
586 my $collect_tmp_area = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
587 $gsdl_tmp_area = &util::filename_to_regex($gsdl_tmp_area);
588 $collect_tmp_area = &util::filename_to_regex($collect_tmp_area);
589
590
591 foreach my $df (@deleted_files) {
592 next if ($df =~ m/^$gsdl_tmp_area/);
593 next if ($df =~ m/^$collect_tmp_area/);
594
595 push(@filtered_deleted_files,$df);
596 }
597
598
599 @deleted_files = @filtered_deleted_files;
600
601 if (scalar(@deleted_files>0)) {
602 print STDERR "Files deleted since last import:\n ";
603 print STDERR join("\n ",@deleted_files), "\n";
604 }
605
606 my @new_files = sort keys %{$block_hash->{'new_files'}};
607 if (scalar(@new_files>0)) {
608 print STDERR "New files since last import:\n ";
609 print STDERR join("\n ",@new_files), "\n";
610 }
611
612 &inexport::mark_docs_for_deletion($export_info,$block_hash,\@deleted_files,
613 $exportdir,$verbosity);
614
615 &inexport::mark_docs_for_reindex($export_info,$block_hash,
616 $exportdir,$verbosity);
617
618 my @reindex_files = sort keys %{$block_hash->{'reindex_files'}};
619
620 if (scalar(@reindex_files>0)) {
621 print STDERR "Files to reindex since last import:\n ";
622 print STDERR join("\n ",@reindex_files), "\n";
623 }
624
625
626 # not sure if the following will work -- will the metadata data-structure be correctly initialized
627 # in the right order?
628# foreach my $file (@new_files, @reindex_files) {
629# &plugin::read ($pluginfo, $importdir, $file, $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
630# }
631
632
633 # Play it safe, and run through the entire folder, only processing new or edited files
634 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
635
636 }
637 else {
638 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
639 }
640
641 ### end copy
642 }
643 else {
644 # process any files marked for exporting
645 foreach my $file (keys %{$manifest_lookup->{'index'}}) {
646 &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
647 }
648
649 my @deleted_files = keys %{$manifest_lookup->{'delete'}};
650
651 &inexport::mark_docs_for_deletion($export_info,{},\@deleted_files,$exportdir);
652
653 }
654
655 if ($saveas eq "FedoraMETS") {
656 # create collection "doc obj" for Fedora that contains
657 # collection-level metadata
658
659 my $doc_obj = new doc($configfilename,"nonindexed_doc","none");
660 $doc_obj->set_OID("collection");
661
662 my $col_name = undef;
663 my $col_meta = $collectcfg->{'collectionmeta'};
664
665 if (defined $col_meta) {
666
667 store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
668 store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description
669
670 }
671 $processor->process($doc_obj);
672 }
673
674 &plugin::end($pluginfo, $processor);
675
676 &plugin::deinit($pluginfo, $processor);
677
678 # Store the value of OIDCount (used in doc.pm) so it can be
679 # restored correctly to this value on an incremental build
680 &inexport::store_doc_oid_count($exportdir);
681
682 # write out the export information file
683 #$processor->close_file_output() if $groupsize > 1;
684 $processor->close_group_output() if $processor->is_group();
685
686# if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARCXML")) {
687# # Not all export types need this,
688
689## $export_info->save_info($expinfo_doc_filename);
690# }
691
692
693 # for backwards compatability with archvies.inf file
694 if ($expinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
695 $export_info->save_info($expinfo_doc_filename);
696 }
697 else {
698 $export_info->save_revinfo_gdbm($expinfo_src_filename);
699 }
700
701
702 # write out export stats
703 my $close_stats = 0;
704 if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
705 if (open (STATS, ">$statsfile")) {
706 $statsfile = 'import::STATS';
707 $close_stats = 1;
708 } else {
709 &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
710 &gsprintf($out, "{import.stats_backup}\n");
711 $statsfile = 'STDERR';
712 }
713 }
714
715 &gsprintf($out, "\n");
716 &gsprintf($out, "*********************************************\n");
717 &gsprintf($out, "{export.complete}\n");
718 &gsprintf($out, "*********************************************\n");
719
720 &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
721 if ($close_stats) {
722 close STATS;
723 }
724
725 close OUT if $close_out;
726 close FAILLOG;
727}
728
729
730sub store_collectionmeta
731{
732 my ($collectionmeta,$field,$doc_obj) = @_;
733
734 my $section = $doc_obj->get_top_section();
735
736 my $field_hash = $collectionmeta->{$field};
737
738 foreach my $k (keys %$field_hash)
739 {
740 my $val = $field_hash->{$k};
741
742 ### print STDERR "*** $k = $field_hash->{$k}\n";
743
744 my $md_label = "ex.$field";
745
746
747 if ($k =~ m/^\[l=(.*?)\]$/)
748 {
749
750 my $md_suffix = $1;
751 $md_label .= "^$md_suffix";
752 }
753
754
755 $doc_obj->add_utf8_metadata($section,$md_label, $val);
756
757 # see collConfigxml.pm: GS2's "collectionextra" is called "description" in GS3,
758 # while "collectionname" in GS2 is called "name" in GS3.
759 # Variable $nameMap variable in collConfigxml.pm maps between GS2 and GS3
760 if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
761 {
762 $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
763 }
764
765 }
766}
767
768
769
770
Note: See TracBrowser for help on using the repository browser.