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

(-)a/C4/Biblio.pm (-4 / +33 lines)
Lines 257-263 sub AddBiblio { Link Here
257
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
257
    _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
258
258
259
    # now add the record
259
    # now add the record
260
    ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
260
    ModBiblioMarc( $record, $biblionumber, $biblioitemnumber, $frameworkcode ) unless $defer_marc_save;
261
261
262
    # update OAI-PMH sets
262
    # update OAI-PMH sets
263
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
263
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 335-341 sub ModBiblio { Link Here
335
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
335
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
336
336
337
    # update the MARC record (that now contains biblio and items) with the new record data
337
    # update the MARC record (that now contains biblio and items) with the new record data
338
    &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
338
    &ModBiblioMarc( $record, $biblionumber, $biblioitemnumber, $frameworkcode );
339
339
340
    # modify the other koha tables
340
    # modify the other koha tables
341
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
341
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
Lines 429-434 sub DelBiblio { Link Here
429
        # delete this biblioitem
429
        # delete this biblioitem
430
        $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );
430
        $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );
431
        return $error if $error;
431
        return $error if $error;
432
433
        $error = _koha_delete_biblio_metadata( $dbh, $biblioitemnumber, $biblionumber );
434
        return $error if $error;
432
    }
435
    }
433
436
434
    # delete biblio from Koha tables and save in deletedbiblio
437
    # delete biblio from Koha tables and save in deletedbiblio
Lines 436-441 sub DelBiblio { Link Here
436
    # delete cascade will prevent deletedbiblioitems rows
439
    # delete cascade will prevent deletedbiblioitems rows
437
    # from being generated by _koha_delete_biblioitems
440
    # from being generated by _koha_delete_biblioitems
438
    $error = _koha_delete_biblio( $dbh, $biblionumber );
441
    $error = _koha_delete_biblio( $dbh, $biblionumber );
442
    return $error if $error;
439
443
440
    logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
444
    logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
441
445
Lines 3438-3448 sub _koha_delete_biblioitems { Link Here
3438
    return;
3442
    return;
3439
}
3443
}
3440
3444
3445
=head2 _koha_delete_biblio_metadata
3446
3447
  $error = _koha_delete_biblio_metadata($dbh, $biblioitemnumber, $biblionumber);
3448
3449
Internal sub for deleting from biblio_metadata table -- also saves to deletedbiblio_metadata
3450
3451
C<$dbh> - the database handle
3452
C<$biblioitemnumber> - the biblioitemnumber of the biblio_metadata to be deleted
3453
3454
=cut
3455
3456
# FIXME: add error handling
3457
3458
sub _koha_delete_biblio_metadata {
3459
    my ( $dbh, $biblioitemnumber ) = @_;
3460
3461
    my $m = Koha::Biblio::Metadatas->find({biblioitemnumber => $biblioitemnumber});
3462
    die "_koha_delete_biblio_metadata($biblioitemnumber):> No biblio_metadata-row!" unless $m;
3463
3464
    my $dm = Koha::Biblio::DeletedMetadatas->new( $m->_result->{_column_data} );
3465
    $dm->store;
3466
    $m->delete();
3467
}
3468
3441
=head1 UNEXPORTED FUNCTIONS
3469
=head1 UNEXPORTED FUNCTIONS
3442
3470
3443
=head2 ModBiblioMarc
3471
=head2 ModBiblioMarc
3444
3472
3445
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3473
  &ModBiblioMarc($newrec,$biblionumber,$biblioitemnumber,$frameworkcode);
