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
27 #use warnings; FIXME - Bug 2505
29 # find Koha's Perl modules
30 # test carefully before changing this
32 eval { require "$FindBin::Bin/kohalib.pl" };
39 my ( $no_marcxml, $no_isbn, $help) = (0,0,0);
42 'noisbn' => \
$no_isbn,
43 'noxml' => \
$no_marcxml,
50 my $dbh = C4
::Context
->dbh;
56 \t-noisbn don
't remove '-' in biblioitems.isbn
57 \t-noxml don't remove
'-' in biblioitems
.marcxml
in field
010a
67 SELECT biblioitemnumber,isbn FROM biblioitems WHERE isbn IS NOT NULL ORDER BY biblioitemnumber
71 UPDATE biblioitems SET isbn=? WHERE biblioitemnumber = ?
74 my $sth = $dbh->prepare($query_isbn);
77 while (my $data = $sth->fetchrow_arrayref){
78 my $biblioitemnumber = $data->[0];
79 print "\rremoving '-' on isbn for biblioitemnumber $biblioitemnumber";
81 # suppression des tirets de l'isbn
82 my $isbn = $data->[1];
87 my $sth = $dbh->prepare($update_isbn);
88 $sth->execute($isbn,$biblioitemnumber);
92 print "$cpt_isbn updated";
98 SELECT biblioitemnumber,marcxml FROM biblioitems WHERE isbn IS NOT NULL ORDER BY biblioitemnumber
102 my $update_marcxml = "
103 UPDATE biblioitems SET marcxml=? WHERE biblioitemnumber = ?
106 my $sth = $dbh->prepare($query_marcxml);
109 while (my $data = $sth->fetchrow_arrayref){
111 my $biblioitemnumber = $data->[0];
112 print "\rremoving '-' on marcxml for biblioitemnumber $biblioitemnumber";
114 # suppression des tirets de l'isbn dans la notice
115 my $marcxml = $data->[1];
118 my $record = MARC
::Record
->new_from_xml($marcxml,'UTF-8','UNIMARC');
119 my @field = $record->field('010');
121 foreach my $field (@field){
122 my $subfield = $field->subfield('a');
124 my $isbn = $subfield;
126 $field->update('a' => $isbn);
131 $marcxml = $record->as_xml_record('UNIMARC');
133 my $sth = $dbh->prepare($update_marcxml);
134 $sth->execute($marcxml,$biblioitemnumber);
138 print "\n /!\\ pb getting $biblioitemnumber : $@";