Bugzilla – Attachment 29156 Details for
Bug 11399
batch rebuild items tables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 11399: batch Rebuild Items Tables
SIGNED-OFF-Bug-11399-batch-Rebuild-Items-Tables.patch (text/plain), 6.05 KB, created by
Bernardo Gonzalez Kriegel
on 2014-06-23 01:02:48 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 11399: batch Rebuild Items Tables
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2014-06-23 01:02:48 UTC
Size:
6.05 KB
patch
obsolete
>From 367ef782799938249ef3dfd20d015967e21a1f47 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?St=C3=A9phane=20Delaune?= <stephane.delaune@biblibre.com> >Date: Tue, 17 Dec 2013 12:46:39 +0100 >Subject: [PATCH] [SIGNED-OFF] Bug 11399: batch Rebuild Items Tables > >You can/must use it when you change items mapping. >this script rebuilds the non-MARC DB items table from the MARC values > >usage : batchRebuildItemsTables.pl [ -h ][ -c ][ -t ][ -where ] > >Options: > -h --help (or without arguments) shows this help message > -c Confirm: rebuild non marc DB (may be long) > -t test only, change nothing in DB > --where add where condition on default query > (eg. -where 'biblio.biblionumber<100') > >(copied test plan) >to test it : > >create a test item (eg on biblionumber 3) with a non mapped subfield with a test value. >check real items DB row ( SELECT * from items where biblionumber=3 ) => non mapped value is in more_subfields_xml >map the non mapped subfield with unused items column >re-check in Db that nothing changes >run ./batchRebuildItemsTables.pl -c --where 'biblio.biblionumber=3' >check real items DB row ( SELECT * from items where biblionumber=3 ) => new mapped value is not in more_subfields_xml anymore but in the mapped column > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Work as described, no koha-qa errors. >Add a new item to record, save with value in unmapped subfield ('x') >Change mapping, run script, value on newly mapped column >--- > misc/batchRebuildItemsTables.pl | 107 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 107 insertions(+) > create mode 100755 misc/batchRebuildItemsTables.pl > >diff --git a/misc/batchRebuildItemsTables.pl b/misc/batchRebuildItemsTables.pl >new file mode 100755 >index 0000000..e05e4d4 >--- /dev/null >+++ b/misc/batchRebuildItemsTables.pl >@@ -0,0 +1,107 @@ >+#!/usr/bin/perl >+use 5.10.0; >+use strict; >+use warnings; >+use Getopt::Long; >+use C4::Context; >+use C4::Biblio; >+use C4::Items; >+use MARC::Record; >+use MARC::Field; >+use Data::Dumper; >+use Time::HiRes qw(gettimeofday); >+use Pod::Usage; >+ >+=head1 NAME >+ >+batchRebuildBiblioTables.pl - rebuilds the non-MARC DB items table from the MARC values >+ >+You can/must use it when you change items mapping. >+ >+=head1 SYNOPSIS >+ >+batchRebuildItemsTables.pl [ -h ][ -c ][ -t ][ --where ] >+ >+ Options: >+ -h --help (or without arguments) shows this help message >+ -c Confirm: rebuild non marc DB (may be long) >+ -t test only, change nothing in DB >+ --where add where condition on default query (eg. --where 'biblio.biblionumber<100') >+ >+=cut >+ >+ >+my $count = 0; >+my $errorcount = 0; >+my $starttime = gettimeofday; >+my @errors; >+my %opt; >+my ($confirm, $help, $test_parameter, $where); >+GetOptions( >+ 'c' => \$confirm, >+ 'help|h' => \$help, >+ 't' => \$test_parameter, >+ 'where:s' => \$where, >+) or pod2usage(2); >+ >+pod2usage(1) if ($help || (!$confirm)); >+print "### Database will not be modified ###\n" if $test_parameter; >+#dbh >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+#sysprefs >+C4::Context->disable_syspref_cache() if ( defined( C4::Context->disable_syspref_cache() ) ); >+my $CataloguingLog = C4::Context->preference('CataloguingLog'); >+my $dontmerge = C4::Context->preference('dontmerge'); >+$dontmerge="0" unless defnonull($dontmerge); >+$dbh->do("UPDATE systempreferences SET value=0 WHERE variable='CataloguingLog'"); >+$dbh->do("UPDATE systempreferences SET value=1 where variable='dontmerge'"); >+$dbh->commit() unless $test_parameter; >+my ($itemfield,$itemnumbersubfield) = &GetMarcFromKohaField("items.itemnumber",''); >+#dbh query init >+my $query = qq{SELECT biblio.biblionumber AS biblionumber, biblioitems.biblioitemnumber AS biblioitemnumber, biblio.frameworkcode AS frameworkcode FROM biblio JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber}; >+$query.=qq{ WHERE $where } if ($where); >+ >+my $sth = $dbh->prepare($query); >+$sth->execute(); >+while ( my ( $biblionumber, $biblioitemnumber, $frameworkcode ) = $sth->fetchrow ) >+{ >+ $count++; >+ warn $count unless $count %1000; >+ my $extkey; >+ my $record = GetMarcBiblio($biblionumber,1); >+ unless ($record){ push @errors, "bad record biblionumber $biblionumber"; next; } >+ my ($tmptestfields,$tmptestdirectory,$reclen,$tmptestbaseaddress) = MARC::File::USMARC::_build_tag_directory($record); >+ if ($reclen > 99999) { push @errors, "bad record length for biblionumber $biblionumber (length : $reclen) "; next; } >+ #print "\n################################ record before ##################################\n".$record->as_formatted;#!test >+ unless ($test_parameter) { >+ my $rqitemnumber=$dbh->prepare("SELECT itemnumber, biblionumber from items where itemnumber = ? and biblionumber = ?"); >+ foreach my $itemfield ($record->field($itemfield)){ >+ my $marcitem=MARC::Record->new(); >+ $marcitem->encoding('UTF-8'); >+ $marcitem->append_fields($itemfield); >+ my $itemnum; my @itemnumbers = $itemfield->subfield($itemnumbersubfield); >+ foreach my $itemnumber ( @itemnumbers ){ >+ $rqitemnumber->execute($itemnumber, $biblionumber); >+ if( my $row = $rqitemnumber->fetchrow_hashref ){ $itemnum = $row->{itemnumber};} >+ } >+ eval{ if($itemnum){ ModItemFromMarc($marcitem,$biblionumber,$itemnum) }else{ die("$biblionumber"); } }; >+ if ($@){ warn "Problem with : $biblionumber : $@"; warn $record->as_formatted; } >+ } >+ } >+ unless ($test_parameter) { >+ $dbh->commit() unless $count %1000; >+ } >+} >+ >+$dbh->do("UPDATE systempreferences SET value=$CataloguingLog WHERE variable='CataloguingLog'"); >+$dbh->do("UPDATE systempreferences SET value=$dontmerge where variable='dontmerge'"); >+$dbh->commit() unless $test_parameter; >+my $timeneeded = time() - $starttime; >+print "$count MARC record done in $timeneeded seconds\n"; >+if (scalar(@errors) > 0) { >+ print "Some biblionumber could not be processed though: ", join(" ", @errors); >+} >+ >+sub defnonull { my $var = shift; defined $var and $var ne "" } >+__END__ >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11399
:
23575
|
23593
|
29156
|
31518
|
32511
|
32512