From ff4e86d0985a8891803456cf560afdf7f2745b3c Mon Sep 17 00:00:00 2001 From: toins Date: Mon, 18 Jun 2007 13:29:38 +0000 Subject: [PATCH] New script: This script allows you to update your database/records after a bulkmarckimport integration. Currectly it reformats biblioitems.isbn and bibliotitems.marcxml on deleting any '-' on isbn. --- misc/bulkupdate.pl | 130 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 misc/bulkupdate.pl diff --git a/misc/bulkupdate.pl b/misc/bulkupdate.pl new file mode 100644 index 0000000000..0ecd12ed02 --- /dev/null +++ b/misc/bulkupdate.pl @@ -0,0 +1,130 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +# $Id$ + + +=head1 bulkupdate.pl + + This script allows you to update your database/records after a bulkmarckimport integration. + +=cut + + +use C4::Context; +use MARC::File::XML; +use MARC::Record; +use Getopt::Long; + +my ( $process_marcxml, $process_isbn, $help) = (0,0,0); + +GetOptions( + 'noisbn' => \$process_isbn, + 'noxml' => \$process_marcxml, + 'h' => \$help, + 'help' => \$help, +); + + +$| = 1; +my $dbh = C4::Context->dbh; + +if($help){ + print qq( + Option : + \t-h show this help + \t-noisbn don't remove '-' in biblioitems.isbn + \t-noxml don't remove '-' in biblioitems.marcxml in field 010a + \n\n + ); + exit; +} + +my $cpt_isbn = 0; +if(not $process_isbn){ + + my $query_isbn = " + SELECT biblioitemnumber,isbn FROM biblioitems WHERE isbn IS NOT NULL + "; + + my $update_isbn = " + UPDATE biblioitems SET isbn=? WHERE biblioitemnumber = ? + "; + + my $sth = $dbh->prepare($query_isbn); + $sth->execute; + + while (my $data = $sth->fetchrow_arrayref){ + my $biblioitemnumber = $data->[0]; + print "\rremoving '-' on isbn for biblioitemnumber $biblioitemnumber"; + + # suppression des tirets de l'isbn + my $isbn = $data->[1]; + if($isbn){ + $isbn =~ s/\-//g; + + #update + my $sth = $dbh->prepare($update_isbn); + $sth->execute($isbn,$biblioitemnumber); + } + $cpt_isbn++; + } + print "$cpt_isbn updated"; +} + +if(not $process_marcxml){ + + my $query_marcxml = " + SELECT biblioitemnumber,marcxml FROM biblioitems WHERE isbn IS NOT NULL + "; + + + my $update_marcxml = " + UPDATE biblioitems SET marcxml=? WHERE biblioitemnumber = ? + "; + + my $sth = $dbh->prepare($query_marcxml); + $sth->execute; + + while (my $data = $sth->fetchrow_arrayref){ + + my $biblioitemnumber = $data->[0]; + print "\rremoving '-' on marcxml for biblioitemnumber $biblioitemnumber"; + + # suppression des tirets de l'isbn dans la notice + my $marcxml = $data->[1]; + + eval{ + my $record = MARC::Record->new_from_xml($marcxml,'UTF-8'); + my $field = $record->field('010'); + my $subfield = $field->subfield('a'); + if($subfield){ + my $isbn = $subfield; + $isbn =~ s/\-//g; + $field->update('a' => $isbn); + $marcxml = $record->as_xml('UTF-8'); + + # Update + my $sth = $dbh->prepare($update_marcxml); + $sth->execute($marcxml,$biblioitemnumber); + } + }; + if($@){ + print "\n /!\\ pb getting $biblioitemnumber : $@"; + } + } +} \ No newline at end of file -- 2.39.5