3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
20 =head1 batchupdateISBNs.pl
22 This script batch updates ISBN fields
28 # find Koha's Perl modules
29 # test carefully before changing this
31 eval { require "$FindBin::Bin/kohalib.pl" };
38 my ( $no_marcxml, $no_isbn, $help) = (0,0,0);
41 'noisbn' => \
$no_isbn,
42 'noxml' => \
$no_marcxml,
49 my $dbh = C4
::Context
->dbh;
55 \t-noisbn don
't remove '-' in biblioitems.isbn
56 \t-noxml don't remove
'-' in biblioitems
.marcxml
in field
010a
66 SELECT biblioitemnumber,isbn FROM biblioitems WHERE isbn IS NOT NULL ORDER BY biblioitemnumber
70 UPDATE biblioitems SET isbn=? WHERE biblioitemnumber = ?
73 my $sth = $dbh->prepare($query_isbn);
76 while (my $data = $sth->fetchrow_arrayref){
77 my $biblioitemnumber = $data->[0];
78 print "\rremoving '-' on isbn for biblioitemnumber $biblioitemnumber";
80 # suppression des tirets de l'isbn
81 my $isbn = $data->[1];
86 my $sth = $dbh->prepare($update_isbn);
87 $sth->execute($isbn,$biblioitemnumber);
91 print "$cpt_isbn updated";
97 SELECT biblioitemnumber,marcxml FROM biblioitems WHERE isbn IS NOT NULL ORDER BY biblioitemnumber
101 my $update_marcxml = "
102 UPDATE biblioitems SET marcxml=? WHERE biblioitemnumber = ?
105 my $sth = $dbh->prepare($query_marcxml);
108 while (my $data = $sth->fetchrow_arrayref){
110 my $biblioitemnumber = $data->[0];
111 print "\rremoving '-' on marcxml for biblioitemnumber $biblioitemnumber";
113 # suppression des tirets de l'isbn dans la notice
114 my $marcxml = $data->[1];
117 my $record = MARC
::Record
->new_from_xml($marcxml,'UTF-8','UNIMARC');
118 my @field = $record->field('010');
120 foreach my $field (@field){
121 my $subfield = $field->subfield('a');
123 my $isbn = $subfield;
125 $field->update('a' => $isbn);
130 $marcxml = $record->as_xml_record('UNIMARC');
132 my $sth = $dbh->prepare($update_marcxml);
133 $sth->execute($marcxml,$biblioitemnumber);
137 print "\n /!\\ pb getting $biblioitemnumber : $@";