View | Details | Raw Unified | Return to bug 5943
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-21 / +49 lines)
Lines 27-32 use C4::AuthoritiesMarc::MARC21; Link Here
27
use C4::AuthoritiesMarc::UNIMARC;
27
use C4::AuthoritiesMarc::UNIMARC;
28
use C4::Charset;
28
use C4::Charset;
29
use C4::Log;
29
use C4::Log;
30
use List::MoreUtils qw/none/;
31
use C4::Debug;
30
32
31
use vars qw($VERSION @ISA @EXPORT);
33
use vars qw($VERSION @ISA @EXPORT);
32
34
Lines 1270-1278 sub merge { Link Here
1270
    
1272
    
1271
    my @record_to;
1273
    my @record_to;
1272
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1274
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1275
    my $field_to;
1276
    $field_to = $MARCto->field($auth_tag_to_report_to) if $MARCto->field($auth_tag_to_report_to);
1273
    my @record_from;
1277
    my @record_from;
1274
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1278
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1275
    
1276
    my @reccache;
1279
    my @reccache;
1277
    # search all biblio tags using this authority.
1280
    # search all biblio tags using this authority.
1278
    #Getting marcbiblios impacted by the change.
1281
    #Getting marcbiblios impacted by the change.
Lines 1330-1358 sub merge { Link Here
1330
    # BulkEdit marc records
1333
    # BulkEdit marc records
1331
    # May be used as a template for a bulkedit field  
1334
    # May be used as a template for a bulkedit field  
1332
    foreach my $marcrecord(@reccache){
1335
    foreach my $marcrecord(@reccache){
1333
        my $update;           
1336
	    $debug && warn "before merge",$marcrecord->as_formatted;
1334
        $marcrecord= MARC::Record->new_from_xml($marcrecord,"utf8",C4::Context->preference("marcflavour")) unless(C4::Context->preference('NoZebra'));
1335
        foreach my $tagfield (@tags_using_authtype){
1337
        foreach my $tagfield (@tags_using_authtype){
1336
#             warn "tagfield : $tagfield ";
1337
            foreach my $field ($marcrecord->field($tagfield)){
1338
            foreach my $field ($marcrecord->field($tagfield)){
1338
                my $auth_number=$field->subfield("9");
1339
                my $update;           
1339
                my $tag=$field->tag();          
1340
                my $tag=$field->tag();          
1340
                if ($auth_number==$mergefrom) {
1341
		my @newsubfields;
1341
                my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1342
		my %indexes;
1342
		my $exclude='9';
1343
		foreach my $subfield ($field->subfields()){
1343
                foreach my $subfield (@record_to) {
1344
			$debug && warn @$subfield, " ", $mergefrom," ",$mergeto;
1344
                    $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1345
		    if ($subfield->[0] eq 9 and $subfield->[1] eq $mergefrom){
1345
		    $exclude.= $subfield->[0];
1346
			$debug && warn $subfield->[1], " ", $mergeto;
1347
			    $subfield->[1] = $mergeto;
1348
		    	    $update=1;
1349
		    	$debug && warn "update 1";
1350
		}
1351
1352
		    if ($update){
1353
		# Removing numeric subfields from the authority record
1354
		    for my $subfieldfrom (@record_from) {
1355
			$debug && warn $subfield->[1], " ", $subfieldfrom->[1];
1356
			next if ($subfield->[0] eq 9);
1357
		    	if ($subfield->[0] eq $subfieldfrom->[0]){
1358
			    if (exists $indexes{$subfield->[0]}){
1359
			    $indexes{$subfield->[0]}++;
1360
			    } else {
1361
			    $indexes{$subfield->[0]}=0;
1346
                }
1362
                }
1347
		$exclude='['.$exclude.']';
1363
				my @subfstemp=$field_to->subfield($subfield->[0]);
1348
#		add subfields in $field not included in @record_to
1364
				$debug && warn @subfstemp;
1349
		my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1365
				$subfield->[1] = $subfstemp[$indexes{$subfield->[0]}];
1350
                foreach my $subfield (@restore) {
1366
                $update=1;
1351
                   $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1367
				last;
1368
			}
1369
		    }
1370
		    }
1371
			$debug && warn @$subfield;
1372
          	    push @newsubfields,@$subfield;
1373
		}
1374
		#filter to subfields which are not in the subfield
1375
		# and not in 1245678
1376
		for my $subf (grep {my $subftag=$_->[0];$subftag !~m/[1245678]/ and none {$subftag eq $_}@newsubfields }@record_to){
1377
		   push @newsubfields,@$subf;
1352
		}
1378
		}
1379
		if ($update){
1380
                my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),@newsubfields);
1353
                $marcrecord->delete_field($field);
1381
                $marcrecord->delete_field($field);
1354
                $marcrecord->insert_grouped_field($field_to);            
1382
                $marcrecord->insert_fields_ordered($field_to);            
1355
                $update=1;
1356
                }
1383
                }
1357
            }#for each tag
1384
            }#for each tag
1358
        }#foreach tagfield
1385
        }#foreach tagfield
Lines 1364-1379 sub merge { Link Here
1364
        else {
1391
        else {
1365
            $biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
1392
            $biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
1366
        }
1393
        }
1394
#	    $debug && warn $biblionumber,$marcrecord->as_formatted;
1367
        unless ($biblionumber){
1395
        unless ($biblionumber){
1368
            warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
1396
            warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
1369
            next;
1397
            next;
1370
        }
1398
        }
1371
        if ($update==1){
1399
        #if ($update==1){
1372
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1400
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1373
            $counteditedbiblio++;
1401
            $counteditedbiblio++;
1374
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1402
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1375
        }    
1403
        #}    
1376
    }#foreach $marc
1404
    }#foreach $marc
1405
    DelAuthority($mergefrom) if ($mergefrom != $mergeto);
1377
    return $counteditedbiblio;  
1406
    return $counteditedbiblio;  
1378
  # now, find every other authority linked with this authority
1407
  # now, find every other authority linked with this authority
1379
  # now, find every other authority linked with this authority
1408
  # now, find every other authority linked with this authority
1380
- 

Return to bug 5943