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

(-)a/C4/ImportBatch.pm (-10 lines)
Lines 1625-1640 sub _create_import_record { Link Here
1625
    return $import_record_id;
1625
    return $import_record_id;
1626
}
1626
}
1627
1627
1628
sub _update_import_record_marc {
1629
    my ($import_record_id, $marc_record, $marc_type) = @_;
1630
1631
    my $dbh = C4::Context->dbh;
1632
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
1633
                             WHERE  import_record_id = ?");
1634
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id);
1635
    $sth->finish();
1636
}
1637
1638
sub _add_auth_fields {
1628
sub _add_auth_fields {
1639
    my ($import_record_id, $marc_record) = @_;
1629
    my ($import_record_id, $marc_record) = @_;
1640
1630
(-)a/Koha/Import/Record.pm (-10 / +2 lines)
Lines 37-51 Koha::Import::Record - Koha Import Record Object class Link Here
37
37
38
Returns a MARC::Record object
38
Returns a MARC::Record object
39
39
40
    my $marc_record = $import_record->get_marc_record({ embed_items => $embed_items })
40
    my $marc_record = $import_record->get_marc_record()
41
42
If $embed_items is true then items from import_items are embedded into the
43
MARC::Record returned
44
41
45
=cut
42
=cut
46
43
47
sub get_marc_record {
44
sub get_marc_record {
48
    my ($self, $args) = @_;
45
    my ($self) = @_;
49
46
50
    my $marcflavour = C4::Context->preference('marcflavour');
47
    my $marcflavour = C4::Context->preference('marcflavour');
51
48
Lines 56-66 sub get_marc_record { Link Here
56
53
57
    my $record = MARC::Record->new_from_xml($self->marcxml, $self->encoding, $format);
54
    my $record = MARC::Record->new_from_xml($self->marcxml, $self->encoding, $format);
58
55
59
    if ($self->record_type eq 'biblio' && $args->{embed_items}) {
60
        require C4::ImportBatch;
61
        C4::ImportBatch::EmbedItemsInImportBiblio($record, $self->id);
62
    }
63
64
    return $record;
56
    return $record;
65
}
57
}
66
58
(-)a/catalogue/showmarc.pl (-1 / +1 lines)
Lines 62-68 if ($importid) { Link Here
62
            $format = 'UNIMARCAUTH';
62
            $format = 'UNIMARCAUTH';
63
        }
63
        }
64
64
65
        $record = $import_record->get_marc_record({ embed_items => 1 });
65
        $record = $import_record->get_marc_record();
66
    }
66
    }
67
}
67
}
68
else {
68
else {
(-)a/t/db_dependent/ImportBatch.t (-11 / +6 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 19;
4
use Test::More tests => 18;
5
use utf8;
5
use utf8;
6
use File::Basename;
6
use File::Basename;
7
use File::Temp qw/tempfile/;
7
use File::Temp qw/tempfile/;
Lines 88-95 is_deeply( $importbatch1, $sample_import_batch1, Link Here
88
    "GetImportBatch returns the right informations about $sample_import_batch1" );
88
    "GetImportBatch returns the right informations about $sample_import_batch1" );
89
89
90
my $record = MARC::Record->new;
90
my $record = MARC::Record->new;
91
# FIXME Create another MARC::Record which won't be modified
92
# AddItemsToImportBiblio will remove the items field from the record passed in parameter.
93
my $original_record = MARC::Record->new;
91
my $original_record = MARC::Record->new;
94
$record->leader('03174nam a2200445 a 4500');
92
$record->leader('03174nam a2200445 a 4500');
95
$original_record->leader('03174nam a2200445 a 4500');
93
$original_record->leader('03174nam a2200445 a 4500');
Lines 162-176 my $import_record_id = AddBiblioToBatch( $id_import_batch1, 0, $record, 'utf8', Link Here
162
AddItemsToImportBiblio( $id_import_batch1, $import_record_id, $record, 0 );
160
AddItemsToImportBiblio( $id_import_batch1, $import_record_id, $record, 0 );
163
161
164
my $import_record = Koha::Import::Records->find($import_record_id);
162
my $import_record = Koha::Import::Records->find($import_record_id);
165
my $record_from_import_biblio_with_items = $import_record->get_marc_record({ embed_items => 1 });
163
my $record_from_import_biblio = $import_record->get_marc_record();
166
$original_record->leader($record_from_import_biblio_with_items->leader());
164
167
is_deeply( $record_from_import_biblio_with_items, $original_record, 'Koha::Import::Record::get_marc_record should return the record with items if specified' );
165
$original_record->leader($record_from_import_biblio->leader());
168
my $utf8_field = $record_from_import_biblio_with_items->subfield($item_tag, 'e');
166
is_deeply( $record_from_import_biblio, $original_record, 'Koha::Import::Record::get_marc_record should return the record in original state' );
167
my $utf8_field = $record_from_import_biblio->subfield($item_tag, 'e');
169
is($utf8_field, 'my edition ❤');
168
is($utf8_field, 'my edition ❤');
170
$original_record->delete_fields($original_record->field($item_tag)); #Remove items fields
171
my $record_from_import_biblio_without_items = $import_record->get_marc_record();
172
$original_record->leader($record_from_import_biblio_without_items->leader());
173
is_deeply( $record_from_import_biblio_without_items, $original_record, 'Koha::Import::Record::get_marc_record should return the record without items by default' );
174
169
175
my $another_biblio = $builder->build_sample_biblio;
170
my $another_biblio = $builder->build_sample_biblio;
176
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber );
171
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber );
(-)a/tools/showdiffmarc.pl (-2 / +1 lines)
Lines 77-83 if( $record ) { Link Here
77
77
78
if( $importid ) {
78
if( $importid ) {
79
    my $import_record = Koha::Import::Records->find($importid);
79
    my $import_record = Koha::Import::Records->find($importid);
80
    my $recordImportid = $import_record->get_marc_record({ embed_items => 1 });
80
    my $recordImportid = $import_record->get_marc_record();
81
    $formatted2 = $recordImportid->as_formatted;
81
    $formatted2 = $recordImportid->as_formatted;
82
    my $biblio = GetImportBiblios($importid);
82
    my $biblio = GetImportBiblios($importid);
83
    $importTitle = $biblio->[0]->{'title'};
83
    $importTitle = $biblio->[0]->{'title'};
84
- 

Return to bug 30779