Bug 24153: Add a confirm flag to cleanup_database
[koha.git] / misc / maintenance / remove_items_from_biblioitems.pl
blobd78ad696ad950cbba5f9629278b7a70c81184bc0
1 #!/usr/bin/perl
3 # Copyright 2010 BibLibre
4 # Copyright 2011 Equinox Software, Inc.
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 use warnings;
23 $|=1;
25 use Koha::Script;
26 use C4::Context;
27 use C4::Biblio;
28 use Getopt::Long;
30 my ($wherestring, $run, $silent, $want_help);
31 my $result = GetOptions(
32 'where:s' => \$wherestring,
33 '--run' => \$run,
34 '--silent' => \$silent,
35 'help|h' => \$want_help,
38 if ( not $result or not $run or $want_help ) {
39 print_usage();
40 exit 0;
43 my $dbh = C4::Context->dbh;
44 my $count = 0;
45 my $querysth = qq{SELECT biblionumber from biblioitems };
46 $querysth .= " WHERE $wherestring " if ($wherestring);
47 my $query = $dbh->prepare($querysth);
48 $query->execute;
49 while (my $biblionumber = $query->fetchrow){
50 $count++;
51 print "." unless $silent;
52 print "\r$count" unless ($silent or ($count % 100));
53 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
55 if ($record) {
56 ModBiblio($record, $biblionumber, GetFrameworkCode($biblionumber)) ;
58 else {
59 print "error in $biblionumber : can't parse biblio";
63 print "\n\n$count records processed.\n" unless $silent;
65 sub print_usage {
66 print <<_USAGE_;
67 $0: removes items from selected biblios
69 This utility is meant to be run as part of the upgrade to
70 Koha 3.4. It removes the 9XX fields in the bib records that
71 store a (now) duplicate copy of the item record information. After
72 running this utility, a full reindexing of the bibliographic records
73 should be run using rebuild_zebra.pl -b -r.
75 Parameters:
76 -where use this to limit modifications to selected biblios
77 --run perform the update
78 --silent run silently
79 --help or -h show this message
80 _USAGE_