From 0d96be2e2905a4c3430f3dd7140d399eb73b1b6d Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 14 Oct 2003 09:45:29 +0000 Subject: [PATCH] adding rebuildnonmarc.pl script : run this script when you change a link between marc and non MARC DB. It rebuilds the non-MARC DB (long operation) --- C4/Biblio.pm | 9 ++- .../default/en/parameters/koha2marclinks.tmpl | 3 +- .../en/parameters/marctagstructure.tmpl | 2 +- .../default/fr/parameters/koha2marclinks.tmpl | 3 +- .../fr/parameters/marctagstructure.tmpl | 2 +- misc/rebuildnonmarc.pl | 75 +++++++++++++++++++ 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100755 misc/rebuildnonmarc.pl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 1cb5ae7eb3..28dd036854 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1,6 +1,9 @@ package C4::Biblio; # $Id$ # $Log$ +# Revision 1.65 2003/10/14 09:45:29 tipaul +# adding rebuildnonmarc.pl script : run this script when you change a link between marc and non MARC DB. It rebuilds the non-MARC DB (long operation) +# # Revision 1.64 2003/10/06 15:20:51 tipaul # fix for 536 (subtitle error) # @@ -1590,8 +1593,10 @@ size = $biblioitem->{'size'}, place = $biblioitem->{'place'} where biblioitemnumber = $biblioitem->{'biblioitemnumber'}"; - $dbh->do($query); - +$dbh->do($query); +if ($dbh->errstr) { + warn "$query"; +} # $dbh->disconnect; } # sub modbibitem diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/koha2marclinks.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/koha2marclinks.tmpl index ee297723e2..ba7a10138a 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/koha2marclinks.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/koha2marclinks.tmpl @@ -155,7 +155,8 @@ MARC links -

+

NOTE : if you change the link between a MARC subfield and a non-MARC field, ask your administrator to run misc/rebuildnonmarc.pl script. +

diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/marctagstructure.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/marctagstructure.tmpl index bc84a765d0..4f2532e500 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/marctagstructure.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/marctagstructure.tmpl @@ -93,6 +93,7 @@

MARC tag structure admin

+NOTE : if you change the link between a MARC subfield and a non-MARC field, ask your administrator to run misc/rebuildnonmarc.pl script.
@@ -136,5 +137,4 @@
- diff --git a/koha-tmpl/intranet-tmpl/default/fr/parameters/koha2marclinks.tmpl b/koha-tmpl/intranet-tmpl/default/fr/parameters/koha2marclinks.tmpl index 9661e11b9c..f6b7bbb765 100644 --- a/koha-tmpl/intranet-tmpl/default/fr/parameters/koha2marclinks.tmpl +++ b/koha-tmpl/intranet-tmpl/default/fr/parameters/koha2marclinks.tmpl @@ -155,7 +155,8 @@ Liens MARC -

+

NOTE : si vous modifiez un lien entre un sous champ MARC et une zone non-MARC, demandez à votre administrateur d'exécuter le script misc/rebuildnonmarc.pl +

diff --git a/koha-tmpl/intranet-tmpl/default/fr/parameters/marctagstructure.tmpl b/koha-tmpl/intranet-tmpl/default/fr/parameters/marctagstructure.tmpl index 597e9d364f..fdf8b2b224 100644 --- a/koha-tmpl/intranet-tmpl/default/fr/parameters/marctagstructure.tmpl +++ b/koha-tmpl/intranet-tmpl/default/fr/parameters/marctagstructure.tmpl @@ -109,6 +109,7 @@ Gestion de la structure de balisage MARC +

NOTE : si vous modifiez un lien entre un sous champ MARC et une zone non-MARC, demandez à votre administrateur d'exécuter le script misc/rebuildnonmarc.pl

@@ -158,6 +159,5 @@
- diff --git a/misc/rebuildnonmarc.pl b/misc/rebuildnonmarc.pl new file mode 100755 index 0000000000..aac4d1af93 --- /dev/null +++ b/misc/rebuildnonmarc.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl +# small script that rebuilds the non-MARC DB + +use strict; + +# Koha modules used +# use MARC::File::USMARC; +use MARC::Record; +use MARC::Batch; +use C4::Context; +use C4::Biblio; +use Time::HiRes qw(gettimeofday); + +use Getopt::Long; +my ( $input_marc_file, $number) = ('',0); +my ($version, $confirm,$test_parameter); +GetOptions( + 'c' => \$confirm, + 'h' => \$version, + 't' => \$test_parameter, +); + +if ($version || (!$confirm)) { + print < shows this screen) +\t./rebuildnonmarc.pl -c (c like confirm => rebuild non marc DB (may be long) +\t-t => test only, change nothing in DB +EOF +; +die; +} + +my $dbh = C4::Context->dbh; +my $i=0; +my $starttime = gettimeofday; +#1st of all, find item MARC tag. +my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber"); +# $dbh->do("lock tables biblio write, biblioitems write, items write, marc_biblio write, marc_subfield_table write, marc_blob_subfield write, marc_word write, marc_subfield_structure write, stopwords write"); +my $sth = $dbh->prepare("select bibid from marc_biblio"); +$sth->execute; +# my ($bibidmax) = $sth->fetchrow; +# warn "$bibidmax <<=="; +while (my ($bibid)= $sth->fetchrow) { + #now, parse the record, extract the item fields, and store them in somewhere else. + my $record = MARCgetbiblio($dbh,$bibid); + my @fields = $record->field($tagfield); + my @items; + my $nbitems=0; + $i++; + foreach my $field (@fields) { + my $item = MARC::Record->new(); + $item->append_fields($field); + push @items,$item; + $record->delete_field($field); + $nbitems++; + } + print "$bibid\n"; + # now, create biblio and items with NEWnewXX call. + NEWmodbiblio($dbh,$record,$bibid) unless $test_parameter; +# print "biblio done\n"; + for (my $i=0;$i<=$#items;$i++) { + my $tmp = MARCmarc2koha($dbh,$items[$i]) unless $test_parameter; # finds the itemnumber +# warn "==> ".$items[$i]->as_formatted; + NEWmoditem($dbh,$items[$i],$bibid,$tmp->{itemnumber}) unless $test_parameter; +# print "1 item done\n"; + } +} +# $dbh->do("unlock tables"); +my $timeneeded = gettimeofday - $starttime; +print "$i MARC record done in $timeneeded seconds\n"; -- 2.20.1