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