adding rebuildnonmarc.pl script : run this script when you change a link between...
authortipaul <tipaul>
Tue, 14 Oct 2003 09:45:29 +0000 (09:45 +0000)
committertipaul <tipaul>
Tue, 14 Oct 2003 09:45:29 +0000 (09:45 +0000)
C4/Biblio.pm
koha-tmpl/intranet-tmpl/default/en/parameters/koha2marclinks.tmpl
koha-tmpl/intranet-tmpl/default/en/parameters/marctagstructure.tmpl
koha-tmpl/intranet-tmpl/default/fr/parameters/koha2marclinks.tmpl
koha-tmpl/intranet-tmpl/default/fr/parameters/marctagstructure.tmpl
misc/rebuildnonmarc.pl [new file with mode: 0755]

index 1cb5ae7..28dd036 100644 (file)
@@ -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
 
index ee29772..ba7a101 100644 (file)
 <!-------------------------------------------------------------------------------------------------->
 <TMPL_IF name="else">
 <font SIZE=6><em>MARC links<TMPL_VAR name="tagfield"></em></font>
-<p></p>
+<p><b>NOTE : if you change the link between a MARC subfield and a non-MARC field, ask your administrator to run misc/rebuildnonmarc.pl script.</b>
+</p>
 <form action='<TMPL_VAR name="script_name">' method=post>
 <TMPL_VAR name="tablename"> <input type="submit" value="OK">
 </form>
index bc84a76..4f2532e 100644 (file)
@@ -93,6 +93,7 @@
 <!-------------------------------------------------------------------------------------------------->
 <TMPL_IF name="else">
 <h1>MARC tag structure admin</h1>
+<b>NOTE : if you change the link between a MARC subfield and a non-MARC field, ask your administrator to run misc/rebuildnonmarc.pl script.</b>
 <form action='<TMPL_VAR name="script_name">' method=post>
        <input type=text name=searchfield value="">
        <input type=reset name=reset value="clr">
 </table>
 </form>
 </TMPL_IF>
-
 <TMPL_INCLUDE NAME="parameters-bottom.inc">
index 9661e11..f6b7bbb 100644 (file)
 <!-------------------------------------------------------------------------------------------------->
 <TMPL_IF name="else">
 <font SIZE=6><em>Liens MARC<TMPL_VAR name="tagfield"></em></font>
-<p></p>
+<p><b>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</b>
+</p>
 <form action='<TMPL_VAR name="script_name">' method=post>
 <TMPL_VAR name="tablename"> <input type="submit" value="OK">
 </form>
index 597e9d3..fdf8b2b 100644 (file)
 <!-------------------------------------------------------------------------------------------------->
 <TMPL_IF name="else">
 <font SIZE=6><em>Gestion de la structure de balisage MARC</em></font>
+<p><b>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</b></p>
 <form action='<TMPL_VAR name="script_name">' method=post>
        <input type=text name=searchfield value="">
        <input type=reset name=reset value="clr">
 </table>
 </form>
 </TMPL_IF>
-
 <TMPL_INCLUDE NAME="parameters-bottom.inc">
 </table>
diff --git a/misc/rebuildnonmarc.pl b/misc/rebuildnonmarc.pl
new file mode 100755 (executable)
index 0000000..aac4d1a
--- /dev/null
@@ -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 <<EOF
+This script rebuilds the non-MARC DB from the MARC values.
+You can/must use it when you change your mapping.
+For example : you decide to map biblio.title to 200$a (it was previously mapped to 610$a) : run this script or you will have strange
+results in OPAC !
+syntax :
+\t./rebuildnonmarc.pl -h (or without arguments => 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";