From 3eb94f3451c038015bca850bb3c0f9a7caa0b3de Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 22 Jun 2021 13:00:01 +0000 Subject: [PATCH] Bug 27981: (follow-up) Handle duplciation and remove debug There were some additional lines in the commits on accident I add a 'duplication' option to svc/bib and pass the parameter from rancor to remove the 001 if autoControlNumber is set I add code to addbiblio.pl to remove 001 in standard editor To test: 1 - Follow above test plan 2 - Edit a record as duplicate when using the advanced editor 3 - Confirm the 001 does not load, but record saves correctly 4 - Edit the record 5 - Switch to 'basic editor' 6 - Save, then view record 7 - Edit as duplicate in basic editor 8 - Confirm the 001 is removed 9 - Confirm the 001 is added on save Signed-off-by: hakam --- C4/Biblio.pm | 2 -- cataloguing/addbiblio.pl | 6 +++++- .../lib/koha/cateditor/koha-backend.js | 4 ++-- .../intranet-tmpl/prog/en/includes/cateditor-ui.inc | 4 ++-- .../en/modules/admin/preferences/cataloguing.pref | 1 + members/memberentry.pl | 2 -- svc/bib | 13 ++++++++++--- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 6744803701..efc0f11e69 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2632,8 +2632,6 @@ sub _koha_marc_update_bib_ids { 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); } } } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 7eba09f55d..0033c8f9eb 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -790,7 +790,11 @@ if (($biblionumber) && !($breedingid)){ if ($breedingid) { ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; } - +if ( $record && $op eq 'duplicate' && + C4::Context->preference('autoControlNumber') eq 'biblionumber' ){ + my @control_num = $record->field('001'); + $record->delete_fields(@control_num); +} #populate hostfield if hostbiblionumber is available if ($hostbiblionumber) { my $marcflavour = C4::Context->preference("marcflavour"); diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js index eeca779440..93fc5c492c 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js @@ -103,9 +103,9 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin return _framework_kohafields[kohafield]; }, - GetRecord: function( id, callback ) { + GetRecord: function( id, duplicate, callback ) { $.get( - '/cgi-bin/koha/svc/bib/' + id + '/cgi-bin/koha/svc/bib/'+ duplicate + id ).done( function( metadata ) { $.get( '/cgi-bin/koha/svc/bib_framework/' + id diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc index 352e9a0c53..8ed5016df1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc @@ -252,7 +252,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr get: function( id, callback ) { if ( !id ) return false; - KohaBackend.GetRecord( id, callback ); + KohaBackend.GetRecord( id, "d", callback ); }, save: function( id, record, done ) { function finishCb( data ) { @@ -272,7 +272,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr get: function( id, callback ) { if ( !id ) return false; - KohaBackend.GetRecord( id, callback ); + KohaBackend.GetRecord( id, "", callback ); }, save: function( id, record, done ) { function finishCb( data ) { 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 76cb45174b..a740bd0a68 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 @@ -164,6 +164,7 @@ Cataloging: choices: biblionumber: generated as biblionumber. "OFF": not generated automatically. + Display: - - 'Separate main entry and subdivisions with ' - pref: AuthoritySeparator diff --git a/members/memberentry.pl b/members/memberentry.pl index abae2ec53e..da8a324c78 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -109,9 +109,7 @@ $template->param( relationships => scalar $patron->guarantor_relationships ) if my @relations = split /\|/, C4::Context->preference('borrowerRelationship'), -1; @relations = ('') unless @relations; -warn Data::Dumper::Dumper( \@relations ); my $empty_relationship_allowed = grep {$_ eq ""} @relations; -warn $empty_relationship_allowed; $template->param( empty_relationship_allowed => $empty_relationship_allowed ); my $guarantor_id = $input->param('guarantor_id'); diff --git a/svc/bib b/svc/bib index 43fc6f6857..2a500254eb 100755 --- a/svc/bib +++ b/svc/bib @@ -40,16 +40,18 @@ unless ($status eq "ok") { # do initial validation my $path_info = $query->path_info(); +my $duplicate = undef; my $biblionumber = undef; -if ($path_info =~ m!^/(\d+)$!) { - $biblionumber = $1; +if ($path_info =~ m!^/(d?)(\d+)$!) { + $duplicate = $1; + $biblionumber = $2; } else { print $query->header(-type => 'text/xml', -status => '400 Bad Request'); } # are we retrieving, updating or deleting a bib? if ($query->request_method eq "GET") { - fetch_bib($query, $biblionumber); + fetch_bib($query, $biblionumber, $duplicate); } elsif ($query->request_method eq "POST") { update_bib($query, $biblionumber); } elsif ($query->request_method eq "DELETE") { @@ -65,10 +67,15 @@ exit 0; sub fetch_bib { my $query = shift; my $biblionumber = shift; + my $duplicate = shift; my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => scalar $query->param('items') }); if (defined $record) { + if( $duplicate && C4::Context->preference('autoControlNumber') eq 'biblionumber' ){ + my @control_nums = $record->field('001'); + $record->delete_fields(@control_nums); + } print $query->header(-type => 'text/xml',-charset => 'utf-8',); print $record->as_xml_record(); } else { -- 2.25.1