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

Return to bug 30888