From 860fcc68772e12fc58732bf022c84a774ebd1242 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Sun, 11 Jun 2017 19:23:41 +0000 Subject: [PATCH] Bug 10132: Add ability to set MARC Organization Code at library level Test plan: 0. Apply patches 1. Update database 2. Go to administration -> libraries, try to update some library and fill in some value into Marc Organization code field 3. Save this library and edit again - the code should be stored correctly 4. Go to system preferences and fill in some value into MARCOrgCode preference, note there is enhanced description mentioning the ability to set organization code on library level 5. Set active library to the one with own org code stored 6. Go to cataloguing, create new empty record and click into field 003 - there should be the code you filled for that library 7. Set active library to one withou marc org code 8. Go to cataloguing, create new empty record and click into field 003 - there should be the code from system preference 9. Go to system preferences again and set AutoCreateAuthorities to 'generate' and BiblioAddsAuthorities to 'allow' 10. Go to cataloguing and create some biblio record, fill in any author in to create its authority record, save the biblio 11. Go to authorities and find this created authority, go to details and check the fields: 003, 040$a, 040$c, 670$a - there should be used right org code 12. prove t/db_dependent/AuthoritiesMarc.t t/db_dependent/Biblio.t t/db_dependent/Koha/Libraries.t Signed-off-by: Hugo Agud Signed-off-by: Tomas Cohen Arazi --- C4/AuthoritiesMarc.pm | 12 +++++++++--- C4/Biblio.pm | 7 ++++++- Koha/Library.pm | 8 ++++++++ cataloguing/value_builder/marc21_orgcode.pl | 5 ++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 8b9c6c1..96034ac 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -32,6 +32,7 @@ use Koha::Authorities; use Koha::Authority::MergeRequest; use Koha::Authority::Types; use Koha::Authority; +use Koha::Libraries; use Koha::SearchEngine; use Koha::SearchEngine::Search; @@ -605,12 +606,17 @@ sub AddAuthority { SetUTF8Flag($record); if ($format eq "MARC21") { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } if (!$record->leader) { $record->leader($leader); } if (!$record->field('003')) { $record->insert_fields_ordered( - MARC::Field->new('003',C4::Context->preference('MARCOrgCode')) + MARC::Field->new('003', $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode')) ); } my $date=POSIX::strftime("%y%m%d",localtime); @@ -629,8 +635,8 @@ sub AddAuthority { if (!$record->field('040')) { $record->insert_fields_ordered( MARC::Field->new('040','','', - 'a' => C4::Context->preference('MARCOrgCode'), - 'c' => C4::Context->preference('MARCOrgCode') + 'a' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode'), + 'c' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) ); } diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 54a6731..ad5ba66 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -569,6 +569,11 @@ sub LinkBibHeadingsToAuthorities { # of change to a core API just before the 3.0 release. if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } $marcrecordauth->insert_fields_ordered( MARC::Field->new( '667', '', '', @@ -583,7 +588,7 @@ sub LinkBibHeadingsToAuthorities { $cite =~ s/[\s\,]*$//; $cite = "Work cat.: (" - . C4::Context->preference('MARCOrgCode') . ")" + . ( $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) . ")" . $bib->subfield( '999', 'c' ) . ": " . $cite; $marcrecordauth->insert_fields_ordered( diff --git a/Koha/Library.pm b/Koha/Library.pm index 44088ea..7cfb749 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -21,6 +21,8 @@ use Modern::Perl; use Carp; +use C4::Context; + use Koha::Database; use base qw(Koha::Object); @@ -54,6 +56,12 @@ sub add_to_categories { } } +sub get_effective_marcorgcode { + my ( $self ) = @_; + + return $self->marcorgcode || C4::Context->preference("MARCOrgCode"); +} + =head3 type =cut diff --git a/cataloguing/value_builder/marc21_orgcode.pl b/cataloguing/value_builder/marc21_orgcode.pl index 48a30ab..6724fc8 100755 --- a/cataloguing/value_builder/marc21_orgcode.pl +++ b/cataloguing/value_builder/marc21_orgcode.pl @@ -23,9 +23,12 @@ use Modern::Perl; use C4::Context; +use Koha::Libraries; + my $builder = sub { my ( $params ) = @_; - my $org = C4::Context->preference('MARCOrgCode'); + my $library = Koha::Libraries->find( C4::Context->userenv->{'branch'} ); + my $org = $library->get_effective_marcorgcode; return <<"HERE";