|
Lines 685-691
sub AddAuthority {
Link Here
|
| 685 |
)->store(); |
685 |
)->store(); |
| 686 |
$authority->discard_changes(); |
686 |
$authority->discard_changes(); |
| 687 |
$authid = $authority->authid; |
687 |
$authid = $authority->authid; |
| 688 |
logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
|
|
| 689 |
} else { |
688 |
} else { |
| 690 |
$action = 'modify'; |
689 |
$action = 'modify'; |
| 691 |
$authority = Koha::Authorities->find($authid); |
690 |
$authority = Koha::Authorities->find($authid); |
|
Lines 715-720
sub AddAuthority {
Link Here
|
| 715 |
} |
714 |
} |
| 716 |
|
715 |
|
| 717 |
_after_authority_action_hooks( { action => $action, authority_id => $authid } ); |
716 |
_after_authority_action_hooks( { action => $action, authority_id => $authid } ); |
|
|
717 |
|
| 718 |
if ( $action eq 'create' && C4::Context->preference("AuthoritiesLog") ) { |
| 719 |
$authority->discard_changes; |
| 720 |
logaction( |
| 721 |
"AUTHORITIES", "ADD", $authid, "authority", undef, |
| 722 |
_authority_log_data( $authority, $record ) |
| 723 |
); |
| 724 |
} |
| 725 |
|
| 718 |
return ($authid); |
726 |
return ($authid); |
| 719 |
} |
727 |
} |
| 720 |
|
728 |
|
|
Lines 744-750
sub DelAuthority {
Link Here
|
| 744 |
Koha::Authority::MergeRequests->search($condition)->delete; |
752 |
Koha::Authority::MergeRequests->search($condition)->delete; |
| 745 |
merge( { mergefrom => $authid } ) if !$skip_merge; |
753 |
merge( { mergefrom => $authid } ) if !$skip_merge; |
| 746 |
|
754 |
|
| 747 |
my $authority = Koha::Authorities->find($authid); |
755 |
my $authority = Koha::Authorities->find($authid); |
|
|
756 |
my $deleted_marc = eval { $authority->record } if C4::Context->preference("AuthoritiesLog"); |
| 757 |
my $deleted_data = |
| 758 |
C4::Context->preference("AuthoritiesLog") |
| 759 |
? _authority_log_data( $authority, $deleted_marc ) |
| 760 |
: undef; |
| 761 |
|
| 748 |
$schema->txn_do( |
762 |
$schema->txn_do( |
| 749 |
sub { |
763 |
sub { |
| 750 |
$authority->move_to_deleted; #FIXME We should define 'move' .. |
764 |
$authority->move_to_deleted; #FIXME We should define 'move' .. |
|
Lines 752-758
sub DelAuthority {
Link Here
|
| 752 |
} |
766 |
} |
| 753 |
); |
767 |
); |
| 754 |
|
768 |
|
| 755 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
769 |
logaction( "AUTHORITIES", "DELETE", $authid, "authority", undef, $deleted_data ) |
|
|
770 |
if C4::Context->preference("AuthoritiesLog"); |
| 756 |
unless ($skip_record_index) { |
771 |
unless ($skip_record_index) { |
| 757 |
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
772 |
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
| 758 |
$indexer->index_records( $authid, "recordDelete", "authorityserver", undef ); |
773 |
$indexer->index_records( $authid, "recordDelete", "authorityserver", undef ); |
|
Lines 784-796
sub ModAuthority {
Link Here
|
| 784 |
my $skip_record_index = $params->{skip_record_index} || 0; |
799 |
my $skip_record_index = $params->{skip_record_index} || 0; |
| 785 |
|
800 |
|
| 786 |
my $oldrecord = GetAuthority($authid); |
801 |
my $oldrecord = GetAuthority($authid); |
|
|
802 |
my ( $original_data, $original_marc ); |
| 803 |
if ( C4::Context->preference("AuthoritiesLog") ) { |
| 804 |
my $old_authority = Koha::Authorities->find($authid); |
| 805 |
$original_data = _authority_log_data( $old_authority, $oldrecord ); |
| 806 |
} |
| 787 |
|
807 |
|
| 788 |
#Now rewrite the $record to table with an add |
808 |
#Now rewrite the $record to table with an add |
| 789 |
$authid = AddAuthority( $record, $authid, $authtypecode, { skip_record_index => $skip_record_index } ); |
809 |
$authid = AddAuthority( $record, $authid, $authtypecode, { skip_record_index => $skip_record_index } ); |
| 790 |
merge( { mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record } ) |
810 |
merge( { mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record } ) |
| 791 |
if !$params->{skip_merge}; |
811 |
if !$params->{skip_merge}; |
| 792 |
logaction( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted ) |
812 |
|
| 793 |
if C4::Context->preference("AuthoritiesLog"); |
813 |
if ( C4::Context->preference("AuthoritiesLog") ) { |
|
|
814 |
my $new_authority = Koha::Authorities->find($authid); |
| 815 |
logaction( |
| 816 |
"AUTHORITIES", "MODIFY", $authid, |
| 817 |
_authority_log_data( $new_authority, $record ), |
| 818 |
undef, $original_data |
| 819 |
); |
| 820 |
} |
| 821 |
|
| 794 |
return $authid; |
822 |
return $authid; |
| 795 |
} |
823 |
} |
| 796 |
|
824 |
|
|
Lines 1495-1500
sub _get_authid_subfield {
Link Here
|
| 1495 |
return $field->subfield('9') || $field->subfield('3'); |
1523 |
return $field->subfield('9') || $field->subfield('3'); |
| 1496 |
} |
1524 |
} |
| 1497 |
|
1525 |
|
|
|
1526 |
sub _marc_record_to_diffable { |
| 1527 |
my ($record) = @_; |
| 1528 |
return {} unless defined $record; |
| 1529 |
my %marc; |
| 1530 |
for my $field ( $record->fields ) { |
| 1531 |
my $tag = $field->tag; |
| 1532 |
if ( $field->is_control_field ) { |
| 1533 |
$marc{$tag} = $field->data; |
| 1534 |
} else { |
| 1535 |
my $ind1 = $field->indicator(1); |
| 1536 |
my $ind2 = $field->indicator(2); |
| 1537 |
my $formatted = "$ind1$ind2"; |
| 1538 |
for my $subfield ( $field->subfields ) { |
| 1539 |
$formatted .= " \$$subfield->[0] $subfield->[1]"; |
| 1540 |
} |
| 1541 |
push @{ $marc{$tag} }, $formatted; |
| 1542 |
} |
| 1543 |
} |
| 1544 |
return \%marc; |
| 1545 |
} |
| 1546 |
|
| 1547 |
sub _authority_log_data { |
| 1548 |
my ( $authority, $marc_record ) = @_; |
| 1549 |
my %data = %{ $authority->unblessed }; |
| 1550 |
delete $data{marcxml}; |
| 1551 |
$data{_marc} = _marc_record_to_diffable($marc_record); |
| 1552 |
return \%data; |
| 1553 |
} |
| 1554 |
|
| 1498 |
=head2 GetHeaderAuthority |
1555 |
=head2 GetHeaderAuthority |
| 1499 |
|
1556 |
|
| 1500 |
$ref= &GetHeaderAuthority( $authid) |
1557 |
$ref= &GetHeaderAuthority( $authid) |