3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 : $@";