Bugzilla – Attachment 118460 Details for
Bug 9921
Make it possible to force 001 = biblionumber
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9921: Remove option of 'incremental' and add tests
Bug-9921-Remove-option-of-incremental-and-add-test.patch (text/plain), 13.87 KB, created by
Nick Clemens
on 2021-03-18 13:13:21 UTC
(
hide
)
Description:
Bug 9921: Remove option of 'incremental' and add tests
Filename:
MIME Type:
Creator:
Nick Clemens
Created:
2021-03-18 13:13:21 UTC
Size:
13.87 KB
patch
obsolete
>From ea719c9125c6019edb7b323b23711b5d885b7c60 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 18 Mar 2021 13:11:31 +0000 >Subject: [PATCH] Bug 9921: Remove option of 'incremental' and add tests > >--- > C4/Biblio.pm | 52 +++------------ > cataloguing/value_builder/marc21_field_001.pl | 76 ---------------------- > installer/data/mysql/atomicupdate/bug_9921.perl | 23 +------ > installer/data/mysql/mandatory/sysprefs.sql | 3 +- > .../en/modules/admin/preferences/cataloguing.pref | 8 --- > t/db_dependent/Biblio.t | 25 ++++++- > 6 files changed, 37 insertions(+), 150 deletions(-) > delete mode 100755 cataloguing/value_builder/marc21_field_001.pl > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 6bb0d7194a..523558c550 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -283,28 +283,6 @@ sub AddBiblio { > # update MARC subfield that stores biblioitems.cn_sort > _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); > >- # 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); >- } >- }elsif(C4::Context->preference('autoControlNumber') eq 'incremental'){ >- if(!defined($record->field('001')) or (defined($record->field('001')) and $record->field('001')->data() eq 'incremental')){ >- my $sth = $dbh->prepare(q{UPDATE systempreferences SET value = value+1 WHERE variable = 'incrementalControlNumber'}); >- $sth->execute(); >- $sth->finish(); >- my $incrementalCN=C4::Context->preference('incrementalControlNumber')-1; >- unless($record->field('001')){ >- $record->insert_fields_ordered(MARC::Field->new('001', $incrementalCN)); >- }else{ >- $record->field('001')->update($incrementalCN); >- } >- } >- } >- >- > # now add the record > ModBiblioMarc( $record, $biblionumber ) unless $defer_marc_save; > >@@ -398,27 +376,6 @@ sub ModBiblio { > # update MARC subfield that stores biblioitems.cn_sort > _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); > >- # 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); >- } >- }elsif(C4::Context->preference('autoControlNumber') eq 'incremental'){ >- if(!defined($record->field('001')) or (defined($record->field('001')) and $record->field('001')->data() eq 'incremental')){ >- my $sth = $dbh->prepare(q{UPDATE systempreferences SET value = value+1 WHERE variable = 'incrementalControlNumber'}); >- $sth->execute(); >- $sth->finish(); >- my $incrementalCN=C4::Context->preference('incrementalControlNumber')-1; >- unless($record->field('001')){ >- $record->insert_fields_ordered(MARC::Field->new('001', $incrementalCN)); >- }else{ >- $record->field('001')->update($incrementalCN); >- } >- } >- } >- > # update the MARC record (that now contains biblio and items) with the new record data > &ModBiblioMarc( $record, $biblionumber ); > >@@ -2668,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/cataloguing/value_builder/marc21_field_001.pl b/cataloguing/value_builder/marc21_field_001.pl >deleted file mode 100755 >index 5eca9c7050..0000000000 >--- a/cataloguing/value_builder/marc21_field_001.pl >+++ /dev/null >@@ -1,76 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2013 Spanish Ministry of Education, Culture and Sport >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it under the >-# terms of the GNU General Public License as published by the Free Software >-# Foundation; either version 2 of the License, or (at your option) any later >-# version. >-# >-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >-# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License along >-# with Koha; if not, write to the Free Software Foundation, Inc., >-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >- >-use Modern::Perl; >- >-use C4::Context; >- >-# This is a new style cataloging plugin, using $building_plugin >- >-our $building_plugin; >-if(defined $building_plugin) { >- marc21_field001_plugin_javascript(); >-} >-else { #nothing to do (no popup) >-} >- >-#------------------------------------------------------------------------------- >- >-sub marc21_field001_plugin_javascript { >- my $field_number= $building_plugin->{subfieldid}; >- my $function_name= $field_number; >- >- #depending on preference, adjust Focus function >- my $autoControlNumber = C4::Context->preference('autoControlNumber'); >- my $focusline=''; >- if( $autoControlNumber ne 'OFF' ) { >- $focusline= "document.getElementById(\"$field_number\").value='$autoControlNumber';\n"; >- } >- $focusline.='return 1;'; >- >- #build the actual javascript >- my $res = " >-<script type=\"text/javascript\"> >-//<![CDATA[ >-oldValue = document.getElementById(\"$field_number\").value; >-function Blur$function_name(subfield_managed) { >- if(oldValue != document.getElementById(\"$field_number\").value){ >- $focusline >- } >- return 1; >-} >-function Focus$function_name(subfield_managed) { >- if(!document.getElementById(\"$field_number\").value){ >- $focusline >- } >- return 1; >-} >-function Clic$function_name(index) { >- $focusline >-} >-//]]> >-</script> >-"; >- >- #return to caller via global hash >- $building_plugin->{function}= $function_name; >- $building_plugin->{javascript}= $res; >-} >- >-1; >diff --git a/installer/data/mysql/atomicupdate/bug_9921.perl b/installer/data/mysql/atomicupdate/bug_9921.perl >index 7322f81d48..7358523c82 100644 >--- a/installer/data/mysql/atomicupdate/bug_9921.perl >+++ b/installer/data/mysql/atomicupdate/bug_9921.perl >@@ -2,27 +2,10 @@ $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','incremental|biblionumber|OFF', >- 'Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','Choice');} >+ 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');} > ); >- $dbh->do( >- q{INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('incrementalControlNumber', '1', 'Set the number >- (controlnumber) of the next bibliographic record.',NULL,'');} >- ); >- if (C4::Context->preference("marcflavour") eq 'MARC21') { >- my $sth = $dbh->prepare( >- q{SELECT * FROM marc_subfield_structure WHERE tagfield = '001' AND tagsubfield = '@' >- AND (value_builder IS NOT NULL AND value_builder != '') LIMIT 1;} >- ); >- $sth->execute; >- unless($sth->fetchrow){ >- $dbh->do( >- q{UPDATE marc_subfield_structure SET value_builder = 'marc21_field_001.pl' WHERE tagfield = '001' AND tagsubfield = '@';} >- ); >- print "WARNING: Your frameworks have been updated, field 001 will filled in through marc21_field_001.pl plugin.\n"; >- } >- } > > # Always end with this (adjust the bug info) >- NewVersion( $DBversion, 9921, "Make it possible to force 001 = biblionumbe"); >+ 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 fcb3b6acce..ea075d7c2b 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -69,7 +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','incremental|biblionumber|OFF','Used to autogenerate a Control Number: incremental will be of the form 1, 2, 3; biblionumber will be as biblionumber;','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'), >@@ -256,7 +256,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('ILS-DI:AuthorizedIPs','','Restricts usage of ILS-DI to some IPs','.','Free'), > ('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'), > ('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'), >-('incrementalControlNumber', '1', 'Set the number (controlnumber) of the next bibliographic record.',NULL,''), > ('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'), > ('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'), > ('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','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 ff61f1a3bc..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 >@@ -163,15 +163,7 @@ Cataloging: > - pref: autoControlNumber > choices: > biblionumber: generated as biblionumber. >- incremental: generated in the form 1, 2, 3. > "OFF": not generated automatically. >- - (You should fill in a value in incrementalControlNumber preference.) >- - >- - Use Control Number (001) >- - pref: incrementalControlNumber >- class: integer >- - as incremental number. (This requires generated in the form 1, 2, 3 in autoControlNumber preference.) >- Display: > - > - '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
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 9921
:
16896
|
18700
|
18701
|
18707
|
18862
|
18863
|
19062
|
19099
|
19153
|
19156
|
19170
|
19176
|
118424
|
118425
| 118460