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

(-)a/C4/ImportBatch.pm (-4 / +6 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
use C4::Context;
23
use C4::Context;
24
use C4::Koha   qw( GetNormalizedISBN );
24
use C4::Koha qw( GetNormalizedISBN );
25
use C4::Biblio qw(
25
use C4::Biblio qw(
26
    AddBiblio
26
    AddBiblio
27
    DelBiblio
27
    DelBiblio
Lines 30-36 use C4::Biblio qw( Link Here
30
    ModBiblio
30
    ModBiblio
31
    TransformMarcToKoha
31
    TransformMarcToKoha
32
);
32
);
33
use C4::Items   qw( AddItemFromMarc ModItemFromMarc );
33
use C4::Items qw( AddItemFromMarc ModItemFromMarc );
34
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars );
34
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars );
35
use C4::AuthoritiesMarc
35
use C4::AuthoritiesMarc
36
    qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading );
36
    qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading );
Lines 1281-1287 Returns an array of imported item branches. Link Here
1281
=cut
1281
=cut
1282
1282
1283
sub GetImportItemsBranches {
1283
sub GetImportItemsBranches {
1284
    my ( $batch_id ) = @_;
1284
    my ($batch_id) = @_;
1285
1285
1286
    my $dbh   = C4::Context->dbh;
1286
    my $dbh   = C4::Context->dbh;
1287
    my $query = "SELECT import_items_id, import_items.marcxml, encoding
1287
    my $query = "SELECT import_items_id, import_items.marcxml, encoding
Lines 1297-1304 sub GetImportItemsBranches { Link Here
1297
    my @branch;
1297
    my @branch;
1298
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1298
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1299
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1299
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1300
1300
    foreach my $row (@$results) {
1301
    foreach my $row (@$results) {
1301
        my $item_marc    = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1302
        my $item_marc =
1303
            MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1302
        push @branch, $item_marc->subfield( $homebranchfield,    $homebranchsubfield );
1304
        push @branch, $item_marc->subfield( $homebranchfield,    $homebranchsubfield );
1303
        push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );
1305
        push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );
1304
    }
1306
    }
(-)a/t/db_dependent/ImportBatch.t (-6 / +17 lines)
Lines 274-281 subtest "_batchCommitItems" => sub { Link Here
274
        'Error correctly set when import item has duplicate barcode and action always_add'
274
        'Error correctly set when import item has duplicate barcode and action always_add'
275
    );
275
    );
276
276
277
    $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => {
277
    $import_item = $builder->build_object(
278
        marcxml => q{<?xml version="1.0" encoding="UTF-8"?>
278
        {
279
            class => 'Koha::Import::Record::Items',
280
            value => {
281
                marcxml => q{<?xml version="1.0" encoding="UTF-8"?>
279
<collection
282
<collection
280
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
283
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
281
  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
284
  xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
Lines 293-306 subtest "_batchCommitItems" => sub { Link Here
293
</record>
296
</record>
294
</collection>
297
</collection>
295
        },
298
        },
296
    }});
299
            }
300
        }
301
    );
297
302
298
    ( $num_items_added, $num_items_replaced, $num_items_errored ) =
303
    ( $num_items_added, $num_items_replaced, $num_items_errored ) =
299
        C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add',64 );
304
        C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add', 64 );
300
    is( $num_items_errored, 1, "Item with wrong branchcode fails when action always_add" );
305
    is( $num_items_errored, 1, "Item with wrong branchcode fails when action always_add" );
301
    $import_item->discard_changes();
306
    $import_item->discard_changes();
302
    is( $import_item->status, 'error', "Import item marked as error when wrong branchcode detected and action always_add");
307
    is(
303
    is( $import_item->import_error, 'Branch code WBRC missing', 'Error correctly set when import item has a wrong branchcode detected and action always_add' );
308
        $import_item->status, 'error',
309
        "Import item marked as error when wrong branchcode detected and action always_add"
310
    );
311
    is(
312
        $import_item->import_error, 'Branch code WBRC missing',
313
        'Error correctly set when import item has a wrong branchcode detected and action always_add'
314
    );
304
};
315
};
305
316
306
subtest "RecordsFromMarcPlugin" => sub {
317
subtest "RecordsFromMarcPlugin" => sub {
(-)a/tools/manage-marc-import.pl (-3 / +2 lines)
Lines 28-34 use Try::Tiny; Link Here
28
# Koha modules used
28
# Koha modules used
29
use C4::Context;
29
use C4::Context;
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Auth   qw( get_template_and_user );
31
use C4::Auth qw( get_template_and_user );
32
use C4::Output qw( output_html_with_http_headers );
32
use C4::Output qw( output_html_with_http_headers );
33
use C4::ImportBatch
33
use C4::ImportBatch
34
    qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches GetBadBranchesImportItems );
34
    qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches GetBadBranchesImportItems );
Lines 96-102 if ( $op eq "" ) { Link Here
96
        import_batches_list( $template, $offset, $results_per_page );
96
        import_batches_list( $template, $offset, $results_per_page );
97
    } else {
97
    } else {
98
        my @import_items_branches = GetImportItemsBranches($import_batch_id);
98
        my @import_items_branches = GetImportItemsBranches($import_batch_id);
99
        my @import_items = GetBadBranchesImportItems($import_batch_id);
99
        my @import_items          = GetBadBranchesImportItems($import_batch_id);
100
        my @bad_item_titles;
100
        my @bad_item_titles;
101
        my @missing_branches;
101
        my @missing_branches;
102
        foreach my $item (@import_items) {
102
        foreach my $item (@import_items) {
103
- 

Return to bug 21272