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

(-)a/C4/ImportBatch.pm (+70 lines)
Lines 41-46 use Koha::SearchEngine::Indexer; Link Here
41
use Koha::Plugins::Handler;
41
use Koha::Plugins::Handler;
42
use Koha::Logger;
42
use Koha::Logger;
43
use List::MoreUtils qw( uniq any );
43
use List::MoreUtils qw( uniq any );
44
use Array::Utils qw( array_minus );
44
45
45
our (@ISA, @EXPORT_OK);
46
our (@ISA, @EXPORT_OK);
46
BEGIN {
47
BEGIN {
Lines 72-77 BEGIN { Link Here
72
      GetImportRecordsRange
73
      GetImportRecordsRange
73
      GetItemNumbersFromImportBatch
74
      GetItemNumbersFromImportBatch
74
      GetImportItemsBranches
75
      GetImportItemsBranches
76
      GetBadBranchesImportItems
75
77
76
      GetImportBatchStatus
78
      GetImportBatchStatus
77
      SetImportBatchStatus
79
      SetImportBatchStatus
Lines 1248-1253 sub GetImportItemsBranches { Link Here
1248
    return uniq @branch;
1250
    return uniq @branch;
1249
}
1251
}
1250
1252
1253
=head2 GetBadBranchesImportItems
1254
1255
  my @results = GetBadBranchesImportItems($batch_id);
1256
1257
Returns an array of bad branches imported items.
1258
1259
=cut
1260
1261
sub GetBadBranchesImportItems {
1262
    my ($batch_id) = @_;
1263
1264
    my $dbh   = C4::Context->dbh;
1265
    my $query = "SELECT import_items_id, import_record_id, import_items.marcxml, encoding
1266
        FROM import_items
1267
        JOIN import_records USING (import_record_id)
1268
        WHERE import_batch_id = ?
1269
        ORDER BY import_items_id";
1270
    my @params;
1271
    push( @params, $batch_id );
1272
    my $sth = $dbh->prepare($query);
1273
    $sth->execute(@params);
1274
    my $results = $sth->fetchall_arrayref( {} );
1275
    my @items;
1276
1277
    my @import_items_branches = GetImportItemsBranches($batch_id);
1278
    my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
1279
    my @missing_branches = array_minus( @import_items_branches, @branches );
1280
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1281
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1282
1283
    foreach my $row (@$results) {
1284
        my $item_marc =
1285
            MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1286
        my $title = GetTitleImportRecord( $row->{'import_record_id'} );
1287
        foreach my $branch (@missing_branches) {   
1288
            if ( $item_marc->subfield( $homebranchfield, $homebranchsubfield ) eq $branch ) {
1289
                push @items, { title => $title, branch => $branch };
1290
            }
1291
            if ( $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ) eq $branch ) {
1292
                push @items, { title => $title, branch => $branch };
1293
            }
1294
        }
1295
    }
1296
    $sth->finish();
1297
    return uniq @items;
1298
}
1299
1300
=head2 GetTitleImportRecord
1301
1302
  my $status = GetTitleImportRecord($import_record_id);
1303
1304
=cut
1305
1306
sub GetTitleImportRecord {
1307
    my ($import_record_id) = @_;
1308
1309
    my $dbh = C4::Context->dbh;
1310
    my $sth = $dbh->prepare("SELECT import_record_id, import_records.marcxml, encoding 
1311
        FROM import_records WHERE import_record_id = ?");
1312
    $sth->execute($import_record_id);
1313
    my $record = $sth->fetchall_arrayref( {} );
1314
    my $marc_record =
1315
        MARC::Record->new_from_xml( StripNonXmlChars( $record->[0]->{'marcxml'} ), 'UTF-8', $record->[0]->{'encoding'} );
1316
    $sth->finish();
1317
    my $title = $marc_record->field('245')->subfield('a');
1318
    return $title;
1319
}
1320
1251
=head2 GetBestRecordMatch
1321
=head2 GetBestRecordMatch
1252
1322
1253
  my $record_id = GetBestRecordMatch($import_record_id);
1323
  my $record_id = GetBestRecordMatch($import_record_id);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+11 lines)
Lines 313-318 Link Here
313
                                            </span>
313
                                            </span>
314
                                        </div>
314
                                        </div>
315
                                    [% END %]
315
                                    [% END %]
316
                                    [% IF ( bad_titles ) %]
317
                                        <div class="dialog alert">
318
                                            <span>The problems come from these items:  </span>
319
                                            <span>
320
                                                [% FOREACH title IN titles %]
321
                                                    [% title | html %]
322
                                                     | 
323
                                                [% END %]
324
                                            </span>
325
                                        </div>                                        
326
                                    [% END %]
316
                                </form> <!-- /#import_batch_form -->
327
                                </form> <!-- /#import_batch_form -->
317
                            [% END # /IF can_commit %]
328
                            [% END # /IF can_commit %]
318
                            [% IF ( can_revert ) %]
329
                            [% IF ( can_revert ) %]
(-)a/tools/manage-marc-import.pl (-6 / +15 lines)
Lines 30-42 use C4::Context; Link Here
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 qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches );
33
use C4::ImportBatch qw( GetBadBranchesImportItems CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches );
34
use C4::Matcher;
34
use C4::Matcher;
35
use C4::Labels::Batch;
35
use C4::Labels::Batch;
36
use Koha::BiblioFrameworks;
36
use Koha::BiblioFrameworks;
37
use Koha::BackgroundJob::MARCImportCommitBatch;
37
use Koha::BackgroundJob::MARCImportCommitBatch;
38
use Koha::BackgroundJob::MARCImportRevertBatch;
38
use Koha::BackgroundJob::MARCImportRevertBatch;
39
use Array::Utils qw( array_minus );
39
use Array::Utils qw( array_minus );
40
use List::MoreUtils qw( uniq any );
40
41
41
use Koha::Logger;
42
use Koha::Logger;
42
43
Lines 86-97 if ($op eq "") { Link Here
86
    if ($import_batch_id eq '') {
87
    if ($import_batch_id eq '') {
87
        import_batches_list($template, $offset, $results_per_page);
88
        import_batches_list($template, $offset, $results_per_page);
88
    } else {
89
    } else {
89
        my @import_items_branches = GetImportItemsBranches($import_batch_id);
90
        my @import_items = GetBadBranchesImportItems($import_batch_id);
90
        my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
91
        my @bad_item_titles;
91
        my @missing_branches = array_minus( @import_items_branches, @branches );
92
        my @missing_branches;
93
        foreach my $item (@import_items) {
94
            push @bad_item_titles, $item->{title};
95
            push @missing_branches, $item->{branch};
96
        }
97
        @bad_item_titles = uniq @bad_item_titles;
98
        @missing_branches = uniq @missing_branches;
99
92
        $template->param(
100
        $template->param(
101
            bad_titles => scalar @bad_item_titles,
102
            titles => \@bad_item_titles,
93
            missing_branches => scalar @missing_branches,
103
            missing_branches => scalar @missing_branches,
94
            branches => \@missing_branches
104
            branches => \@missing_branches,
95
        );
105
        );
96
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
106
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
97
    }
107
    }
98
- 

Return to bug 21272