3446
3474
3447
Add MARC XML data for a biblio to koha
3475
Add MARC XML data for a biblio to koha
3448
3476
Lines 3453-3459 Function exported, but should NOT be used, unless you really know what you're do Link Here
3453
sub ModBiblioMarc {
3481
sub ModBiblioMarc {
3454
    # pass the MARC::Record to this function, and it will create the records in
3482
    # pass the MARC::Record to this function, and it will create the records in
3455
    # the marcxml field
3483
    # the marcxml field
3456
    my ( $record, $biblionumber, $frameworkcode ) = @_;
3484
    my ( $record, $biblionumber, $biblioitemnumber, $frameworkcode ) = @_;
3457
    if ( !$record ) {
3485
    if ( !$record ) {
3458
        carp 'ModBiblioMarc passed an undefined record';
3486
        carp 'ModBiblioMarc passed an undefined record';
3459
        return;
3487
        return;
Lines 3500-3505 sub ModBiblioMarc { Link Here
3500
    }
3528
    }
3501
3529
3502
    my $metadata = {
3530
    my $metadata = {
3531
        biblioitemnumber => $biblioitemnumber,
3503
        biblionumber => $biblionumber,
3532
        biblionumber => $biblionumber,
3504
        format       => 'marcxml',
3533
        format       => 'marcxml',
3505
        marcflavour  => C4::Context->preference('marcflavour'),
3534
        marcflavour  => C4::Context->preference('marcflavour'),
(-)a/Koha/Biblio/DeletedMetadata.pm (+32 lines)
Line 0 Link Here
1
package Koha::Biblio::DeletedMetadata;
2
3
# This file is part of Koha.
4
#
5
6
use Modern::Perl;
7
8
use Carp;
9
10
use Koha::Database;
11
12
use base qw(Koha::Object);
13
14
=head1 NAME
15
16
Koha::Biblio::DeletedMetadata - Koha Metadata Object class
17
18
=head1 API
19
20
=head2 Class Methods
21
22
=cut
23
24
=head3 type
25
26
=cut
27
28
sub _type {
29
    return 'DeletedbiblioMetadata';
30
}
31
32
1;
(-)a/Koha/Biblio/DeletedMetadatas.pm (+38 lines)
Line 0 Link Here
1
package Koha::Biblio::DeletedMetadatas;
2
3
# This file is part of Koha.
4
#
5
6
use Modern::Perl;
7
8
use Carp;
9
10
use Koha::Database;
11
12
use Koha::Biblio::Metadata;
13
14
use base qw(Koha::Objects);
15
16
=head1 NAME
17
18
Koha::Biblio::DeletedMetadatas - Koha Metadata Object set class
19
20
=head1 API
21
22
=head2 Class Methods
23
24
=cut
25
26
=head3 type
27
28
=cut
29
30
sub _type {
31
    return 'DeletedbiblioMetadata';
32
}
33
34
sub object_class {
35
    return 'Koha::Biblio::DeletedMetadata';
36
}
37
38
1;
(-)a/Koha/Biblio/Metadata.pm (-1 / +1 lines)
Lines 25-31 use base qw(Koha::Object); Link Here
25
25
26
=head1 NAME
26
=head1 NAME
27
27
28
Koha::Metadata - Koha Metadata Object class
28
Koha::Biblio::Metadata - Koha Metadata Object class
29
29
30
=head1 API
30
=head1 API
31
31
(-)a/installer/data/mysql/atomicupdate/Bug-18265-Followup_to_Buuug_17196.sql (+15 lines)
Line 0 Link Here
1
ALTER TABLE biblio_metadata DROP FOREIGN KEY `record_metadata_fk_1`;
2
ALTER TABLE biblio_metadata DROP KEY `biblio_metadata_uniq_key`;
3
ALTER TABLE biblio_metadata ADD COLUMN `biblioitemnumber` int(11) NOT NULL;
4
ALTER TABLE biblio_metadata ADD FOREIGN KEY `biblioitems_metadata_fk_1` (biblioitemnumber) REFERENCES biblioitems (biblioitemnumber) ON DELETE CASCADE ON UPDATE CASCADE;
5
ALTER TABLE biblio_metadata ADD UNIQUE KEY `biblio_metadata_uniq_key` (`biblioitemnumber`, `biblionumber`,`format`,`marcflavour`);
6
7
8
9
ALTER TABLE deletedbiblio_metadata DROP FOREIGN KEY `deletedrecord_metadata_fk_1`;
10
ALTER TABLE deletedbiblio_metadata DROP KEY `deletedbiblio_metadata_uniq_key`;
11
ALTER TABLE deletedbiblio_metadata ADD COLUMN `biblioitemnumber` int(11) NOT NULL;
12
ALTER TABLE deletedbiblio_metadata ADD FOREIGN KEY `deletedbiblioitems_metadata_fk_1` (biblioitemnumber) REFERENCES deletedbiblioitems (biblioitemnumber) ON DELETE CASCADE ON UPDATE CASCADE;
13
ALTER TABLE deletedbiblio_metadata ADD UNIQUE KEY `deletedbiblio_metadata_uniq_key` (`biblioitemnumber`, `biblionumber`,`format`,`marcflavour`);
14
15
(-)a/t/db_dependent/Biblio_crud.t (-1 / +99 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
5
use Modern::Perl;
6
use Test::More;
7
8
use C4::Biblio;
9
use Koha::Biblios;
10
use Koha::Biblio::Metadatas;
11
use Koha::Biblio::DeletedMetadatas;
12
13
14
15
##This test is not intended to fully cover all aspects of Biblio creation and it's linked business objects.
16
##It is simply intended for now to test biblio_metadata-table population.
17
subtest "Scenario: CRUD a Biblio, happy path", \&crudBiblio;
18
sub crudBiblio { plan tests => 9;
19
    my ($record, $kohaBiblio, $deletedKohaBiblio, $biblionumber, $biblioitemnumber, $metadata, $deletedMetadata);
20
    my $title = 'Incurable disease of test apparatuses';
21
    eval {
22
23
    $record = C4::Biblio::TransformKohaToMarc({
24
        title => $title,
25
        isbn  => '0123456789',
26
    });
27
    ok($record,
28
        "Given a fresh Biblio from the top of my head");
29
30
    subtest "Create", sub {
31
        ($biblionumber, $biblioitemnumber) = C4::Biblio::AddBiblio($record,'');
32
        ok($biblionumber && $biblioitemnumber,
33
            "When the Biblio is added to DB");
34
    };
35
36
    subtest "Read", sub {
37
        $kohaBiblio = Koha::Biblios->find($biblionumber);
38
        ok($kohaBiblio,
39
            "Then it can be found from the DB");
40
41
        is($kohaBiblio->biblionumber,
42
            "And it looks like a real biblio");
43
44
        $metadata = Koha::Biblio::Metadatas->find($biblioitemnumber);
45
        ok($metadata,
46
            "When I fetch the Metadata record from DB");
47
48
        is($metadata->format, 'marcxml',
49
            "Then the Metadata record format is 'marcxml'");
50
51
        is($metadata->biblionumber, $biblionumber,
52
            "And biblionumber matches the original Biblio");
53
54
        is($metadata->biblioitemnumber, $biblioitemnumber,
55
            "And the biblioitemnumber matches the original Biblio");
56
57
        #Shouldn't marcflavour be just flavour since we don't always store MARC to the biblio_metadata?
58
        is($metadata->marcflavour, C4::Context->marcformat(),
59
            "And the marcflavour is the default");
60
61
        like($metadata->metadata, qr/$title/,
62
            "And the record itself contains the correct title");
63
    };
64
65
    subtest "Delete", sub {
66
        ok(C4::Biblio::DelBiblio($biblionumber),
67
            "When I delete the Biblio");
68
69
        ok(! Koha::Biblios->find($biblionumber),
70
            "Then I get nothing when I fetch it from DB");
71
72
        $deletedKohaBiblio = Koha::DeletedBiblios->find($biblionumber);
73
        ok($deletedKohaBiblio,
74
            "But I find it in the deletedbiblios");
75
76
        is($deletedKohaBiblio->title, $kohaBiblio->title,
77
            "And the Biblio looks just like before!");
78
79
        ok(! Koha::Biblio::Metadatas->find($biblioitemnumber),
80
            "When I fetch the Metadata record, I get nothing");
81
82
        $deletedMetadata = Koha::Biblio::DeletedMetadatas->find($biblioitemnumber);
83
        ok($deletedMetadata,
84
            "But I found it in the deletedbiblio_metadata");
85
86
        is_deeply($deletedMetadata->_result->{_column_data}, $metadata->_result->{_column_data},
87
            "And the Metadata looks just like before!");
88
    };
89
90
    };
91
    ok(0, $@) if $@;
92
}
93
94
95
96
97
98
done_testing;
99

Return to bug 18265