Bug 30888: Copy info to deleted table
Test plan: Delete an authority from the interface. Check presence in the table deletedauth_header, verify that the correct authid and authtype have been inserted. Bonus: Check leader position 05 in deleted table. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
2261e06b82
commit
ad45e5650b
2 changed files with 53 additions and 13 deletions
|
@ -21,6 +21,8 @@ package C4::AuthoritiesMarc;
|
|||
use strict;
|
||||
use warnings;
|
||||
use MARC::Field;
|
||||
use Scalar::Util qw(blessed);
|
||||
use Try::Tiny qw( try catch );
|
||||
|
||||
use C4::Context;
|
||||
use C4::Biblio qw( ModBiblio );
|
||||
|
@ -34,6 +36,7 @@ use Koha::Authorities;
|
|||
use Koha::Authority::MergeRequests;
|
||||
use Koha::Authority::Types;
|
||||
use Koha::Authority;
|
||||
use Koha::Database;
|
||||
use Koha::Libraries;
|
||||
use Koha::RecordProcessor;
|
||||
use Koha::SearchEngine;
|
||||
|
@ -737,21 +740,35 @@ sub DelAuthority {
|
|||
my $skip_merge = $params->{skip_merge};
|
||||
my $skip_record_index = $params->{skip_record_index} || 0;
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $schema = Koha::Database->schema;
|
||||
try {
|
||||
# TODO Make following lines part of transaction? Does merge take too long?
|
||||
# Remove older pending merge requests for $authid to itself. (See bug 22437)
|
||||
my $condition = { authid => $authid, authid_new => [ undef, 0, $authid ], done => 0 };
|
||||
Koha::Authority::MergeRequests->search($condition)->delete;
|
||||
merge( { mergefrom => $authid } ) if !$skip_merge;
|
||||
|
||||
# Remove older pending merge requests for $authid to itself. (See bug 22437)
|
||||
my $condition = { authid => $authid, authid_new => [ undef, 0, $authid ], done => 0 };
|
||||
Koha::Authority::MergeRequests->search($condition)->delete;
|
||||
my $authority = Koha::Authorities->find($authid);
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
$authority->move_to_deleted; #FIXME We should define 'move' ..
|
||||
$authority->delete;
|
||||
}
|
||||
);
|
||||
|
||||
merge( { mergefrom => $authid } ) if !$skip_merge;
|
||||
$dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
|
||||
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
|
||||
unless ($skip_record_index) {
|
||||
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
|
||||
$indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
|
||||
}
|
||||
|
||||
_after_authority_action_hooks( { action => 'delete', authority_id => $authid } );
|
||||
logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
|
||||
unless ($skip_record_index) {
|
||||
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
|
||||
$indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
|
||||
}
|
||||
_after_authority_action_hooks( { action => 'delete', authority_id => $authid } );
|
||||
} catch {
|
||||
if ( blessed $_ && $_->can('rethrow') ) {
|
||||
$_->rethrow();
|
||||
} else {
|
||||
die "Deleting authority $authid failed: " . $_;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
=head2 ModAuthority
|
||||
|
|
|
@ -309,6 +309,29 @@ sub to_api_mapping {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 move_to_deleted
|
||||
|
||||
$authority->move_to_deleted;
|
||||
|
||||
This sub actually copies the authority (to be deleted) into the
|
||||
deletedauth_header table. (Just as the other ones.)
|
||||
|
||||
=cut
|
||||
|
||||
sub move_to_deleted {
|
||||
my ($self) = @_;
|
||||
my $data = $self->unblessed;
|
||||
delete $data->{modification_time}; # trigger new timestamp
|
||||
|
||||
# Set leader 05 (deleted)
|
||||
my $format = C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'UNIMARCAUTH' : 'MARC21';
|
||||
my $record = $self->record;
|
||||
$record->leader( substr( $record->leader, 0, 5 ) . 'd' . substr( $record->leader, 6, 18 ) );
|
||||
$data->{marcxml} = $record->as_xml_record($format);
|
||||
|
||||
return Koha::Database->new->schema->resultset('DeletedauthHeader')->create($data);
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
|
||||
=head3 _type
|
||||
|
|
Loading…
Reference in a new issue