Lines 28-33
use C4::Charset;
Link Here
|
28 |
use C4::Log; |
28 |
use C4::Log; |
29 |
use Koha::MetadataRecord::Authority; |
29 |
use Koha::MetadataRecord::Authority; |
30 |
use Koha::Authorities; |
30 |
use Koha::Authorities; |
|
|
31 |
use Koha::Authority::MergeRequest; |
31 |
use Koha::Authority::Types; |
32 |
use Koha::Authority::Types; |
32 |
use Koha::Authority; |
33 |
use Koha::Authority; |
33 |
use Koha::SearchEngine; |
34 |
use Koha::SearchEngine; |
Lines 692-705
sub DelAuthority {
Link Here
|
692 |
my ( $params ) = @_; |
693 |
my ( $params ) = @_; |
693 |
my $authid = $params->{authid} || return; |
694 |
my $authid = $params->{authid} || return; |
694 |
my $dbh=C4::Context->dbh; |
695 |
my $dbh=C4::Context->dbh; |
695 |
|
696 |
merge({ mergefrom => $authid, MARCfrom => GetAuthority($authid) }); |
696 |
unless( C4::Context->preference('dontmerge') eq '1' ) { |
|
|
697 |
&merge({ mergefrom => $authid, MARCfrom => GetAuthority($authid) }); |
698 |
} else { |
699 |
# save a record in need_merge_authorities table |
700 |
my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) VALUES (?,?)"; |
701 |
$dbh->do( $sqlinsert, undef, $authid, 0 ); |
702 |
} |
703 |
$dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid ); |
697 |
$dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid ); |
704 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
698 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
705 |
ModZebra( $authid, "recordDelete", "authorityserver", undef); |
699 |
ModZebra( $authid, "recordDelete", "authorityserver", undef); |
Lines 714-740
Modifies authority record, optionally updates attached biblios.
Link Here
|
714 |
=cut |
708 |
=cut |
715 |
|
709 |
|
716 |
sub ModAuthority { |
710 |
sub ModAuthority { |
717 |
my ($authid,$record,$authtypecode)=@_; # deprecated $merge parameter removed |
711 |
my ( $authid, $record, $authtypecode ) = @_; |
718 |
|
712 |
my $oldrecord = GetAuthority($authid); |
719 |
my $dbh=C4::Context->dbh; |
713 |
#Now rewrite the $record to table with an add |
720 |
#Now rewrite the $record to table with an add |
714 |
$authid = AddAuthority($record, $authid, $authtypecode); |
721 |
my $oldrecord=GetAuthority($authid); |
715 |
merge({ mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record }); |
722 |
$authid=AddAuthority($record,$authid,$authtypecode); |
716 |
logaction( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog"); |
723 |
|
717 |
return $authid; |
724 |
# If a library thinks that updating all biblios is a long process and wishes |
|
|
725 |
# to leave that to a cron job, use misc/migration_tools/merge_authority.pl. |
726 |
# In that case set system preference "dontmerge" to 1. Otherwise biblios will |
727 |
# be updated. |
728 |
unless(C4::Context->preference('dontmerge') eq '1'){ |
729 |
&merge({ mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record }); |
730 |
} else { |
731 |
# save a record in need_merge_authorities table |
732 |
my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ". |
733 |
"VALUES (?,?)"; |
734 |
$dbh->do($sqlinsert,undef,($authid,0)); |
735 |
} |
736 |
logaction( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog"); |
737 |
return $authid; |
738 |
} |
718 |
} |
739 |
|
719 |
|
740 |
=head2 GetAuthorityXML |
720 |
=head2 GetAuthorityXML |
Lines 1395-1400
sub AddAuthorityTrees{
Link Here
|
1395 |
[ mergeto => $mergeto, ] |
1375 |
[ mergeto => $mergeto, ] |
1396 |
[ MARCto => $MARCto, ] |
1376 |
[ MARCto => $MARCto, ] |
1397 |
[ biblionumbers => [ $a, $b, $c ], ] |
1377 |
[ biblionumbers => [ $a, $b, $c ], ] |
|
|
1378 |
[ override_limit => 1, ] |
1398 |
}); |
1379 |
}); |
1399 |
|
1380 |
|
1400 |
Merge biblios linked to authority $mergefrom. |
1381 |
Merge biblios linked to authority $mergefrom. |
Lines 1405-1410
If $mergeto is missing, the biblio field is deleted.
Link Here
|
1405 |
Normally all biblio records linked to $mergefrom, will be considered. But |
1386 |
Normally all biblio records linked to $mergefrom, will be considered. But |
1406 |
you can pass specific numbers via the biblionumbers parameter. |
1387 |
you can pass specific numbers via the biblionumbers parameter. |
1407 |
|
1388 |
|
|
|
1389 |
The parameter override_limit is used by the cron job to force larger |
1390 |
postponed merges. |
1391 |
|
1408 |
Note: Although $mergefrom and $mergeto will normally be of the same |
1392 |
Note: Although $mergefrom and $mergeto will normally be of the same |
1409 |
authority type, merge also supports moving to another authority type. |
1393 |
authority type, merge also supports moving to another authority type. |
1410 |
|
1394 |
|
Lines 1416-1435
sub merge {
Link Here
|
1416 |
my $MARCfrom = $params->{MARCfrom}; |
1400 |
my $MARCfrom = $params->{MARCfrom}; |
1417 |
my $mergeto = $params->{mergeto}; |
1401 |
my $mergeto = $params->{mergeto}; |
1418 |
my $MARCto = $params->{MARCto}; |
1402 |
my $MARCto = $params->{MARCto}; |
1419 |
my @biblionumbers = $params->{biblionumbers} |
1403 |
my $override_limit = $params->{override_limit}; |
1420 |
# If we do not have biblionumbers, we get all linked biblios |
1404 |
|
1421 |
? @{ $params->{biblionumbers} } |
1405 |
# If we do not have biblionumbers, we get all linked biblios if the |
1422 |
: Koha::Authorities->linked_biblionumbers({ authid => $mergefrom }); |
1406 |
# number of linked records does not exceed the limit UNLESS we override. |
|
|
1407 |
my @biblionumbers; |
1408 |
if( $params->{biblionumbers} ) { |
1409 |
@biblionumbers = @{ $params->{biblionumbers} }; |
1410 |
} elsif( $override_limit ) { |
1411 |
@biblionumbers = Koha::Authorities->linked_biblionumbers({ authid => $mergefrom }); |
1412 |
} else { # now first check number of linked records |
1413 |
my $max = C4::Context->preference('AuthorityMergeLimit') // 0; |
1414 |
my $hits = Koha::Authorities->get_usage_count({ authid => $mergefrom }); |
1415 |
if( $hits > 0 && $hits <= $max ) { |
1416 |
@biblionumbers = Koha::Authorities->linked_biblionumbers({ authid => $mergefrom }); |
1417 |
} elsif( $hits > $max ) { #postpone this merge to the cron job |
1418 |
Koha::Authority::MergeRequest->new({ |
1419 |
authid => $mergefrom, |
1420 |
oldrecord => $MARCfrom, |
1421 |
authid_new => $mergeto, |
1422 |
})->store; |
1423 |
} |
1424 |
} |
1423 |
return 0 if !@biblionumbers; |
1425 |
return 0 if !@biblionumbers; |
1424 |
|
1426 |
|
1425 |
my $counteditedbiblio = 0; |
1427 |
# Search authtypes and reporting tags |
1426 |
my $dbh = C4::Context->dbh; |
|
|
1427 |
my $authfrom = Koha::Authorities->find($mergefrom); |
1428 |
my $authfrom = Koha::Authorities->find($mergefrom); |
1428 |
my $authto = Koha::Authorities->find($mergeto); |
1429 |
my $authto = Koha::Authorities->find($mergeto); |
1429 |
my $authtypefrom = $authfrom ? Koha::Authority::Types->find($authfrom->authtypecode) : undef; |
1430 |
my $authtypefrom = $authfrom ? Koha::Authority::Types->find($authfrom->authtypecode) : undef; |
1430 |
my $authtypeto = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef; |
1431 |
my $authtypeto = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef; |
1431 |
|
|
|
1432 |
# search the tag to report |
1433 |
my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : ''; |
1432 |
my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : ''; |
1434 |
my $auth_tag_to_report_to = $authtypeto ? $authtypeto->auth_tag_to_report : ''; |
1433 |
my $auth_tag_to_report_to = $authtypeto ? $authtypeto->auth_tag_to_report : ''; |
1435 |
|
1434 |
|
Lines 1441-1446
sub merge {
Link Here
|
1441 |
# Get All candidate Tags for the change |
1440 |
# Get All candidate Tags for the change |
1442 |
# (This will reduce the search scope in marc records). |
1441 |
# (This will reduce the search scope in marc records). |
1443 |
# For a deleted authority record, we scan all auth controlled fields |
1442 |
# For a deleted authority record, we scan all auth controlled fields |
|
|
1443 |
my $dbh = C4::Context->dbh; |
1444 |
my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?"; |
1444 |
my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?"; |
1445 |
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<>''" ); |
1445 |
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<>''" ); |
1446 |
my $tags_new; |
1446 |
my $tags_new; |
Lines 1458-1463
sub merge {
Link Here
|
1458 |
# And we need to add $9 in order not to duplicate |
1458 |
# And we need to add $9 in order not to duplicate |
1459 |
$skip_subfields->{9} = 1 if !$overwrite; |
1459 |
$skip_subfields->{9} = 1 if !$overwrite; |
1460 |
|
1460 |
|
|
|
1461 |
my $counteditedbiblio = 0; |
1461 |
foreach my $biblionumber ( @biblionumbers ) { |
1462 |
foreach my $biblionumber ( @biblionumbers ) { |
1462 |
my $marcrecord = GetMarcBiblio( $biblionumber ); |
1463 |
my $marcrecord = GetMarcBiblio( $biblionumber ); |
1463 |
next if !$marcrecord; |
1464 |
next if !$marcrecord; |