koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/misc bulkupdate.pl


From: Antoine Farnault
Subject: [Koha-cvs] koha/misc bulkupdate.pl
Date: Mon, 18 Jun 2007 13:29:38 +0000

CVSROOT:        /sources/koha
Module name:    koha
Changes by:     Antoine Farnault <toins>        07/06/18 13:29:38

Added files:
        misc           : bulkupdate.pl 

Log message:
        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.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/bulkupdate.pl?cvsroot=koha&rev=1.1

Patches:
Index: bulkupdate.pl
===================================================================
RCS file: bulkupdate.pl
diff -N bulkupdate.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ bulkupdate.pl       18 Jun 2007 13:29:38 -0000      1.1
@@ -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: bulkupdate.pl,v 1.1 2007/06/18 13:29:38 toins Exp $
+
+
+=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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]