- $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);
+ $oConnection->destroy();
+ }
+ #warn scalar(@reccache)." biblios to update";
+ # Get All candidate Tags for the change
+ # (This will reduce the search scope in marc records).
+ $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
+ $sth->execute($authtypecodefrom);
+ my @tags_using_authtype;
+ while (my ($tagfield) = $sth->fetchrow) {
+ push @tags_using_authtype,$tagfield ;
+ }
+ my $tag_to=0;
+ if ($authtypecodeto ne $authtypecodefrom){
+ # If many tags, take the first
+ $sth->execute($authtypecodeto);
+ $tag_to=$sth->fetchrow;
+ #warn $tag_to;
+ }
+ # 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'));
+ foreach my $tagfield (@tags_using_authtype){
+# warn "tagfield : $tagfield ";
+ foreach my $field ($marcrecord->field($tagfield)){
+ my $auth_number=$field->subfield("9");
+ 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);