View | Details | Raw Unified | Return to bug 30888
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-14 / +31 lines)
Lines 21-26 package C4::AuthoritiesMarc; Link Here
21
use strict;
21
use strict;
22
use warnings;
22
use warnings;
23
use MARC::Field;
23
use MARC::Field;
24
use Scalar::Util qw(blessed);
25
use Try::Tiny    qw( try catch );
24
26
25
use C4::Context;
27
use C4::Context;
26
use C4::Biblio qw( ModBiblio );
28
use C4::Biblio qw( ModBiblio );
Lines 34-39 use Koha::Authorities; Link Here
34
use Koha::Authority::MergeRequests;
36
use Koha::Authority::MergeRequests;
35
use Koha::Authority::Types;
37
use Koha::Authority::Types;
36
use Koha::Authority;
38
use Koha::Authority;
39
use Koha::Database;
37
use Koha::Libraries;
40
use Koha::Libraries;
38
use Koha::RecordProcessor;
41
use Koha::RecordProcessor;
39
use Koha::SearchEngine;
42
use Koha::SearchEngine;
Lines 718-738 sub DelAuthority { Link Here
718
    my $skip_merge = $params->{skip_merge};
721
    my $skip_merge = $params->{skip_merge};
719
    my $skip_record_index = $params->{skip_record_index} || 0;
722
    my $skip_record_index = $params->{skip_record_index} || 0;
720
723
721
    my $dbh = C4::Context->dbh;
724
    my $schema = Koha::Database->schema;
722
725
    try {
723
    # Remove older pending merge requests for $authid to itself. (See bug 22437)
726
        # TODO Make following lines part of transaction? Does merge take too long?
724
    my $condition = { authid => $authid, authid_new => [undef, 0, $authid], done => 0 };
727
        # Remove older pending merge requests for $authid to itself. (See bug 22437)
725
    Koha::Authority::MergeRequests->search($condition)->delete;
728
        my $condition = { authid => $authid, authid_new => [ undef, 0, $authid ], done => 0 };
726
729
        Koha::Authority::MergeRequests->search($condition)->delete;
727
    merge({ mergefrom => $authid }) if !$skip_merge;
730
        merge( { mergefrom => $authid } ) if !$skip_merge;
728
    $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
731
729
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
732
        my $authority = Koha::Authorities->find($authid);
730
    unless ( $skip_record_index ) {
733
        $schema->txn_do(
731
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
734
            sub {
732
        $indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
735
                $authority->move_to_deleted;    #FIXME We should define 'move' ..
733
    }
736
                $authority->delete;
737
            }
738
        );
734
739
735
    _after_authority_action_hooks({ action => 'delete', authority_id => $authid });
740
        logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
741
        unless ($skip_record_index) {
742
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
743
            $indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
744
        }
745
        _after_authority_action_hooks( { action => 'delete', authority_id => $authid } );
746
    } catch {
747
        if ( blessed $_ && $_->can('rethrow') ) {
748
            $_->rethrow();
749
        } else {
750
            die "Deleting authority $authid failed: " . $_;
751
        }
752
    };
736
}
753
}
737
754
738
=head2 ModAuthority
755
=head2 ModAuthority
(-)a/Koha/Authority.pm (-1 / +24 lines)
Lines 189-194 sub to_api_mapping { Link Here
189
    };
189
    };
190
}
190
}
191
191
192
=head3 move_to_deleted
193
194
    $authority->move_to_deleted;
195
196
    This sub actually copies the authority (to be deleted) into the
197
    deletedauth_header table. (Just as the other ones.)
198
199
=cut
200
201
sub move_to_deleted {
202
    my ($self) = @_;
203
    my $data = $self->unblessed;
204
    delete $data->{modification_time};    # trigger new timestamp
205
206
    # Set leader 05 (deleted)
207
    my $format = C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'UNIMARCAUTH' : 'MARC21';
208
    my $record = $self->record;
209
    $record->leader( substr( $record->leader, 0, 5 ) . 'd' . substr( $record->leader, 6, 18 ) );
210
    $data->{marc}    = $record->as_usmarc;
211
    $data->{marcxml} = $record->as_xml_record($format);
212
213
    return Koha::Database->new->schema->resultset('DeletedauthHeader')->create($data);
214
}
215
192
=head2 Internal methods
216
=head2 Internal methods
193
217
194
=head3 _type
218
=head3 _type
195
- 

Return to bug 30888