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

(-)a/C4/ImportBatch.pm (+57 lines)
Lines 41-46 use Koha::SearchEngine; Link Here
41
use Koha::SearchEngine::Indexer;
41
use Koha::SearchEngine::Indexer;
42
use Koha::Plugins::Handler;
42
use Koha::Plugins::Handler;
43
use Koha::Logger;
43
use Koha::Logger;
44
use List::MoreUtils qw( uniq );
44
45
45
our ( @ISA, @EXPORT_OK );
46
our ( @ISA, @EXPORT_OK );
46
47
Lines 72-77 BEGIN { Link Here
72
        GetImportBiblios
73
        GetImportBiblios
73
        GetImportRecordsRange
74
        GetImportRecordsRange
74
        GetItemNumbersFromImportBatch
75
        GetItemNumbersFromImportBatch
76
        GetImportItemsBranches
75
77
76
        GetImportBatchStatus
78
        GetImportBatchStatus
77
        SetImportBatchStatus
79
        SetImportBatchStatus
Lines 843-848 sub _batchCommitItems { Link Here
843
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber");
845
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber");
844
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
846
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
845
847
848
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch');
849
            my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield );
850
            my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
851
            my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );
852
853
            my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
854
            my %branches = map { $_ => 1 } @branches;
855
856
            my $missing_branchcode;
857
            $missing_branchcode = $homebranch    if ( !exists( $branches{$homebranch} ) );
858
            $missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) );
859
            if ($missing_branchcode) {
860
                $updsth->bind_param( 1, 'error' );
861
                $updsth->bind_param( 2, undef );
862
                $updsth->bind_param( 3, "Branch code $missing_branchcode missing" );
863
                $updsth->bind_param( 4, $row->{'import_items_id'} );
864
                $updsth->execute();
865
                $num_items_errored++;
866
                next;
867
            }
868
846
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc(
869
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc(
847
                $item_marc, $biblionumber,
870
                $item_marc, $biblionumber,
848
                { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 }
871
                { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 }
Lines 1248-1253 sub GetImportRecordsRange { Link Here
1248
1271
1249
}
1272
}
1250
1273
1274
=head2 GetImportItemsBranches
1275
1276
  my @results = GetImportItemsBranches($batch_id);
1277
1278
Returns an array of imported item branches.
1279
1280
=cut
1281
1282
sub GetImportItemsBranches {
1283
    my ( $batch_id ) = @_;
1284
1285
    my $dbh   = C4::Context->dbh;
1286
    my $query = "SELECT import_items_id, import_items.marcxml, encoding
1287
        FROM import_items
1288
        JOIN import_records USING (import_record_id)
1289
        WHERE import_batch_id = ?
1290
        ORDER BY import_items_id";
1291
    my @params;
1292
    push( @params, $batch_id );
1293
    my $sth = $dbh->prepare_cached($query);
1294
    $sth->execute(@params);
1295
    my $results = $sth->fetchall_arrayref( {} );
1296
    my @branch;
1297
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1298
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1299
    foreach my $row (@$results) {
1300
        my $item_marc    = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1301
        push @branch, $item_marc->subfield( $homebranchfield,    $homebranchsubfield );
1302
        push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );;
1303
    }
1304
    $sth->finish();
1305
    return uniq @branch;
1306
}
1307
1251
=head2 GetBestRecordMatch
1308
=head2 GetBestRecordMatch
1252
1309
1253
  my $record_id = GetBestRecordMatch($import_record_id);
1310
  my $record_id = GetBestRecordMatch($import_record_id);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+9 lines)
Lines 257-262 Link Here
257
                        <fieldset class="action">
257
                        <fieldset class="action">
258
                            <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
258
                            <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
259
                        </fieldset>
259
                        </fieldset>
260
                        [% IF ( missing_branches ) %]
261
                            <div class="dialog alert">There are some missing branches in your installation :
262
                            [% FOREACH branche IN branches %]
263
                                <a href="/cgi-bin/koha/admin/branches.pl?op=add_form" target="_blank">
264
                                    [% branche | html %]
265
                                </a>
266
                            [% END %]
267
                            </div>
268
                        [% END %]
260
                    </form>
269
                    </form>
261
                    <!-- /#import_batch_form -->
270
                    <!-- /#import_batch_form -->
262
                </div>
271
                </div>
(-)a/tools/manage-marc-import.pl (-2 / +9 lines)
Lines 31-42 use C4::Koha; Link Here
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 );
34
    qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches );
35
use C4::Matcher;
35
use C4::Matcher;
36
use C4::Labels::Batch;
36
use C4::Labels::Batch;
37
use Koha::BiblioFrameworks;
37
use Koha::BiblioFrameworks;
38
use Koha::BackgroundJob::MARCImportCommitBatch;
38
use Koha::BackgroundJob::MARCImportCommitBatch;
39
use Koha::BackgroundJob::MARCImportRevertBatch;
39
use Koha::BackgroundJob::MARCImportRevertBatch;
40
use Array::Utils qw( array_minus );
40
41
41
use Koha::Logger;
42
use Koha::Logger;
42
43
Lines 93-98 if ( $op eq "" ) { Link Here
93
    if ( $import_batch_id eq '' ) {
94
    if ( $import_batch_id eq '' ) {
94
        import_batches_list( $template, $offset, $results_per_page );
95
        import_batches_list( $template, $offset, $results_per_page );
95
    } else {
96
    } else {
97
        my @import_items_branches = GetImportItemsBranches($import_batch_id);
98
        my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
99
        my @missing_branches = array_minus( @import_items_branches, @branches );
100
        $template->param(
101
            missing_branches => scalar @missing_branches,
102
            branches => \@missing_branches
103
        );
96
        import_records_list( $template, $import_batch_id, $offset, $results_per_page );
104
        import_records_list( $template, $import_batch_id, $offset, $results_per_page );
97
    }
105
    }
98
} elsif ( $op eq "cud-commit-batch" ) {
106
} elsif ( $op eq "cud-commit-batch" ) {
99
- 

Return to bug 21272