Bugzilla – Attachment 80322 Details for
Bug 20447
Add support for MARC holdings records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20447: Include basic summary holdings in the OAI-PMH responses.
Bug-20447-Include-basic-summary-holdings-in-the-OA.patch (text/plain), 7.12 KB, created by
Ere Maijala
on 2018-10-10 08:55:42 UTC
(
hide
)
Description:
Bug 20447: Include basic summary holdings in the OAI-PMH responses.
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2018-10-10 08:55:42 UTC
Size:
7.12 KB
patch
obsolete
>From 592dfff29c18a6e71d8687dbac746986d168922d Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Mon, 27 Aug 2018 15:07:12 +0300 >Subject: [PATCH] Bug 20447: Include basic summary holdings in the OAI-PMH > responses. > >https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20447 > >If include_items is set in oai conf, also basic location information from holdings records is included in the returned MARC records. >--- > C4/Biblio.pm | 6 ++++ > C4/Holdings.pm | 75 +++++++++++++++++++++++++++++++++++++++++++ > Koha/OAI/Server/ListBase.pm | 10 ++++-- > Koha/OAI/Server/Repository.pm | 1 + > 4 files changed, 90 insertions(+), 2 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 447ef96..fac6a56 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -2809,6 +2809,12 @@ sub EmbedItemsInMarcBiblio { > > $itemnumbers = [] unless defined $itemnumbers; > >+ if ( C4::Context->preference('SummaryHoldings') && !@$itemnumbers ) { >+ require C4::Holdings; >+ my $holdings_fields = C4::Holdings::GetMarcHoldingsFields( $biblionumber ); >+ $marc->append_fields(@$holdings_fields) if ( @$holdings_fields ); >+ } >+ > my $frameworkcode = GetFrameworkCode($biblionumber); > _strip_item_fields($marc, $frameworkcode); > >diff --git a/C4/Holdings.pm b/C4/Holdings.pm >index 8d5c73f..4e30b3d 100644 >--- a/C4/Holdings.pm >+++ b/C4/Holdings.pm >@@ -414,6 +414,35 @@ sub GetMarcHoldingsByBiblionumber { > return \@records; > } > >+=head2 GetMarcHoldingsFields >+ >+ my @marc_fields = GetMarcHoldingsFields($biblionumber); >+ >+Returns an array of MARC::Record objects of the holdings for the biblio. >+ >+=cut >+ >+sub GetMarcHoldingsFields { >+ my ( $biblionumber ) = @_; >+ # This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly. >+ my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' ); >+ $sth->execute( $biblionumber ); >+ my $holdings = $sth->fetchall_arrayref({}); >+ $sth->finish(); >+ my @holdings_fields; >+ my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' ); >+ ITEMLOOP: foreach my $holding (@$holdings) { >+ my $mungedholding = { >+ map { >+ defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : () >+ } keys %{ $holding } >+ }; >+ my $marc = TransformKohaHoldingToMarc($mungedholding); >+ push @holdings_fields, $marc->field( $holdingstag ); >+ } >+ return \@holdings_fields; >+} >+ > =head2 GetHoldingFrameworkCode > > $frameworkcode = GetFrameworkCode( $holding_id ) >@@ -772,6 +801,52 @@ sub TransformMarcHoldingToKohaOneField { > return $retval; > } > >+=head2 TransformKohaToMarc >+ >+ $record = TransformKohaToMarc( $hash [, $params ] ) >+ >+This function builds partial MARC::Record from holdings hash entries. >+This function is called when embedding holdings into a biblio record. >+ >+=cut >+ >+sub TransformKohaHoldingToMarc { >+ my ( $hash, $params ) = @_; >+ my $record = MARC::Record->new(); >+ SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); >+ >+ # In the next call we use the Default holdings framework, since it is considered >+ # authoritative for Koha to Marc mappings. >+ my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok >+ my $tag_hr = {}; >+ while ( my ($kohafield, $value) = each %$hash ) { >+ foreach my $fld ( @{ $mss->{$kohafield} } ) { >+ my $tagfield = $fld->{tagfield}; >+ my $tagsubfield = $fld->{tagsubfield}; >+ next if !$tagfield; >+ my @values = $params->{no_split} >+ ? ( $value ) >+ : split(/\s?\|\s?/, $value, -1); >+ foreach my $value ( @values ) { >+ next if $value eq ''; >+ $tag_hr->{$tagfield} //= []; >+ push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; >+ } >+ } >+ } >+ foreach my $tag (sort keys %$tag_hr) { >+ my @sfl = @{$tag_hr->{$tag}}; >+ @sfl = sort { $a->[0] cmp $b->[0]; } @sfl; >+ @sfl = map { @{$_}; } @sfl; >+ # Special care for control fields: remove the subfield indication @ >+ # and do not insert indicators. >+ my @ind = $tag < 10 ? () : ( " ", " " ); >+ @sfl = grep { $_ ne '@' } @sfl if $tag < 10; >+ $record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) ); >+ } >+ return $record; >+} >+ > 1; > > >diff --git a/Koha/OAI/Server/ListBase.pm b/Koha/OAI/Server/ListBase.pm >index 92af1c3..dbaa492 100644 >--- a/Koha/OAI/Server/ListBase.pm >+++ b/Koha/OAI/Server/ListBase.pm >@@ -69,8 +69,9 @@ sub GetRecords { > if ($include_items) { > $sql .= " > OR biblionumber IN (SELECT biblionumber from deleteditems WHERE timestamp >= ? AND timestamp <= ?) >+ OR biblionumber IN (SELECT biblionumber from holdings WHERE timestamp >= ? AND timestamp <= ?) > "; >- push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'}); >+ push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'}, $token->{'from_arg'}, $token->{'until_arg'}); > if (!$deleted) { > $sql .= " > OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ?) >@@ -106,6 +107,8 @@ sub GetRecords { > SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ? > UNION > SELECT timestamp FROM deleteditems WHERE biblionumber = ? >+ UNION >+ SELECT timestamp FROM holdings WHERE biblionumber = ? > ) bis > "; > } else { >@@ -117,6 +120,8 @@ sub GetRecords { > SELECT timestamp FROM deleteditems WHERE biblionumber = ? > UNION > SELECT timestamp FROM items WHERE biblionumber = ? >+ UNION >+ SELECT timestamp FROM holdings WHERE biblionumber = ? > ) bi > "; > } >@@ -139,7 +144,8 @@ sub GetRecords { > ); > last STAGELOOP; > } >- my @params = $deleted ? ( $biblionumber, $biblionumber ) : ( $biblionumber, $biblionumber, $biblionumber ); >+ my @params = $deleted ? ( $biblionumber, $biblionumber, $biblionumber ) >+ : ( $biblionumber, $biblionumber, $biblionumber, $biblionumber ); > $record_sth->execute( @params ) || die( 'Could not execute statement: ' . $sth->errstr ); > > my ($timestamp) = $record_sth->fetchrow; >diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm >index 30ace36..e95200d 100644 >--- a/Koha/OAI/Server/Repository.pm >+++ b/Koha/OAI/Server/Repository.pm >@@ -93,6 +93,7 @@ mode. A configuration file koha-oai.conf can look like that: > xsl_file: /usr/local/koha/koha-tmpl/intranet-tmpl/xslt/UNIMARCslim2OAIDC.xsl > > Note the 'include_items' parameter which is the only mean to return item-level info. >+If summary holdings are enabled, 'include_items' includes their location information too. > > =cut > >-- >2.7.4
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 20447
:
73703
|
73704
|
76485
|
76542
|
76670
|
76671
|
76672
|
76735
|
76736
|
78178
|
78179
|
78180
|
78738
|
78739
|
78740
|
78907
|
79403
|
79413
|
79565
|
79566
|
79567
|
79568
|
79569
|
79570
|
79812
|
79813
|
79814
|
79815
|
79816
|
79819
|
80320
|
80321
|
80322
|
80323
|
80324
|
80823
|
80824
|
80825
|
80826
|
80827
|
81264
|
81265
|
81266
|
81267
|
81268
|
82669
|
82670
|
82671
|
82672
|
82673
|
83550
|
83551
|
83552
|
83553
|
83554
|
83555
|
83556
|
83557
|
83558
|
83559
|
85364
|
85368
|
85369
|
85370
|
85371
|
85416
|
85417
|
85418
|
85419
|
85906
|
85907
|
85908
|
85909
|
85994
|
85995
|
85996
|
85997
|
86088
|
86089
|
86090
|
86091
|
87307
|
87308
|
87309
|
87310
|
87346
|
87347
|
87348
|
87349
|
88751
|
88752
|
88753
|
88754
|
88755
|
91743
|
91744
|
91745
|
91746
|
91747
|
94539
|
94540
|
94541
|
94542
|
97796
|
97797
|
97798
|
97799
|
97800
|
97843
|
97844
|
97845
|
97846
|
99143
|
99144
|
99145
|
99146
|
99176
|
99177
|
99178
|
99179
|
99235
|
99236
|
99237
|
99238
|
99239
|
105068
|
105069
|
105070
|
105071
|
105072
|
105259
|
105260
|
105261
|
105262
|
105263
|
106147
|
106148
|
106149
|
106150
|
106151
|
108250
|
108251
|
108252
|
108253
|
108254
|
108255
|
108336
|
108337
|
108338
|
108339
|
108340
|
108341
|
108789
|
108790
|
108791
|
108792
|
108793
|
108794
|
109695
|
109696
|
109697
|
109698
|
109699
|
109700
|
109703
|
109704
|
109705
|
109706
|
109707
|
109708
|
109711
|
109712
|
109713
|
109714
|
109715
|
109717
|
109718
|
109719
|
109720
|
109721
|
109722
|
109741
|
109742
|
109743
|
109744
|
109745
|
109746
|
109765
|
109766
|
109767
|
109768
|
109769
|
109770
|
109873
|
109874
|
109875
|
109877
|
109878
|
109879
|
110115
|
110174
|
110313
|
110314
|
110315
|
110316
|
110317
|
110318
|
110319
|
110320
|
110467
|
110468
|
110469
|
110471
|
110472
|
110473
|
110474
|
110475
|
112176
|
112177
|
112179
|
112180
|
112181
|
112182
|
112189
|
112190
|
112191
|
112192
|
112193
|
112194
|
112570
|
112571
|
112572
|
112573
|
112574
|
112575
|
113943
|
113944
|
113945
|
113946
|
113947
|
113948
|
113952
|
113953
|
113954
|
113955
|
113956
|
113957
|
113958
|
113959
|
115239
|
115240
|
115241
|
115242
|
115243
|
115244
|
115245
|
115654
|
115655
|
115656
|
115657
|
115658
|
115659
|
115660
|
115722
|
115723
|
115724
|
115725
|
115726
|
115727
|
115728
|
115729
|
116797
|
116798
|
116799
|
116800
|
116801
|
116802
|
116803
|
116804
|
116805
|
116806
|
116807
|
116808
|
116809
|
116810
|
116811
|
116812
|
118382
|
118383
|
118385
|
118386
|
118387
|
118388
|
118389
|
118390
|
118397
|
118398
|
118399
|
118400
|
118401
|
118402
|
118403
|
118404
|
118405
|
118406
|
118407
|
118408
|
118409
|
118410
|
118411
|
118412
|
118429
|
118430
|
118431
|
118432
|
118433
|
118434
|
118435
|
118436
|
118527
|
118528
|
118529
|
118530
|
118531
|
118532
|
118533
|
118534
|
118535
|
118536
|
119265
|
119266
|
119267
|
119268
|
119269
|
119270
|
119271
|
119272
|
119273
|
119274
|
119514
|
119515
|
119516
|
119517
|
119518
|
119519
|
119520
|
119521
|
119522
|
119523
|
119570
|
119571
|
121216
|
121217
|
121220
|
121221
|
121222
|
121223
|
121226
|
121227
|
121228
|
121229
|
121230
|
121231
|
121379
|
121380
|
121381
|
121382
|
121383
|
121406
|
121407
|
121408
|
121409
|
121410
|
122501
|
122502
|
122503
|
122504
|
122505
|
122851
|
122852
|
122853
|
122854
|
122855
|
122856
|
122891
|
122892
|
122893
|
122894
|
122895
|
122896
|
122897
|
123047
|
123048
|
123049
|
123050
|
123051
|
123052
|
123053
|
123054
|
123055
|
123056
|
123057
|
123058
|
123059
|
123060
|
123061
|
124012
|
124013
|
124014
|
124015
|
124016
|
124017
|
124018
|
124944
|
124945
|
124946
|
124947
|
124948
|
124949
|
124950
|
126204
|
126205
|
126206
|
126207
|
126208
|
126209
|
126210
|
126211
|
126212
|
126296
|
126391
|
126392
|
126394
|
126395
|
126396
|
126397
|
126398
|
126399
|
126400
|
126401
|
126402
|
126403
|
126404
|
126405
|
126932
|
126933
|
126934
|
126935
|
126936
|
126937
|
126938
|
126939
|
126940
|
126941
|
126942
|
126943
|
127040
|
128079
|
128131
|
128134
|
130776
|
130777
|
130778
|
130779
|
130780
|
130781
|
130782
|
130783
|
130784
|
130785
|
130786
|
130787
|
130788
|
130789
|
130790
|
130791
|
130792
|
130793
|
130794
|
130795
|
130796
|
130797
|
130798
|
130799
|
130800
|
130801
|
130802
|
130803
|
130804
|
130805
|
130806
|
130807
|
131458
|
131459
|
131460
|
131461
|
131462
|
131463
|
131464
|
131465
|
131466
|
131467
|
131468
|
131469
|
131470
|
131471
|
131472
|
131473
|
131474
|
131475
|
131476
|
131477
|
131478
|
131479
|
131480
|
131481
|
131482
|
139865
|
139866
|
139867
|
139868
|
139869
|
139870
|
139871
|
139872
|
139873
|
139874
|
139875
|
139876
|
139877
|
139878
|
139879
|
139880
|
139881
|
139882
|
139883
|
139884
|
139885
|
139886
|
139887
|
139888
|
139889
|
139890
|
139891
|
139892
|
139893
|
139894
|
139895
|
139896
|
157492
|
157493