Bugzilla – Attachment 171191 Details for
Bug 37380
Move GetMarcControlnumber to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37380: Replace uses of GetMarcControlnumber for get_control_number()
Bug-37380-Replace-uses-of-GetMarcControlnumber-for.patch (text/plain), 13.19 KB, created by
Jonathan Druart
on 2024-09-09 11:48:44 UTC
(
hide
)
Description:
Bug 37380: Replace uses of GetMarcControlnumber for get_control_number()
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-09-09 11:48:44 UTC
Size:
13.19 KB
patch
obsolete
>From 79b166b18bf5a2452078295b6ade4bf11d1181d1 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 16 Jul 2024 15:42:10 -0300 >Subject: [PATCH] Bug 37380: Replace uses of GetMarcControlnumber for > get_control_number() > >Signed-off-by: Sam Lau <samalau@gmail.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > C4/Biblio.pm | 27 --------------------------- > catalogue/export.pl | 12 ++++++------ > opac/opac-ISBDdetail.pl | 7 ++++--- > opac/opac-MARCdetail.pl | 17 +++++++++-------- > opac/opac-detail.pl | 11 ++++++----- > opac/opac-export.pl | 12 ++++++------ > t/Biblio.t | 10 ++-------- > t/db_dependent/Biblio.t | 21 +++------------------ > 8 files changed, 36 insertions(+), 81 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 063a07a7655..2ab15c5aa0f 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -30,7 +30,6 @@ BEGIN { > AddBiblio > GetBiblioData > GetISBDView >- GetMarcControlnumber > GetMarcISBN > GetMarcISSN > GetMarcSubjects >@@ -1528,32 +1527,6 @@ sub GetAuthorisedValueDesc { > } > } > >-=head2 GetMarcControlnumber >- >- $marccontrolnumber = GetMarcControlnumber($record,$marcflavour); >- >-Get the control number / record Identifier from the MARC record and return it. >- >-=cut >- >-sub GetMarcControlnumber { >- my ( $record, $marcflavour ) = @_; >- if (!$record) { >- carp 'GetMarcControlnumber called on undefined record'; >- return; >- } >- my $controlnumber = ""; >- # Control number or Record identifier are the same field in MARC21 and UNIMARC >- # Keep $marcflavour for possible later use >- if ($marcflavour eq "MARC21" || $marcflavour eq "UNIMARC" ) { >- my $controlnumberField = $record->field('001'); >- if ($controlnumberField) { >- $controlnumber = $controlnumberField->data(); >- } >- } >- return $controlnumber; >-} >- > =head2 GetMarcISBN > > $marcisbnsarray = GetMarcISBN( $record, $marcflavour ); >diff --git a/catalogue/export.pl b/catalogue/export.pl >index ff02cea67f0..eb54b3683ba 100755 >--- a/catalogue/export.pl >+++ b/catalogue/export.pl >@@ -4,7 +4,6 @@ use Modern::Perl; > use C4::Record; > use C4::Auth qw( get_template_and_user ); > use C4::Output; >-use C4::Biblio qw( GetMarcControlnumber ); > use CGI qw ( -utf8 ); > use C4::Ris qw( marc2ris ); > >@@ -30,11 +29,12 @@ if ($op eq "export") { > my $biblio = Koha::Biblios->find($biblionumber); > my $marc = $biblio->metadata->record({ embed_items => 1 }); > >- if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ >- my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour >- my $control_num = GetMarcControlnumber( $marc, $marcflavour ); >- if( $control_num ){ >- $file_id = $control_num; >+ my $metadata_extractor = $biblio->metadata_extractor; >+ >+ if ( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ) { >+ my $control_num = $metadata_extractor->get_control_number(); >+ if ($control_num) { >+ $file_id = $control_num; > $file_pre = "record-"; > } > } >diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl >index a70d2ccf765..1b863efeb30 100755 >--- a/opac/opac-ISBDdetail.pl >+++ b/opac/opac-ISBDdetail.pl >@@ -48,7 +48,6 @@ use CGI qw ( -utf8 ); > use C4::Biblio qw( > CountItemsIssued > GetISBDView >- GetMarcControlnumber > GetMarcISSN > TransformMarcToKoha > ); >@@ -102,6 +101,8 @@ unless ( $patron and $patron->category->override_hidden_items ) { > my $record = $biblio->metadata->record; > my @items = $biblio->items->filter_by_visible_in_opac({ patron => $patron })->as_list; > >+my $metadata_extractor = $biblio->metadata_extractor; >+ > my $record_processor = Koha::RecordProcessor->new( > { filters => [ 'EmbedItems', 'ViewPolicy' ], > options => { >@@ -195,7 +196,7 @@ $template->param( > ); > > #Search for title in links >-my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); >+my $control_number = $metadata_extractor->get_control_number(); > my $marcissns = GetMarcISSN ( $record, $marcflavour ); > my $issn = $marcissns->[0] || ''; > >@@ -210,7 +211,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > AUTHOR => $dat->{author}, > ISBN => $isbn, > ISSN => $issn, >- CONTROLNUMBER => $marccontrolnumber, >+ CONTROLNUMBER => $control_number, > BIBLIONUMBER => $biblionumber, > OCLC_NO => $oclc_no, > } >diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl >index 406d2d4ceb1..34ddd838778 100755 >--- a/opac/opac-MARCdetail.pl >+++ b/opac/opac-MARCdetail.pl >@@ -52,7 +52,6 @@ use CGI qw ( -utf8 ); > use C4::Biblio qw( > CountItemsIssued > GetAuthorisedValueDesc >- GetMarcControlnumber > GetMarcFromKohaField > GetMarcISSN > GetMarcStructure >@@ -108,6 +107,8 @@ unless ( $patron and $patron->category->override_hidden_items ) { > } > } > >+my $metadata_extractor = $biblio->metadata_extractor; >+ > my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron }); > my $framework = $biblio ? $biblio->frameworkcode : q{}; > my $tagslib = &GetMarcStructure( 0, $framework ); >@@ -339,12 +340,12 @@ if ( C4::Context->preference("OPACISBD") ) { > } > > #Search for title in links >-my $marcflavour = C4::Context->preference("marcflavour"); >-my $dat = TransformMarcToKoha({ record => $record }); >-my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); >-my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); >-my $marcissns = GetMarcISSN( $record, $marcflavour ); >-my $issn = $marcissns->[0] || ''; >+my $marcflavour = C4::Context->preference("marcflavour"); >+my $dat = TransformMarcToKoha( { record => $record } ); >+my $isbn = GetNormalizedISBN( undef, $record, $marcflavour ); >+my $control_number = $metadata_extractor->get_control_number(); >+my $marcissns = GetMarcISSN( $record, $marcflavour ); >+my $issn = $marcissns->[0] || ''; > > if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > $dat->{title} =~ s/\/+$//; # remove trailing slash >@@ -357,7 +358,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > AUTHOR => $dat->{author}, > ISBN => $isbn, > ISSN => $issn, >- CONTROLNUMBER => $marccontrolnumber, >+ CONTROLNUMBER => $control_number, > BIBLIONUMBER => $biblionumber, > OCLC_NO => $oclc_no, > } >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 59a7d5ec57f..e9f188da2ba 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -38,7 +38,6 @@ use C4::Output qw( parametrized_url output_html_with_http_headers ); > use C4::Biblio qw( > CountItemsIssued > GetBiblioData >- GetMarcControlnumber > GetMarcISBN > GetMarcISSN > GetMarcSeries >@@ -112,6 +111,8 @@ unless ( $biblio && $record ) { > exit; > } > >+my $metadata_extractor = $biblio->metadata_extractor; >+ > my $items = $biblio->items->search_ordered; > if ($specific_item) { > $items = $items->search( { itemnumber => scalar $query->param('itemnumber') } ); >@@ -1166,9 +1167,9 @@ if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { > } > > #Search for title in links >-my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); >-my $marcissns = GetMarcISSN ( $record, $marcflavour ); >-my $issn = $marcissns->[0] || ''; >+my $control_number = $metadata_extractor->get_control_number(); >+my $marcissns = GetMarcISSN( $record, $marcflavour ); >+my $issn = $marcissns->[0] || ''; > > if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > $dat->{title} =~ s/\/+$//; # remove trailing slash >@@ -1181,7 +1182,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > AUTHOR => $dat->{author}, > ISBN => $isbn, > ISSN => $issn, >- CONTROLNUMBER => $marccontrolnumber, >+ CONTROLNUMBER => $control_number, > BIBLIONUMBER => $biblionumber, > OCLC_NO => $oclc_no, > } >diff --git a/opac/opac-export.pl b/opac/opac-export.pl >index a39c8046953..f5c363fc20b 100755 >--- a/opac/opac-export.pl >+++ b/opac/opac-export.pl >@@ -25,7 +25,6 @@ use C4::Output; > use C4::Biblio qw( > GetFrameworkCode > GetISBDView >- GetMarcControlnumber > ); > use CGI qw ( -utf8 ); > use C4::Auth; >@@ -85,13 +84,14 @@ if(!$marc) { > exit; > } > >+my $metadata_extractor = $biblio->metadata_extractor; >+ > my $file_id = $biblionumber; > my $file_pre = "bib-"; >-if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ >- my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour >- my $control_num = GetMarcControlnumber( $marc, $marcflavour ); >- if( $control_num ){ >- $file_id = $control_num; >+if ( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ) { >+ my $control_number = $metadata_extractor->get_control_number(); >+ if ($control_number) { >+ $file_id = $control_number; > $file_pre = "record-"; > } > } >diff --git a/t/Biblio.t b/t/Biblio.t >index c298349e18f..3fbf90402a1 100755 >--- a/t/Biblio.t >+++ b/t/Biblio.t >@@ -21,10 +21,10 @@ use Test::More; > use Test::MockModule; > use Test::Warn; > >-plan tests => 34; >+plan tests => 32; > > >-use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues )); >+use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues )); > > my $db = Test::MockModule->new('Koha::Database'); > $db->mock( _new_schema => sub { return Schema(); } ); >@@ -70,12 +70,6 @@ warning_is { $ret = GetMarcQuantity(undef, 'MARC21') } > > ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec'); > >-warning_is { $ret = GetMarcControlnumber() } >- { carped => 'GetMarcControlnumber called on undefined record'}, >- "GetMarcControlnumber returns carped warning on undef record"; >- >-ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec'); >- > warning_is { $ret = GetMarcISBN() } > { carped => 'GetMarcISBN called on undefined record'}, > "GetMarcISBN returns carped warning on undef record"; >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index ef8eb0ca545..9f470409d2e 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -34,7 +34,7 @@ use Koha::MarcSubfieldStructures; > use C4::Linker::Default qw( get_link ); > > BEGIN { >- use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData ModBiblio GetMarcISSN GetMarcControlnumber GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio )); >+ use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData ModBiblio GetMarcISSN GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio )); > } > > my $schema = Koha::Database->new->schema; >@@ -417,21 +417,6 @@ sub run_tests { > is( scalar @$issns, 4, > 'GetMARCISSN skips empty ISSN fields (Bug 12674)'); > >- ## Testing GetMarcControlnumber >- my $controlnumber; >- $controlnumber = GetMarcControlnumber( $marc_record, $marcflavour ); >- is( $controlnumber, '', 'GetMarcControlnumber handles records without 001' ); >- >- $field = MARC::Field->new( '001', '' ); >- $marc_record->append_fields($field); >- $controlnumber = GetMarcControlnumber( $marc_record, $marcflavour ); >- is( $controlnumber, '', 'GetMarcControlnumber handles records with empty 001' ); >- >- $field = $marc_record->field('001'); >- $field->update('123456789X'); >- $controlnumber = GetMarcControlnumber( $marc_record, $marcflavour ); >- is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' ); >- > ## Testing GetMarcISBN > my $record_for_isbn = MARC::Record->new(); > my $isbns = GetMarcISBN( $record_for_isbn, $marcflavour ); >@@ -632,14 +617,14 @@ sub create_author_field { > } > > subtest 'MARC21' => sub { >- plan tests => 46; >+ plan tests => 43; > run_tests('MARC21'); > $schema->storage->txn_rollback; > $schema->storage->txn_begin; > }; > > subtest 'UNIMARC' => sub { >- plan tests => 46; >+ plan tests => 43; > > # Mock the auth type data for UNIMARC > $dbh->do("UPDATE auth_types SET auth_tag_to_report = '106' WHERE auth_tag_to_report = '100'") or die $dbh->errstr; >-- >2.34.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 37380
:
169058
|
169059
|
169060
|
169777
|
169778
|
169779
|
171099
|
171100
|
171101
|
171189
|
171190
| 171191