@@ -, +, @@ biblionumber 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 --- 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 --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -2623,6 +2623,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 --- a/installer/data/mysql/atomicupdate/bug_9921.perl +++ a/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"); +} --- a/installer/data/mysql/mandatory/sysprefs.sql +++ a/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'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ a/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 --- a/t/db_dependent/Biblio.t +++ a/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 ); @@ -808,6 +808,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; --