Bugzilla – Attachment 87250 Details for
Bug 11529
Add subtitle, medium and part fields to biblio table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11529: Simplify and optimize batchRebuildBiblioTables.pl
Bug-11529-Simplify-and-optimize-batchRebuildBiblio.patch (text/plain), 5.01 KB, created by
Ere Maijala
on 2019-04-01 08:18:02 UTC
(
hide
)
Description:
Bug 11529: Simplify and optimize batchRebuildBiblioTables.pl
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2019-04-01 08:18:02 UTC
Size:
5.01 KB
patch
obsolete
>From ec133ec690ca6d4ffdab8000fff5b05f43be3c53 Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Thu, 8 Nov 2018 15:30:12 +0200 >Subject: [PATCH] Bug 11529: Simplify and optimize batchRebuildBiblioTables.pl > >--- > misc/batchRebuildBiblioTables.pl | 94 +++++++++++++------------------- > 1 file changed, 37 insertions(+), 57 deletions(-) > >diff --git a/misc/batchRebuildBiblioTables.pl b/misc/batchRebuildBiblioTables.pl >index 5db801bbc1..e81384eaaf 100755 >--- a/misc/batchRebuildBiblioTables.pl >+++ b/misc/batchRebuildBiblioTables.pl >@@ -14,90 +14,70 @@ BEGIN { > > # Koha modules used > use MARC::Record; >+use C4::Charset; > 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); >+ >+my ($version, $confirm); > GetOptions( > 'c' => \$confirm, >- 'h' => \$version, >- 't' => \$test_parameter, >+ 'h' => \$version > ); > > if ($version || (!$confirm)) { > print <<EOF >-This script rebuilds the non-MARC DB from the MARC values. >+This script rebuilds the non-MARC fields from the MARC values. > You can/must use it when you change your mapping. > > 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 ! >+Run this script or you will have strange results in the UI! > > Syntax: >-\t./batchRebuildBiblioTables.pl -h (or without arguments => shows this screen) >-\t./batchRebuildBiblioTables.pl -c (c like confirm => rebuild non marc DB (may be long) >-\t-t => test only, change nothing in DB >+\t./batchRebuildBiblioTables.pl -h (or without arguments => show this screen) >+\t./batchRebuildBiblioTables.pl -c (c like confirm => rebuild non-MARC fields (may take long) > EOF > ; > exit; > } > >+$|=1; # non-buffered output >+ > my $dbh = C4::Context->dbh; > my $i=0; >-my $starttime = time(); >- >-$|=1; # flushes output >-$starttime = gettimeofday; >+my $starttime = gettimeofday; >+my $marcflavour = C4::Context->preference('marcflavour'); >+my $sth = $dbh->prepare('SELECT biblionumber, frameworkcode FROM biblio'); >+$sth->execute(); > >-#1st of all, find item MARC tag. >-my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("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"); >-my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); >-$sth->execute; >-# my ($biblionumbermax) = $sth->fetchrow; >-# warn "$biblionumbermax <<=="; > my @errors; >-while (my ($biblionumber)= $sth->fetchrow) { >- #now, parse the record, extract the item fields, and store them in somewhere else. >- my $record = GetMarcBiblio({ biblionumber => $biblionumber }); >- if (not defined $record) { >- push @errors, $biblionumber; >- next; >+while (my ($biblionumber, $frameworkcode) = $sth->fetchrow) { >+ my $marcxml = GetXmlBiblio($biblionumber); >+ if (not defined $marcxml) { >+ push @errors, $biblionumber; >+ next; > } >- my @fields = $record->field($tagfield); >- my @items; >- my $nbitems=0; >- print "."; >- my $timeneeded = gettimeofday - $starttime; >- print "$i in $timeneeded s\n" unless ($i % 50); >- $i++; >- foreach my $field (@fields) { >- my $item = MARC::Record->new(); >- $item->append_fields($field); >- push @items,$item; >- $record->delete_field($field); >- $nbitems++; >+ >+ $marcxml = C4::Charset::StripNonXmlChars( $marcxml ); >+ my $record = eval { >+ MARC::Record::new_from_xml($marcxml, 'utf8', $marcflavour); >+ }; >+ if ($@) { >+ push @errors, $biblionumber; >+ next; > } >-# print "$biblionumber\n"; >- my $frameworkcode = GetFrameworkCode($biblionumber); >- localNEWmodbiblio($dbh,$record,$biblionumber,$frameworkcode) unless $test_parameter; >-} >-# $dbh->do("unlock tables"); >-my $timeneeded = time() - $starttime; >-print "$i MARC record done in $timeneeded seconds\n"; >-if (scalar(@errors) > 0) { >- print "Some biblionumber could not be processed though: ", join(" ", @errors); >+ >+ my $biblio = TransformMarcToKoha($record); >+ C4::Biblio::_koha_modify_biblio($dbh, $biblio, $frameworkcode); >+ C4::Biblio::_koha_modify_biblioitem_nonmarc($dbh, $biblio); >+ >+ $i++; >+ printf("%lu records processed in %.2f seconds\n", $i, gettimeofday() - $starttime) unless ($i % 100); > } > >-# modified NEWmodbiblio to jump the MARC part of the biblio modif >-# highly faster >-sub localNEWmodbiblio { >- my ($dbh,$record,$biblionumber,$frameworkcode) =@_; >- $frameworkcode="" unless $frameworkcode; >- my $oldbiblio = TransformMarcToKoha($record,$frameworkcode); >- C4::Biblio::_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); >- C4::Biblio::_koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio ); >- return 1; >+printf("\n%lu records processed in %.2f seconds\n", $i, gettimeofday() - $starttime); >+if (scalar(@errors) > 0) { >+ print "Some records could not be processed though: ", join(' ', @errors); > } >-- >2.17.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 11529
:
81930
|
81931
|
82024
|
82025
|
82026
|
82027
|
82028
|
82029
|
82088
|
82089
|
82090
|
82428
|
82429
|
82430
|
82431
|
82538
|
82539
|
82540
|
82541
|
82542
|
83103
|
83104
|
83105
|
83106
|
83107
|
83108
|
83961
|
83962
|
83963
|
83964
|
83965
|
83966
|
85587
|
85588
|
85589
|
85590
|
85591
|
85592
|
86677
|
86678
|
86679
|
86680
|
86681
|
86682
|
87248
|
87249
|
87250
|
87251
|
87252
|
87253
|
87256
|
87257
|
87258
|
87259
|
87260
|
87261
|
87911
|
87912
|
87913
|
87914
|
87915
|
87916
|
87917
|
87918
|
87919
|
88247
|
88248
|
88249
|
88250
|
88251
|
88252
|
88253
|
88254
|
88255
|
88256
|
88406
|
88407
|
88408
|
88409
|
88410
|
88411
|
88412
|
88413
|
88414
|
88415
|
88416
|
88433
|
88434
|
88435
|
88436
|
88437
|
88438
|
88439
|
88440
|
88441
|
88442
|
88443
|
88762
|
88763
|
88764
|
88765
|
88766
|
88767
|
88768
|
88769
|
88770
|
88771
|
88772
|
88851
|
88852
|
88853
|
88854
|
88855
|
88856
|
88857
|
88858
|
88859
|
88860
|
88861
|
88862
|
89096
|
89097
|
89098
|
89099
|
89100
|
89101
|
89102
|
89103
|
89104
|
89105
|
89106
|
89107
|
89234
|
89235
|
89236
|
89237
|
89238
|
89239
|
89240
|
89241
|
89242
|
89243
|
89244
|
89245
|
89246
|
91680
|
91681
|
91682
|
91683
|
91684
|
91685
|
91686
|
91687
|
91688
|
91689
|
91690
|
91691
|
91692
|
91824
|
91825
|
91826
|
91827
|
91828
|
91829
|
91830
|
91831
|
91832
|
91833
|
91834
|
91835
|
91836
|
91837
|
92016
|
92019
|
92020
|
105667
|
105672