source: main/trunk/greenstone2/bin/script/export.pl@ 21613

Last change on this file since 21613 was 21613, checked in by mdewsnip, 14 years ago

Changed calls to read_collection_cfg() so the infodbtype value is set to be the default infodbtype (from dbutil), if not defined in the collect.cfg file. Part of making the code less GDBM-specific.

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