[Koha-patches] [PATCH] New script to upgrade to ISBN 13
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Tue Sep 29 16:15:17 CEST 2009
This new script upgrade all isbn from the database to ISBN13.
---
misc/maintenance/upgradeISBNto13.pl | 61 +++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
create mode 100755 misc/maintenance/upgradeISBNto13.pl
diff --git a/misc/maintenance/upgradeISBNto13.pl b/misc/maintenance/upgradeISBNto13.pl
new file mode 100755
index 0000000..d6fe17d
--- /dev/null
+++ b/misc/maintenance/upgradeISBNto13.pl
@@ -0,0 +1,61 @@
+#! /usr/bin/perl
+
+use strict;
+use C4::Context;
+use C4::Biblio;
+use C4::Koha;
+use Business::ISBN;
+
+
+BEGIN {
+ use FindBin;
+ eval { require "$FindBin::Bin/../kohalib.pl" };
+}
+
+sub updateMARC {
+ my $biblionumber = shift;
+ my $fwcode = shift;
+
+ my $biblio = GetMarcBiblio($biblionumber);
+ return 0 unless $biblio;
+
+ my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn', $fwcode);
+
+ if ( $biblio->field($isbnfield)) {
+ foreach my $field ( $biblio->field($isbnfield) ) {
+ my $isbn = $field->subfield($isbnsubfield);
+ my $newisbn;
+ eval {
+ $isbn = Business::ISBN->new($isbn);
+ $newisbn = C4::Koha::_isbn_cleanup($isbn->as_isbn13->as_string);
+ };
+
+ if($@){
+ return 0;
+ }
+
+ if($newisbn){
+ $field->update( $isbnsubfield => $newisbn );
+ ModBiblio($biblio, $biblionumber, $fwcode);
+ return 1;
+ }
+ }
+ }
+
+}
+
+sub process {
+ my $dbh = C4::Context->dbh;
+ # on génère les publics existants
+ my $sth = $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio");
+ $sth->execute();
+ my $i = 1;
+ while(my $biblios = $sth->fetchrow_hashref){
+ if(updateMARC($biblios->{'biblionumber'}, $biblios->{'frameworkcode'})){
+ print "$i records updated\n" unless ($i % 100);
+ $i++;
+ }
+ }
+}
+
+process();
\ No newline at end of file
--
1.6.0.4
More information about the Koha-patches
mailing list