From 91d870f67aa4b6a4784794e77304fcf759675184 Mon Sep 17 00:00:00 2001 From: Srdjan Jankovic Date: Mon, 19 Dec 2011 19:22:49 +1300 Subject: [PATCH] bug_6210: Select framework if merging two records with different frameworks ModBiblio() - set framework to "" if "Default" Signed-off-by: Nicole C. Engard All 4 tests passed: Test 1: Merge two records with the same framework Desired result: shouldn't get any prompting to pick a framework, and the same framework should be used Test 2: 2 records, different frameworks, into the kept record's framework Desired result: merge with kept records framework used Test 3: 2 records, different frameworks, into the discarded record's framework Desired result: merge with used records framework used Test 4: 2 records, different frameworks, into a third framework Desired result: merge with third framework used --- C4/Biblio.pm | 41 +++--- cataloguing/merge.pl | 136 ++++++++++-------- .../prog/en/modules/cataloguing/merge.tt | 39 ++++- 3 files changed, 136 insertions(+), 80 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ad559faca6..631e8911e0 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -320,7 +320,7 @@ sub ModBiblio { SetUTF8Flag($record); my $dbh = C4::Context->dbh; - $frameworkcode = "" unless $frameworkcode; + $frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX _strip_item_fields($record, $frameworkcode); @@ -1043,9 +1043,13 @@ for the given frameworkcode sub GetMarcFromKohaField { my ( $kohafield, $frameworkcode ) = @_; - return 0, 0 unless $kohafield and defined $frameworkcode; + return (0, undef) unless $kohafield and defined $frameworkcode; my $relations = C4::Context->marcfromkohafield; - return ( $relations->{$frameworkcode}->{$kohafield}->[0], $relations->{$frameworkcode}->{$kohafield}->[1] ); + if ( my $mf = $relations->{$frameworkcode}->{$kohafield} ) { + return @$mf; + } + warn qq{No marc tags for framework "$frameworkcode" field $kohafield}; + return (0, undef); } =head2 GetMarcBiblio @@ -3157,9 +3161,24 @@ sub _koha_marc_update_bib_ids { # we drop the original field # we add the new builded field. my ( $biblio_tag, $biblio_subfield ) = GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode ); + die qq{No biblionumber tag for framework "$frameworkcode"} unless $biblio_tag; my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode ); + die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblio_tag; - if ( $biblio_tag != $biblioitem_tag ) { + if ( $biblio_tag == $biblioitem_tag ) { + + # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value) + my $new_field = MARC::Field->new( + $biblio_tag, '', '', + "$biblio_subfield" => $biblionumber, + "$biblioitem_subfield" => $biblioitemnumber + ); + + # drop old field and create new one... + my $old_field = $record->field($biblio_tag); + $record->delete_field($old_field) if $old_field; + $record->insert_fields_ordered($new_field); + } else { # biblionumber & biblioitemnumber are in different fields @@ -3187,20 +3206,6 @@ sub _koha_marc_update_bib_ids { $old_field = $record->field($biblioitem_tag); $record->delete_field($old_field) if $old_field; $record->insert_fields_ordered($new_field); - - } else { - - # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value) - my $new_field = MARC::Field->new( - $biblio_tag, '', '', - "$biblio_subfield" => $biblionumber, - "$biblioitem_subfield" => $biblioitemnumber - ); - - # drop old field and create new one... - my $old_field = $record->field($biblio_tag); - $record->delete_field($old_field) if $old_field; - $record->insert_fields_ordered($new_field); } } diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index 0b881f1c13..59b1d028c2 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -27,6 +27,7 @@ use C4::Auth; use C4::Items; use C4::Biblio; use C4::Serials; +use C4::Koha; use C4::Reserves qw/MergeHolds/; my $input = new CGI; @@ -61,7 +62,7 @@ if ($merge) { # Rewriting the leader $record->leader(GetMarcBiblio($tobiblio)->leader()); - my $frameworkcode = &GetFrameworkCode($tobiblio); + my $frameworkcode = $input->param('frameworkcode'); my @notmoveditems; # Modifying the reference record @@ -108,77 +109,98 @@ if ($merge) { push @errors, $error if ($error); } - # Errors - my @errors_loop = map{{error => $_}}@errors; - # Parameters $template->param( - errors => \@errors_loop, result => 1, biblio1 => $input->param('biblio1') ); - #------------------------- # Show records to merge #------------------------- } else { - my $mergereference = $input->param('mergereference'); my $biblionumber = $input->param('biblionumber'); - my $data1 = GetBiblioData($biblionumber[0]); - my $data2 = GetBiblioData($biblionumber[1]); - - # Ask the user to choose which record will be the kept - if (not $mergereference) { - $template->param( - choosereference => 1, - biblio1 => $biblionumber[0], - biblio2 => $biblionumber[1], - title1 => $data1->{'title'}, - title2 => $data2->{'title'} - ); - } else { - - if (scalar(@biblionumber) != 2) { - push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged."; - } - - # Checks if both records use the same framework - my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]); - my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]); - my $framework; - if ($frameworkcode1 ne $frameworkcode2) { - push @errors, "The records selected for merging are using different frameworks. Currently merging is only available for records using the same framework."; - } else { - $framework = $frameworkcode1; - } - - # Getting MARC Structure - my $tagslib = GetMarcStructure(1, $framework); - - my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0]; - - # Creating a loop for display - my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib); - my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib); - - # Errors - my @errors_loop = map{{error => $_}}@errors; - - # Parameters - $template->param( - errors => \@errors_loop, - biblio1 => $mergereference, - biblio2 => $notreference, - mergereference => $mergereference, - record1 => @record1, - record2 => @record2, - framework => $framework - ); + if (scalar(@biblionumber) != 2) { + push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged."; + } + else { + my $data1 = GetBiblioData($biblionumber[0]); + my $data2 = GetBiblioData($biblionumber[1]); + + # Checks if both records use the same framework + my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]); + my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]); + + if ($mergereference) { + + my $framework; + if ($frameworkcode1 ne $frameworkcode2) { + $framework = $input->param('frameworkcode') + or push @errors, "Famework not selected."; + } else { + $framework = $frameworkcode1; + } + + # Getting MARC Structure + my $tagslib = GetMarcStructure(1, $framework); + + my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0]; + + # Creating a loop for display + my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib); + my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib); + + # Parameters + $template->param( + biblio1 => $mergereference, + biblio2 => $notreference, + mergereference => $mergereference, + record1 => @record1, + record2 => @record2, + framework => $framework, + ); + } + else { + + # Ask the user to choose which record will be the kept + $template->param( + choosereference => 1, + biblio1 => $biblionumber[0], + biblio2 => $biblionumber[1], + title1 => $data1->{'title'}, + title2 => $data2->{'title'} + ); + if ($frameworkcode1 ne $frameworkcode2) { + my $frameworks = getframeworks; + my @frameworkselect; + foreach my $thisframeworkcode ( keys %$frameworks ) { + my %row = ( + value => $thisframeworkcode, + frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, + ); + if ($frameworkcode1 eq $thisframeworkcode){ + $row{'selected'} = 1; + } + push @frameworkselect, \%row; + } + $template->param( + frameworkselect => \@frameworkselect, + frameworkcode1 => $frameworkcode1, + frameworkcode2 => $frameworkcode2, + ); + } + } } } + +if (@errors) { + # Errors + my @errors_loop = map{{error => $_}}@errors; + $template->param( errors => \@errors_loop ); +} + output_html_with_http_headers $input, $cookie, $template->output; exit; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt index 0d8a84ca43..5a48385b03 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt @@ -161,6 +161,10 @@ $(document).ready(function(){ }); +function changeFramework(fw) { + $("#Frameworks").val(fw); +} + //]]> @@ -194,10 +198,34 @@ $(document).ready(function(){
Merge reference + + + + + +
    -
  1. -
  2. +
  3. +
+
+ [% IF frameworkselect %] +
+ + [% END %] +
+
@@ -332,14 +360,15 @@ $(document).ready(function(){ [% END %] + + + + - - -
-- 2.39.5