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

Last change on this file since 20652 was 20652, checked in by davidb, 15 years ago

Updated to support incremental exporting

  • 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) {
495 if (-e $exportdir) {
496 &gsprintf($out, "{export.removing_export}\n");
497 &util::rm_r ($exportdir);
498 }
499 my $tmpdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "tmp");
500 $tmpdir =~ s/[\\\/]+/\//g;
501 $tmpdir =~ s/\/$//;
502 if (-e $tmpdir) {
503 &gsprintf($out, "{import.removing_tmpdir}\n");
504 &util::rm_r ($tmpdir);
505 }
506 }
507
508 # create the export dir if needed
509 &util::mk_all_dir($exportdir);
510
511 # read the export information file
512
513 # the plugouts should be doing this!!
514## $expinfo_doc_filename = &util::filename_cat ($exportdir, "export.inf");
515 $expinfo_doc_filename = &util::filename_cat ($exportdir,"archiveinf-doc" );
516 &util::rename_gdbm_file($expinfo_doc_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
517 $expinfo_doc_filename .= ".gdb";
518
519 $expinfo_src_filename = &util::filename_cat ($exportdir,"archiveinf-src" );
520 &util::rename_gdbm_file($expinfo_src_filename); # ensures gdb in case we have an existing legacy ldb one - can this happen?
521 $expinfo_src_filename .= ".gdb";
522
523
524 $export_info = new arcinfo();
525 $export_info -> load_info ($expinfo_doc_filename);
526
527 if ($manifest eq "") {
528 # Load in list of files in export folder from last export (if present)
529 $export_info->load_prev_import_filelist ($expinfo_src_filename);
530 }
531
532 my ($plugout);
533 if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
534 $plugout = $collectcfg->{'plugout'};
535 }
536 else{
537 if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
538 push @$plugout,"GreenstoneMETSPlugout";
539 }
540 else{
541 push @$plugout,$saveas."Plugout";
542 }
543 }
544
545 my $plugout_name = $plugout->[0];
546
547 push @$plugout,("-output_info",$export_info) if (defined $export_info);
548 push @$plugout,("-verbosity",$verbosity) if (defined $verbosity);
549 push @$plugout,("-debug") if ($debug);
550 push @$plugout,("-gzip_output") if ($gzip);
551 push @$plugout,("-output_handle",$out) if (defined $out);
552 push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile && $xsltfile ne "");
553 push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
554 push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "" && $plugout_name =~ m/^MARCXMLPlugout$/);
555 push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $xslt_mets ne "" && $plugout_name =~ m/^.*METSPlugout$/);
556 push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $xslt_txt ne "" && $plugout_name =~ m/^.*METSPlugout$/);
557 push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "" && $plugout_name eq "FedoraMETSPlugout");
558
559 $processor = &plugout::load_plugout($plugout);
560 $processor->setoutputdir ($exportdir);
561
562 $processor->set_OIDtype ($OIDtype, $OIDmetadata);
563
564 &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
565
566 if ($manifest eq "") {
567 # process the import directory
568 my $block_hash = {};
569 my $metadata = {};
570 # gobal blocking pass may set up some metadata
571 &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
572 #&plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
573 ### section below copied from import.pl
574 if ($incremental) {
575 # equivalent to saying ($keepold && ($incremental_mode eq "all"))
576
577 &inexport::prime_doc_oid_count($exportdir);
578
579
580 # Can now work out which files were new, already existed, and have
581 # been deleted
582
583 &inexport::new_vs_old_import_diff($export_info,$block_hash,$importdir,
584 $exportdir,$verbosity,$incremental_mode);
585
586 my @deleted_files = sort keys %{$block_hash->{'deleted_files'}};
587 # Filter out any in gsdl/tmp area
588 my @filtered_deleted_files = ();
589 my $gsdl_tmp_area = &util::filename_cat($ENV{'GSDLHOME'}, "tmp");
590 my $collect_tmp_area = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
591 $gsdl_tmp_area = &util::filename_to_regex($gsdl_tmp_area);
592 $collect_tmp_area = &util::filename_to_regex($collect_tmp_area);
593
594
595 foreach my $df (@deleted_files) {
596 next if ($df =~ m/^$gsdl_tmp_area/);
597 next if ($df =~ m/^$collect_tmp_area/);
598
599 push(@filtered_deleted_files,$df);
600 }
601
602
603 @deleted_files = @filtered_deleted_files;
604
605 if (scalar(@deleted_files>0)) {
606 print STDERR "Files deleted since last import:\n ";
607 print STDERR join("\n ",@deleted_files), "\n";
608 }
609
610 my @new_files = sort keys %{$block_hash->{'new_files'}};
611 if (scalar(@new_files>0)) {
612 print STDERR "New files since last import:\n ";
613 print STDERR join("\n ",@new_files), "\n";
614 }
615
616 &inexport::mark_docs_for_deletion($export_info,$block_hash,\@deleted_files,
617 $exportdir,$verbosity);
618
619 &inexport::mark_docs_for_reindex($export_info,$block_hash,
620 $exportdir,$verbosity);
621
622 my @reindex_files = sort keys %{$block_hash->{'reindex_files'}};
623
624 if (scalar(@reindex_files>0)) {
625 print STDERR "Files to reindex since last import:\n ";
626 print STDERR join("\n ",@reindex_files), "\n";
627 }
628
629
630 # not sure if the following will work -- will the metadata data-structure be correctly initialized
631 # in the right order?
632# foreach my $file (@new_files, @reindex_files) {
633# &plugin::read ($pluginfo, $importdir, $file, $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
634# }
635
636
637 # Play it safe, and run through the entire folder, only processing new or edited files
638 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
639
640 }
641 else {
642 &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
643 }
644
645 ### end copy
646 }
647 else {
648 # process any files marked for exporting
649 foreach my $file (keys %{$manifest_lookup->{'index'}}) {
650 &plugin::read ($pluginfo, $importdir, $file, {}, {}, $processor, $maxdocs, 0, $gli);
651 }
652
653 my @deleted_files = keys %{$manifest_lookup->{'delete'}};
654
655 &inexport::mark_docs_for_deletion($export_info,{},\@deleted_files,$exportdir);
656
657 }
658
659 if ($saveas eq "FedoraMETS") {
660 # create collection "doc obj" for Fedora that contains
661 # collection-level metadata
662
663 my $doc_obj = new doc($configfilename,"nonindexed_doc","none");
664 $doc_obj->set_OID("collection");
665
666 my $col_name = undef;
667 my $col_meta = $collectcfg->{'collectionmeta'};
668
669 if (defined $col_meta) {
670
671 store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
672 store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description
673
674 }
675 $processor->process($doc_obj);
676 }
677
678 &plugin::end($pluginfo, $processor);
679
680 &plugin::deinit($pluginfo, $processor);
681
682 # Store the value of OIDCount (used in doc.pm) so it can be
683 # restored correctly to this value on an incremental build
684 &inexport::store_doc_oid_count($exportdir);
685
686 # write out the export information file
687 #$processor->close_file_output() if $groupsize > 1;
688 $processor->close_group_output() if $processor->is_group();
689
690# if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARCXML")) {
691# # Not all export types need this,
692
693## $export_info->save_info($expinfo_doc_filename);
694# }
695
696
697 # for backwards compatability with archvies.inf file
698 if ($expinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
699 $export_info->save_info($expinfo_doc_filename);
700 }
701 else {
702 $export_info->save_revinfo_gdbm($expinfo_src_filename);
703 }
704
705
706 # write out export stats
707 my $close_stats = 0;
708 if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
709 if (open (STATS, ">$statsfile")) {
710 $statsfile = 'import::STATS';
711 $close_stats = 1;
712 } else {
713 &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
714 &gsprintf($out, "{import.stats_backup}\n");
715 $statsfile = 'STDERR';
716 }
717 }
718
719 &gsprintf($out, "\n");
720 &gsprintf($out, "*********************************************\n");
721 &gsprintf($out, "{export.complete}\n");
722 &gsprintf($out, "*********************************************\n");
723
724 &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
725 if ($close_stats) {
726 close STATS;
727 }
728
729 close OUT if $close_out;
730 close FAILLOG;
731}
732
733
734sub store_collectionmeta
735{
736 my ($collectionmeta,$field,$doc_obj) = @_;
737
738 my $section = $doc_obj->get_top_section();
739
740 my $field_hash = $collectionmeta->{$field};
741
742 foreach my $k (keys %$field_hash)
743 {
744 my $val = $field_hash->{$k};
745
746 ### print STDERR "*** $k = $field_hash->{$k}\n";
747
748 my $md_label = "ex.$field";
749
750
751 if ($k =~ m/^\[l=(.*?)\]$/)
752 {
753
754 my $md_suffix = $1;
755 $md_label .= "^$md_suffix";
756 }
757
758
759 $doc_obj->add_utf8_metadata($section,$md_label, $val);
760
761 # see collConfigxml.pm: GS2's "collectionextra" is called "description" in GS3,
762 # while "collectionname" in GS2 is called "name" in GS3.
763 # Variable $nameMap variable in collConfigxml.pm maps between GS2 and GS3
764 if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
765 {
766 $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
767 }
768
769 }
770}
771
772
773
774
Note: See TracBrowser for help on using the repository browser.