From a16bac770510d4984838ace2095ac010a293acd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C3=B1o=20L=C3=B3pez=20Ans=C3=B3tegui?= Date: Wed, 19 Jun 2013 14:35:41 +0200 Subject: [PATCH] Bug 27981: Add option to automatically set 001 to the biblionumber This patch adds a new system preference: autoControlNumber The option "biblionumber" will set field 001 to the biblionumber when you create a new record or edit an existing record If set to 'OFF' the 001 field wil not be touched To test: 1 - Apply patches and updatedatabase 2 - Create a new record with no 001 field 3 - Save and view the MAC, confirm there is no 001 4 - Set the system preference to 'biblionumber' 5 - Edit the record you created previously 6 - Note the 001 is prepopulated with the biblionumber 7 - Delete the field 8 - Save the record 9 - View the MARC, the 001 is filled with biblionumber 10 - Edit the record 11 - Set the 001 to a different value "Not the biblionumber" 12 - Save 13 - View the marc and confirm the value you entered is retained 14 - Edit a record with an existing 001 that is not the biblionumber 15 - Save and confirm 001 is not updated --- C4/Biblio.pm | 9 ++++++++ installer/data/mysql/atomicupdate/bug_9921.perl | 11 ++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/cataloguing.pref | 7 +++++- t/db_dependent/Biblio.t | 25 +++++++++++++++++++++- 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_9921.perl diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b482a99814..523558c550 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2625,6 +2625,15 @@ sub _koha_marc_update_bib_ids { } else { C4::Biblio::UpsertMarcSubfield($record, $biblioitem_tag, $biblioitem_subfield, $biblioitemnumber); } + + # update the control number (001) in MARC + if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){ + unless($record->field('001')){ + $record->insert_fields_ordered(MARC::Field->new('001', $biblionumber)); + }elsif($record->field('001')->data() eq 'biblionumber'){ + $record->field('001')->update($biblionumber); + } + } } =head2 _koha_marc_update_biblioitem_cn_sort diff --git a/installer/data/mysql/atomicupdate/bug_9921.perl b/installer/data/mysql/atomicupdate/bug_9921.perl new file mode 100644 index 0000000000..7358523c82 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_9921.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); + $dbh->do( + q{INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('autoControlNumber','OFF','biblionumber|OFF', + 'Used to autogenerate a Control Number: biblionumber will be as biblionumber; OFF will leave it as is','Choice');} + ); + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 9921, "Make it possible to force 001 = biblionumber"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index b513bd37bd..ea075d7c2b 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -69,6 +69,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'), ('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'), ('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'), +('autoControlNumber','OFF','biblionumber|OFF','Used to autogenerate a Control Number: biblionumber will be as biblionumber, OFF will leave the field as it is;','Choice'), ('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'), ('AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice'), ('AutoEmailOpacUser','0',NULL,'Sends notification emails containing new account details to patrons - when account is created.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index bee04d5922..9c60d67aa0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -158,7 +158,12 @@ Cataloging: - and record's last modifier name in MARC subfield - pref: MarcFieldForModifierName - ".
NOTE: Use a dollar sign between field and subfield like 123$a." - Display: + - + - Control Number (001) is + - pref: autoControlNumber + choices: + biblionumber: generated as biblionumber. + "OFF": not generated automatically. - - 'Separate main entry and subdivisions with ' - pref: AuthoritySeparator diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index 4e69b3e9b5..8caf76f355 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 16; use Test::MockModule; use Test::Warn; use List::MoreUtils qw( uniq ); @@ -805,6 +805,29 @@ subtest "LinkBibHeadingsToAuthorities record generation tests" => sub { ); }; +subtest 'autoControlNumber tests' => sub { + plan tests => 3; + + t::lib::Mocks::mock_preference('autoControlNumber', 'OFF'); + + my $record = MARC::Record->new(); + my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); + $record = GetMarcBiblio({biblionumber => $biblionumber}); + is($record->field('001'), undef, '001 not set when pref is off'); + + t::lib::Mocks::mock_preference('autoControlNumber', 'biblionumber'); + C4::Biblio::ModBiblio($record, $biblionumber, "", 1); + $record = GetMarcBiblio({biblionumber => $biblionumber}); + is($record->field('001')->as_string(), $biblionumber, '001 set to biblionumber when pref set and field is blank'); + + $record->field('001')->update('Not biblionumber'); + C4::Biblio::ModBiblio($record, $biblionumber, "", 1); + $record = GetMarcBiblio({biblionumber => $biblionumber}); + is($record->field('001')->as_string(), 'Not biblionumber', '001 not set to biblionumber when pref set and field exists'); + +}; + + # Cleanup Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); $schema->storage->txn_rollback; -- 2.11.0