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 734-754 sub DelAuthority { Link Here
734
    my $skip_merge = $params->{skip_merge};
737
    my $skip_merge = $params->{skip_merge};
735
    my $skip_record_index = $params->{skip_record_index} || 0;
738
    my $skip_record_index = $params->{skip_record_index} || 0;
736
739
737
    my $dbh = C4::Context->dbh;
740
    my $schema = Koha::Database->schema;
738
741
    try {
739
    # Remove older pending merge requests for $authid to itself. (See bug 22437)
742
        # TODO Make following lines part of transaction? Does merge take too long?
740
    my $condition = { authid => $authid, authid_new => [undef, 0, $authid], done => 0 };
743
        # Remove older pending merge requests for $authid to itself. (See bug 22437)
741
    Koha::Authority::MergeRequests->search($condition)->delete;
744
        my $condition = { authid => $authid, authid_new => [ undef, 0, $authid ], done => 0 };
742
745
        Koha::Authority::MergeRequests->search($condition)->delete;
743
    merge({ mergefrom => $authid }) if !$skip_merge;
746
        merge( { mergefrom => $authid } ) if !$skip_merge;
744
    $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
747
745
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
748
        my $authority = Koha::Authorities->find($authid);
746
    unless ( $skip_record_index ) {
749
        $schema->txn_do(
747
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
750
            sub {
748
        $indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
751
                $authority->move_to_deleted;    #FIXME We should define 'move' ..
749
    }
752
                $authority->delete;
753
            }
754
        );
750
755
751
    _after_authority_action_hooks({ action => 'delete', authority_id => $authid });
756
        logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
757
        unless ($skip_record_index) {
758
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
759
            $indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
760
        }
761
        _after_authority_action_hooks( { action => 'delete', authority_id => $authid } );
762
    } catch {
763
        if ( blessed $_ && $_->can('rethrow') ) {
764
            $_->rethrow();
765
        } else {
766
            die "Deleting authority $authid failed: " . $_;
767
        }
768
    };
752
}
769
}
753
770
754
=head2 ModAuthority
771
=head2 ModAuthority
(-)a/Koha/Authority.pm (-1 / +24 lines)
Lines 308-313 sub to_api_mapping { Link Here
308
    };
308
    };
309
}
309
}
310
310
311
=head3 move_to_deleted
312
313
    $authority->move_to_deleted;
314
315
    This sub actually copies the authority (to be deleted) into the
316
    deletedauth_header table. (Just as the other ones.)
317
318
=cut
319
320
sub move_to_deleted {
321
    my ($self) = @_;
322
    my $data = $self->unblessed;
323
    delete $data->{modification_time};    # trigger new timestamp
324
325
    # Set leader 05 (deleted)
326
    my $format = C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'UNIMARCAUTH' : 'MARC21';
327
    my $record = $self->record;
328
    $record->leader( substr( $record->leader, 0, 5 ) . 'd' . substr( $record->leader, 6, 18 ) );
329
    $data->{marc}    = $record->as_usmarc;
330
    $data->{marcxml} = $record->as_xml_record($format);
331
332
    return Koha::Database->new->schema->resultset('DeletedauthHeader')->create($data);
333
}
334
311
=head2 Internal methods
335
=head2 Internal methods
312
336
313
=head3 _type
337
=head3 _type
314
- 

Return to bug 30888