Lines 697-708
sub AddAuthority {
Link Here
|
697 |
return ($authid); |
697 |
return ($authid); |
698 |
} |
698 |
} |
699 |
|
699 |
|
700 |
|
|
|
701 |
=head2 DelAuthority |
700 |
=head2 DelAuthority |
702 |
|
701 |
|
703 |
$authid= &DelAuthority($authid) |
702 |
$authid = DelAuthority( $authid ) |
704 |
|
703 |
|
705 |
Deletes $authid |
704 |
Deletes $authid and calls merge to cleanup in linked biblio records |
706 |
|
705 |
|
707 |
=cut |
706 |
=cut |
708 |
|
707 |
|
Lines 710-719
sub DelAuthority {
Link Here
|
710 |
my ($authid) = @_; |
709 |
my ($authid) = @_; |
711 |
my $dbh=C4::Context->dbh; |
710 |
my $dbh=C4::Context->dbh; |
712 |
|
711 |
|
|
|
712 |
unless( C4::Context->preference('dontmerge') eq '1' ) { |
713 |
&merge( $authid, GetAuthority($authid) ); |
714 |
} else { |
715 |
# save a record in need_merge_authorities table |
716 |
my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) VALUES (?,?)"; |
717 |
$dbh->do( $sqlinsert, undef, $authid, 0 ); |
718 |
} |
719 |
$dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid ); |
713 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
720 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
714 |
ModZebra($authid,"recordDelete","authorityserver",GetAuthority($authid),undef); |
721 |
ModZebra( $authid, "recordDelete", "authorityserver", undef); |
715 |
my $sth = $dbh->prepare("DELETE FROM auth_header WHERE authid=?"); |
|
|
716 |
$sth->execute($authid); |
717 |
} |
722 |
} |
718 |
|
723 |
|
719 |
=head2 ModAuthority |
724 |
=head2 ModAuthority |
Lines 1399-1430
sub AddAuthorityTrees{
Link Here
|
1399 |
|
1404 |
|
1400 |
=head2 merge |
1405 |
=head2 merge |
1401 |
|
1406 |
|
1402 |
$ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto) |
1407 |
$count = merge ( mergefrom, $MARCfrom, [$mergeto, $MARCto] ) |
|
|
1408 |
|
1409 |
Merge biblios linked to authority $mergefrom. |
1410 |
If $mergeto equals mergefrom, the linked biblio field is updated. |
1411 |
If $mergeto is different, the biblio field will be linked to $mergeto. |
1412 |
If $mergeto is missing, the biblio field is deleted. |
1403 |
|
1413 |
|
1404 |
Could add some feature : Migrating from a typecode to an other for instance. |
1414 |
Note: Although $mergefrom and $mergeto will normally be of the same |
1405 |
Then we should add some new parameter : bibliotargettag, authtargettag |
1415 |
authority type, merge also supports moving to another authority type. |
1406 |
|
1416 |
|
1407 |
=cut |
1417 |
=cut |
1408 |
|
1418 |
|
1409 |
sub merge { |
1419 |
sub merge { |
1410 |
my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; |
1420 |
my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; |
|
|
1421 |
return 0 unless $mergefrom > 0; # prevent abuse |
1411 |
my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); |
1422 |
my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); |
1412 |
my $dbh=C4::Context->dbh; |
1423 |
my $dbh=C4::Context->dbh; |
1413 |
my $authfrom = Koha::Authorities->find($mergefrom); |
1424 |
my $authfrom = Koha::Authorities->find($mergefrom); |
1414 |
my $authto = Koha::Authorities->find($mergeto); |
1425 |
my $authto = Koha::Authorities->find($mergeto); |
1415 |
my $authtypefrom = Koha::Authority::Types->find($authfrom->authtypecode); |
1426 |
my $authtypefrom = $authfrom ? Koha::Authority::Types->find($authfrom->authtypecode) : undef; |
1416 |
my $authtypeto = Koha::Authority::Types->find($authto->authtypecode); |
1427 |
my $authtypeto = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef; |
1417 |
|
1428 |
|
1418 |
return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0; |
|
|
1419 |
return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0; |
1420 |
# search the tag to report |
1429 |
# search the tag to report |
1421 |
my $auth_tag_to_report_from = $authtypefrom->auth_tag_to_report; |
1430 |
my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : ''; |
1422 |
my $auth_tag_to_report_to = $authtypeto->auth_tag_to_report; |
1431 |
my $auth_tag_to_report_to = $authtypeto ? $authtypeto->auth_tag_to_report : ''; |
1423 |
|
1432 |
|
1424 |
my @record_to; |
1433 |
my @record_to; |
1425 |
@record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to); |
1434 |
@record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to); |
1426 |
my @record_from; |
1435 |
my @record_from; |
1427 |
@record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from); |
1436 |
@record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $auth_tag_to_report_from && $MARCfrom && $MARCfrom->field($auth_tag_to_report_from); |
1428 |
|
1437 |
|
1429 |
my @reccache; |
1438 |
my @reccache; |
1430 |
# search all biblio tags using this authority. |
1439 |
# search all biblio tags using this authority. |
Lines 1457-1466
sub merge {
Link Here
|
1457 |
$oResult->destroy(); |
1466 |
$oResult->destroy(); |
1458 |
# Get All candidate Tags for the change |
1467 |
# Get All candidate Tags for the change |
1459 |
# (This will reduce the search scope in marc records). |
1468 |
# (This will reduce the search scope in marc records). |
|
|
1469 |
# For a deleted authority record, we scan all auth controlled fields |
1460 |
my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?"; |
1470 |
my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?"; |
1461 |
my $tags_using_authtype = $dbh->selectcol_arrayref( $sql, undef, ( $authtypefrom->authtypecode )); |
1471 |
my $tags_using_authtype = $authtypefrom ? $dbh->selectcol_arrayref( $sql, undef, ( $authtypefrom->authtypecode )) : $dbh->selectcol_arrayref( "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode IS NOT NULL AND authtypecode<>''" ); |
1462 |
my $tags_new; |
1472 |
my $tags_new; |
1463 |
if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){ |
1473 |
if( $authtypefrom && $authtypeto && $authtypeto->authtypecode ne $authtypefrom->authtypecode ) { |
1464 |
$tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode )); |
1474 |
$tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode )); |
1465 |
} |
1475 |
} |
1466 |
|
1476 |
|
Lines 1483-1490
sub merge {
Link Here
|
1483 |
my $tag = $field->tag(); |
1493 |
my $tag = $field->tag(); |
1484 |
next if !defined($auth_number) || $auth_number ne $mergefrom; |
1494 |
next if !defined($auth_number) || $auth_number ne $mergefrom; |
1485 |
$countfrom++; |
1495 |
$countfrom++; |
1486 |
if ( $overwrite && $countfrom > 1 ) { |
1496 |
if ( !$mergeto || ( $overwrite && $countfrom > 1 ) ) { |
1487 |
# remove this duplicate in strict mode |
1497 |
# if mergeto is missing, this indicates a delete |
|
|
1498 |
# Or: remove this duplicate in strict mode |
1488 |
$marcrecord->delete_field($field); |
1499 |
$marcrecord->delete_field($field); |
1489 |
$update = 1; |
1500 |
$update = 1; |
1490 |
next; |
1501 |
next; |