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