Bugzilla – Attachment 172093 Details for
Bug 30888
Add a table for deletedauthorities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30888: Copy info to deleted table
Bug-30888-Copy-info-to-deleted-table.patch (text/plain), 4.60 KB, created by
Marcel de Rooy
on 2024-09-27 07:49:44 UTC
(
hide
)
Description:
Bug 30888: Copy info to deleted table
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2024-09-27 07:49:44 UTC
Size:
4.60 KB
patch
obsolete
>From 1abf067f5bff2be827e33012921100fa0f7fdd3c Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Tue, 16 Apr 2024 14:29:08 +0000 >Subject: [PATCH] Bug 30888: Copy info to deleted table >Content-Type: text/plain; charset=utf-8 > >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> >--- > C4/AuthoritiesMarc.pm | 45 +++++++++++++++++++++++++++++-------------- > Koha/Authority.pm | 24 +++++++++++++++++++++++ > 2 files changed, 55 insertions(+), 14 deletions(-) > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 1656a2ba9b..6fc73cc09a 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -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; >@@ -734,21 +737,35 @@ sub DelAuthority { > my $skip_merge = $params->{skip_merge}; > my $skip_record_index = $params->{skip_record_index} || 0; > >- my $dbh = C4::Context->dbh; >- >- # 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; >- $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 ); >- } >+ 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; >+ >+ my $authority = Koha::Authorities->find($authid); >+ $schema->txn_do( >+ sub { >+ $authority->move_to_deleted; #FIXME We should define 'move' .. >+ $authority->delete; >+ } >+ ); > >- _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 >diff --git a/Koha/Authority.pm b/Koha/Authority.pm >index 5cfc806b09..7fa444e89a 100644 >--- a/Koha/Authority.pm >+++ b/Koha/Authority.pm >@@ -308,6 +308,30 @@ 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->{marc} = $record->as_usmarc; >+ $data->{marcxml} = $record->as_xml_record($format); >+ >+ return Koha::Database->new->schema->resultset('DeletedauthHeader')->create($data); >+} >+ > =head2 Internal methods > > =head3 _type >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30888
:
165040
|
165041
|
165042
|
165043
|
171850
|
171851
|
172090
|
172091
|
172092
|
172093
|
172094
|
172095
|
172096
|
172097
|
172098
|
172099
|
172549
|
172550
|
172551
|
172552
|
172553