Bugzilla – Attachment 25086 Details for
Bug 11700
C4::AuthoritiesMarc::merge enhancements/fixes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11700: C4::AuthoritiesMarc::merge enhancements/fixes
Bug-11700-C4AuthoritiesMarcmerge-enhancementsfixes.patch (text/plain), 7.80 KB, created by
Julian Maurice
on 2014-02-06 15:18:44 UTC
(
hide
)
Description:
Bug 11700: C4::AuthoritiesMarc::merge enhancements/fixes
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2014-02-06 15:18:44 UTC
Size:
7.80 KB
patch
obsolete
>From d8cf904aba6c51a5d8c43a15b959aa22d4afbef7 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 6 Feb 2014 15:59:40 +0100 >Subject: [PATCH] Bug 11700: C4::AuthoritiesMarc::merge enhancements/fixes > >- Returns the list of modified biblio records >- Retrieve MARC records from DB if not given in parameters >- Delete source authority if source and destination records are > different >- Indentation and whitespace fixes >--- > C4/AuthoritiesMarc.pm | 126 +++++++++++++++++-------------------------------- > 1 file changed, 43 insertions(+), 83 deletions(-) > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 1c87285..12e95ca 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -1407,19 +1407,25 @@ sub AddAuthorityTrees{ > > =head2 merge > >- $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto) >+ my @edited_biblionumbers = merge(mergefrom, $MARCfrom, $mergeto, $MARCto); > > Could add some feature : Migrating from a typecode to an other for instance. > Then we should add some new parameter : bibliotargettag, authtargettag > >+Returns a list of biblionumbers of records that were modified. >+ > =cut > > sub merge { >- my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; >- my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); >- my $dbh=C4::Context->dbh; >+ my ($mergefrom, $MARCfrom, $mergeto, $MARCto) = @_; >+ my @editedbiblios; >+ my $dbh = C4::Context->dbh; > my $authtypecodefrom = GetAuthTypeCode($mergefrom); > my $authtypecodeto = GetAuthTypeCode($mergeto); >+ >+ $MARCfrom ||= GetAuthority($mergefrom); >+ $MARCto ||= GetAuthority($mergeto); >+ > # warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto "; > # return if authority does not exist > return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0; >@@ -1430,12 +1436,12 @@ sub merge { > my ($auth_tag_to_report_from) = $sth->fetchrow; > $sth->execute($authtypecodeto); > my ($auth_tag_to_report_to) = $sth->fetchrow; >- >+ > my @record_to; > @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() 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. >@@ -1472,42 +1478,42 @@ sub merge { > while (my ($tagfield) = $sth->fetchrow) { > push @tags_using_authtype,$tagfield ; > } >- my $tag_to=0; >- if ($authtypecodeto ne $authtypecodefrom){ >+ my $tag_to=0; >+ if ($authtypecodeto ne $authtypecodefrom){ > # If many tags, take the first >- $sth->execute($authtypecodeto); >+ $sth->execute($authtypecodeto); > $tag_to=$sth->fetchrow; >- #warn $tag_to; >- } >+ } > # BulkEdit marc records >- # May be used as a template for a bulkedit field >+ # May be used as a template for a bulkedit field > foreach my $marcrecord(@reccache){ >- my $update; >+ my $update; > foreach my $tagfield (@tags_using_authtype){ >-# warn "tagfield : $tagfield "; > foreach my $field ($marcrecord->field($tagfield)){ > # biblio is linked to authority with $9 subfield containing authid > my $auth_number=$field->subfield("9"); >- my $tag=$field->tag(); >+ 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 (grep {$_->[0] ne '9'} @record_to) { >- $field_to->add_subfields($subfield->[0] =>$subfield->[1]); >- $exclude.= $subfield->[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]); >- } >- $marcrecord->delete_field($field); >- $marcrecord->insert_grouped_field($field_to); >- $update=1; >+ 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 (grep {$_->[0] ne '9'} @record_to) { >+ $field_to->add_subfields($subfield->[0] =>$subfield->[1]); >+ $exclude.= $subfield->[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]); >+ } >+ $marcrecord->delete_field($field); >+ $marcrecord->insert_grouped_field($field_to); >+ $update=1; > } > }#for each tag > }#foreach tagfield >+ > my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ; > my $biblionumber; > if ($bibliotag<10){ >@@ -1522,60 +1528,14 @@ sub merge { > } > if ($update==1){ > &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ; >- $counteditedbiblio++; >- warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG}); >- } >+ push @editedbiblios, $biblionumber; >+ } > }#foreach $marc >- return $counteditedbiblio; >- # now, find every other authority linked with this authority >- # now, find every other authority linked with this authority >-# my $oConnection=C4::Context->Zconn("authorityserver"); >-# my $query; >-# # att 9210 Auth-Internal-authtype >-# # att 9220 Auth-Internal-LN >-# # ccl.properties to add for authorities >-# $query= "= ".$mergefrom; >-# my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection )); >-# my $count=$oResult->size() if ($oResult); >-# my @reccache; >-# my $z=0; >-# while ( $z<$count ) { >-# my $rec; >-# $rec=$oResult->record($z); >-# my $marcdata = $rec->raw(); >-# push @reccache, $marcdata; >-# $z++; >-# } >-# $oResult->destroy(); >-# foreach my $marc(@reccache){ >-# my $update; >-# my $marcrecord; >-# $marcrecord = MARC::File::USMARC::decode($marc); >-# foreach my $tagfield (@tags_using_authtype){ >-# $tagfield=substr($tagfield,0,3); >-# my @tags = $marcrecord->field($tagfield); >-# foreach my $tag (@tags){ >-# my $tagsubs=$tag->subfield("9"); >-# #warn "$tagfield:$tagsubs:$mergefrom"; >-# if ($tagsubs== $mergefrom) { >-# $tag->update("9" =>$mergeto); >-# foreach my $subfield (@record_to) { >-# # warn "$subfield,$subfield->[0],$subfield->[1]"; >-# $tag->update($subfield->[0] =>$subfield->[1]); >-# }#for $subfield >-# } >-# $marcrecord->delete_field($tag); >-# $marcrecord->add_fields($tag); >-# $update=1; >-# }#for each tag >-# }#foreach tagfield >-# my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ; >-# if ($update==1){ >-# &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ; >-# } >-# >-# }#foreach $marc >-}#sub >+ >+ DelAuthority($mergefrom) if ($mergefrom != $mergeto); >+ >+ return @editedbiblios; >+} > > =head2 get_auth_type_location > >-- >1.7.10.4
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 11700
:
25086
|
25413
|
25414
|
25426
|
27970
|
27971
|
27972
|
27973
|
28176
|
28177
|
35107
|
39264
|
39265
|
39266
|
39267
|
39268
|
39269
|
40968
|
40969
|
40970
|
40971
|
40972
|
45048
|
45049
|
45050
|
45051
|
45052
|
45053
|
46397
|
46398
|
46399
|
46400
|
46401
|
46402
|
56469
|
56470
|
56471
|
56472
|
56473
|
56474