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

(-)a/C4/Biblio.pm (+30 lines)
Lines 431-436 sub DelBiblio { Link Here
431
        return $error if $error;
431
        return $error if $error;
432
    }
432
    }
433
433
434
434
    # delete biblio from Koha tables and save in deletedbiblio
435
    # delete biblio from Koha tables and save in deletedbiblio
435
    # must do this *after* _koha_delete_biblioitems, otherwise
436
    # must do this *after* _koha_delete_biblioitems, otherwise
436
    # delete cascade will prevent deletedbiblioitems rows
437
    # delete cascade will prevent deletedbiblioitems rows
Lines 3360-3365 sub _koha_delete_biblio { Link Here
3360
    my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3361
    my $sth = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber=?");
3361
    $sth->execute($biblionumber);
3362
    $sth->execute($biblionumber);
3362
3363
3364
    # FIXME There is a transaction in _koha_delete_biblio_metadata
3365
    # But actually all the following should be done inside a single transaction
3363
    if ( my $data = $sth->fetchrow_hashref ) {
3366
    if ( my $data = $sth->fetchrow_hashref ) {
3364
3367
3365
        # save the record in deletedbiblio
3368
        # save the record in deletedbiblio
Lines 3377-3382 sub _koha_delete_biblio { Link Here
3377
        $bkup_sth->execute(@bind);
3380
        $bkup_sth->execute(@bind);
3378
        $bkup_sth->finish;
3381
        $bkup_sth->finish;
3379
3382
3383
        _koha_delete_biblio_metadata( $biblionumber );
3384
3380
        # delete the biblio
3385
        # delete the biblio
3381
        my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3386
        my $sth2 = $dbh->prepare("DELETE FROM biblio WHERE biblionumber=?");
3382
        $sth2->execute($biblionumber);
3387
        $sth2->execute($biblionumber);
Lines 3438-3443 sub _koha_delete_biblioitems { Link Here
3438
    return;
3443
    return;
3439
}
3444
}
3440
3445
3446
=head2 _koha_delete_biblio_metadata
3447
3448
  $error = _koha_delete_biblio_metadata($biblionumber);
3449
3450
C<$biblionumber> - the biblionumber of the biblio metadata to be deleted
3451
3452
=cut
3453
3454
sub _koha_delete_biblio_metadata {
3455
    my ($biblionumber) = @_;
3456
3457
    my $dbh    = C4::Context->dbh;
3458
    my $schema = Koha::Database->new->schema;
3459
    $schema->txn_do(
3460
        sub {
3461
            $dbh->do( q|
3462
                INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata)
3463
                SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=?
3464
            |,  undef, $biblionumber );
3465
            $dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|,
3466
                undef, $biblionumber );
3467
        }
3468
    );
3469
}
3470
3441
=head1 UNEXPORTED FUNCTIONS
3471
=head1 UNEXPORTED FUNCTIONS
3442
3472
3443
=head2 ModBiblioMarc
3473
=head2 ModBiblioMarc
(-)a/t/db_dependent/Biblio.t (-8 / +23 lines)
Lines 17-37 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 7;
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use List::MoreUtils qw( uniq );
23
use List::MoreUtils qw( uniq );
24
use MARC::Record;
24
use MARC::Record;
25
use t::lib::Mocks qw( mock_preference );
25
use t::lib::Mocks qw( mock_preference );
26
26
27
use Koha::Database;
28
27
BEGIN {
29
BEGIN {
28
    use_ok('C4::Biblio');
30
    use_ok('C4::Biblio');
29
}
31
}
30
32
33
my $schema = Koha::Database->new->schema;
34
$schema->storage->txn_begin;
31
my $dbh = C4::Context->dbh;
35
my $dbh = C4::Context->dbh;
32
# Start transaction
33
$dbh->{AutoCommit} = 0;
34
$dbh->{RaiseError} = 1;
35
36
36
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
37
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
37
    plan tests => 23;
38
    plan tests => 23;
Lines 328-346 sub create_issn_field { Link Here
328
subtest 'MARC21' => sub {
329
subtest 'MARC21' => sub {
329
    plan tests => 31;
330
    plan tests => 31;
330
    run_tests('MARC21');
331
    run_tests('MARC21');
331
    $dbh->rollback;
332
    $schema->storage->txn_rollback;
333
    $schema->storage->txn_begin;
332
};
334
};
333
335
334
subtest 'UNIMARC' => sub {
336
subtest 'UNIMARC' => sub {
335
    plan tests => 31;
337
    plan tests => 31;
336
    run_tests('UNIMARC');
338
    run_tests('UNIMARC');
337
    $dbh->rollback;
339
    $schema->storage->txn_rollback;
340
    $schema->storage->txn_begin;
338
};
341
};
339
342
340
subtest 'NORMARC' => sub {
343
subtest 'NORMARC' => sub {
341
    plan tests => 31;
344
    plan tests => 31;
342
    run_tests('NORMARC');
345
    run_tests('NORMARC');
343
    $dbh->rollback;
346
    $schema->storage->txn_rollback;
347
    $schema->storage->txn_begin;
344
};
348
};
345
349
346
subtest 'IsMarcStructureInternal' => sub {
350
subtest 'IsMarcStructureInternal' => sub {
Lines 362-365 subtest 'IsMarcStructureInternal' => sub { Link Here
362
    is( grep( /^a$/, @internals ), 0, 'no subfield a' );
366
    is( grep( /^a$/, @internals ), 0, 'no subfield a' );
363
};
367
};
364
368
369
subtest 'deletedbiblio_metadata' => sub {
370
    plan tests => 2;
371
372
    my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
373
    my $biblio_metadata = C4::Biblio::GetXmlBiblio( $biblionumber );
374
    C4::Biblio::DelBiblio( $biblionumber );
375
    my ( $moved ) = $dbh->selectrow_array(q|SELECT biblionumber FROM deletedbiblio WHERE biblionumber=?|, undef, $biblionumber);
376
    is( $moved, $biblionumber );
377
    ( $moved ) = $dbh->selectrow_array(q|SELECT biblionumber FROM deletedbiblio_metadata WHERE biblionumber=?|, undef, $biblionumber);
378
    is( $moved, $biblionumber );
379
};
380
365
1;
381
1;
366
- 

Return to bug 18284