Merge remote-tracking branch 'kc/new/bug_5449' into kcmaster
[koha.git] / misc / maintenance / remove_items_from_biblioitems.pl
1 #!/usr/bin/perl
2
3 # Copyright 2010 BibLibre
4 # Copyright 2011 Equinox Software, Inc.
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use strict;
22 use warnings;
23
24 use C4::Context;
25 use C4::Biblio;
26 use Getopt::Long;
27
28 my ($wherestring, $run, $want_help);
29 my $result = GetOptions(
30     'where:s'      => \$wherestring,
31     '--run'        => \$run,
32     'help|h'       => \$want_help,
33 );
34
35 if ( not $result or not $run or $want_help ) {
36     print_usage();
37     exit 0;
38 }
39
40 my $dbh = C4::Context->dbh;
41 my $querysth =  qq{SELECT biblionumber from biblioitems };
42 $querysth    .= " WHERE $wherestring " if ($wherestring);
43 my $query = $dbh->prepare($querysth);
44 $query->execute;
45 while (my $biblionumber = $query->fetchrow){
46     my $record = GetMarcBiblio($biblionumber);
47     
48     if ($record) {
49         ModBiblio($record, $biblionumber, GetFrameworkCode($biblionumber)) ;
50     }
51     else {
52         print "error in $biblionumber : can't parse biblio";
53     }
54 }
55
56 sub print_usage {
57     print <<_USAGE_;
58 $0: removes items from selected biblios
59
60 This utility is meant to be run as part of the upgrade to
61 Koha 3.4.  It removes the 9XX fields in the bib records that
62 store a (now) duplicate copy of the item record information.  After
63 running this utility, a full reindexing of the bibliographic records
64 should be run using rebuild_zebra.pl -b -r.
65
66 Parameters:
67     -where                  use this to limit modifications to selected biblios
68     --run                   perform the update
69     --help or -h            show this message
70 _USAGE_
71 }