source: main/trunk/greenstone2/bin/script/import.pl@ 21664

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

Renamed util::rename_gdbm_file() to util::rename_ldb_or_bdb_file().

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