[Koha-patches] [PATCH] Bug 5943 : Fixes for merging of authorities Squashed commit of the following:
Chris Cormack
chrisc at catalyst.net.nz
Thu Mar 24 03:22:08 CET 2011
commit 6f35a0b95f3dfeac0aff4a157bb1f1a3676d7201
Author: Matthias Meusburger <matthias.meusburger at biblibre.com>
Date: Tue Oct 26 07:24:15 2010 +0200
C4 AuthoritiesMarc.pm merge problem : new subfields not taken
Previous patches on merge would not take in new subfields from the authority.
This patch fixes that problem
commit 6989dab123377331b9a1502dab75aa0ab7999f37
Author: Matthias Meusburger <matthias.meusburger at biblibre.com>
Date: Thu Oct 14 16:25:23 2010 +0200
Merge authorities subfields orders
commit 297f6a1a2481a39e5625d197cc6f4868518e3646
Author: Matthias Meusburger <matthias.meusburger at biblibre.com>
Date: Thu Oct 7 17:31:54 2010 +0200
Adds debug warns
commit 9339330e82f8f33e2bcf0d8df61363895c5f40fa
Author: Matthias Meusburger <matthias.meusburger at biblibre.com>
Date: Thu Oct 7 17:14:39 2010 +0200
Removes numeric subfields from auth and adds numeric subfields from biblio in merge function
commit 0459a9b881c9df184870c87d25df339d23f7f10c
Author: Matthias Meusburger <matthias.meusburger at biblibre.com>
Date: Thu Oct 7 09:55:46 2010 +0200
Do not delete authority when merging is about the same authority
---
C4/AuthoritiesMarc.pm | 69 ++++++++++++++++++++++++++++++++++--------------
1 files changed, 49 insertions(+), 20 deletions(-)
diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm
index 3c3f6bc..d2ac516 100644
--- a/C4/AuthoritiesMarc.pm
+++ b/C4/AuthoritiesMarc.pm
@@ -27,6 +27,8 @@ use C4::AuthoritiesMarc::MARC21;
use C4::AuthoritiesMarc::UNIMARC;
use C4::Charset;
use C4::Log;
+use List::MoreUtils qw/none/;
+use C4::Debug;
use vars qw($VERSION @ISA @EXPORT);
@@ -1270,9 +1272,10 @@ sub merge {
my @record_to;
@record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
+ my $field_to;
+ $field_to = $MARCto->field($auth_tag_to_report_to) if $MARCto->field($auth_tag_to_report_to);
my @record_from;
@record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
-
my @reccache;
# search all biblio tags using this authority.
#Getting marcbiblios impacted by the change.
@@ -1330,29 +1333,53 @@ sub merge {
# BulkEdit marc records
# May be used as a template for a bulkedit field
foreach my $marcrecord(@reccache){
- my $update;
- $marcrecord= MARC::Record->new_from_xml($marcrecord,"utf8",C4::Context->preference("marcflavour")) unless(C4::Context->preference('NoZebra'));
+ $debug && warn "before merge",$marcrecord->as_formatted;
foreach my $tagfield (@tags_using_authtype){
-# warn "tagfield : $tagfield ";
foreach my $field ($marcrecord->field($tagfield)){
- my $auth_number=$field->subfield("9");
+ my $update;
my $tag=$field->tag();
- if ($auth_number==$mergefrom) {
- my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
- my $exclude='9';
- foreach my $subfield (@record_to) {
- $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
- $exclude.= $subfield->[0];
+ my @newsubfields;
+ my %indexes;
+ foreach my $subfield ($field->subfields()){
+ $debug && warn @$subfield, " ", $mergefrom," ",$mergeto;
+ if ($subfield->[0] eq 9 and $subfield->[1] eq $mergefrom){
+ $debug && warn $subfield->[1], " ", $mergeto;
+ $subfield->[1] = $mergeto;
+ $update=1;
+ $debug && warn "update 1";
+ }
+
+ if ($update){
+ # Removing numeric subfields from the authority record
+ for my $subfieldfrom (@record_from) {
+ $debug && warn $subfield->[1], " ", $subfieldfrom->[1];
+ next if ($subfield->[0] eq 9);
+ if ($subfield->[0] eq $subfieldfrom->[0]){
+ if (exists $indexes{$subfield->[0]}){
+ $indexes{$subfield->[0]}++;
+ } else {
+ $indexes{$subfield->[0]}=0;
}
- $exclude='['.$exclude.']';
-# add subfields in $field not included in @record_to
- my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
- foreach my $subfield (@restore) {
- $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
+ my @subfstemp=$field_to->subfield($subfield->[0]);
+ $debug && warn @subfstemp;
+ $subfield->[1] = $subfstemp[$indexes{$subfield->[0]}];
+ $update=1;
+ last;
+ }
+ }
+ }
+ $debug && warn @$subfield;
+ push @newsubfields,@$subfield;
+ }
+ #filter to subfields which are not in the subfield
+ # and not in 1245678
+ for my $subf (grep {my $subftag=$_->[0];$subftag !~m/[1245678]/ and none {$subftag eq $_}@newsubfields }@record_to){
+ push @newsubfields,@$subf;
}
+ if ($update){
+ my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2), at newsubfields);
$marcrecord->delete_field($field);
- $marcrecord->insert_grouped_field($field_to);
- $update=1;
+ $marcrecord->insert_fields_ordered($field_to);
}
}#for each tag
}#foreach tagfield
@@ -1364,16 +1391,18 @@ sub merge {
else {
$biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
}
+# $debug && warn $biblionumber,$marcrecord->as_formatted;
unless ($biblionumber){
warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
next;
}
- if ($update==1){
+ #if ($update==1){
&ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
$counteditedbiblio++;
warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
- }
+ #}
}#foreach $marc
+ DelAuthority($mergefrom) if ($mergefrom != $mergeto);
return $counteditedbiblio;
# now, find every other authority linked with this authority
# now, find every other authority linked with this authority
--
1.7.1
More information about the Koha-patches
mailing list