2 # small script that rebuilds the non-MARC DB
7 # use MARC::File::USMARC;
12 use Time
::HiRes
qw(gettimeofday);
15 my ( $input_marc_file, $number) = ('',0);
16 my ($version, $confirm,$test_parameter);
20 't' => \
$test_parameter,
23 if ($version || (!$confirm)) {
25 This script cleans unused subfields in the MARC DB.
26 If you alter the MARC parameters and remove a subfield (ie : move it to ignore (10) tab), existing subfields are NOT removed.
27 It's not a bug, it prevents deleting useful values in case of erroneous move.
28 This script definetly remove unused subfields in the MARC DB.
30 \t./cleanmarcdb.pl -h (or without arguments => shows this screen)
31 \t./cleanmarcdb.pl -c (c like confirm => cleans the marc DB (may be long)
32 \t-t => test only, change nothing in DB
38 my $dbh = C4
::Context
->dbh;
40 my $starttime = gettimeofday
;
41 my $cleansubfield = $dbh->prepare("delete from marc_subfield_table where tag=? and subfieldcode=?");
42 my $cleanword = $dbh->prepare("delete from marc_word where tag=? and subfieldid=?");
45 my $tags = GetMarcStructure
(1);
46 foreach my $tag (sort keys(%{$tags})) {
47 foreach my $subfield (sort keys(%{$tags->{$tag}})) {
48 next if $subfield eq "lib";
49 next if $subfield eq "mandatory";
50 next if $subfield eq "tab";
51 # DO NOT drop biblionumber, biblioitemnumber and itemnumber.
52 # they are stored internally, and are mapped to tab -1. This script must keep them or it will completly break Koha DB !!!
53 next if ($tags->{$tag}->{$subfield}->{kohafield
} eq "biblio.biblionumber");
54 next if ($tags->{$tag}->{$subfield}->{kohafield
} eq "biblioitems.biblioitemnumber");
55 next if ($tags->{$tag}->{$subfield}->{kohafield
} eq "items.itemnumber");
56 # now, test => if field is ignored (in tab -1 or '') => drop everything in the MARC table !
57 if ($tags->{$tag}->{$subfield}->{tab
} eq -1 || $tags->{$tag}->{$subfield}->{tab
} eq '') {
58 print "dropping $tag \$ $subfield\n";
59 $cleansubfield->execute($tag,$subfield) unless $test_parameter;
60 $cleanword->execute($tag,$subfield) unless $test_parameter;
61 print "TEST " if $test_parameter;
66 my $timeneeded = gettimeofday
- $starttime;
67 print "done in $timeneeded seconds\n";