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

(-)a/C4/ImportBatch.pm (+56 lines)
Lines 39-44 use Koha::SearchEngine; Link Here
39
use Koha::SearchEngine::Indexer;
39
use Koha::SearchEngine::Indexer;
40
use Koha::Plugins::Handler;
40
use Koha::Plugins::Handler;
41
use Koha::Logger;
41
use Koha::Logger;
42
use List::MoreUtils qw( uniq );
42
43
43
our (@ISA, @EXPORT_OK);
44
our (@ISA, @EXPORT_OK);
44
BEGIN {
45
BEGIN {
Lines 69-74 BEGIN { Link Here
69
      GetImportBiblios
70
      GetImportBiblios
70
      GetImportRecordsRange
71
      GetImportRecordsRange
71
      GetItemNumbersFromImportBatch
72
      GetItemNumbersFromImportBatch
73
      GetImportItemsBranches
72
74
73
      GetImportBatchStatus
75
      GetImportBatchStatus
74
      SetImportBatchStatus
76
      SetImportBatchStatus
Lines 812-817 sub _batchCommitItems { Link Here
812
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
814
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
813
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
815
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
814
816
817
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch');
818
            my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield );
819
            my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
820
            my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );
821
822
            my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
823
            my %branches = map { $_ => 1 } @branches;
824
825
            my $missing_branchcode;
826
            $missing_branchcode = $homebranch    if ( !exists( $branches{$homebranch} ) );
827
            $missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) );
828
            if ($missing_branchcode) {
829
                $updsth->bind_param( 1, 'error' );
830
                $updsth->bind_param( 2, undef );
831
                $updsth->bind_param( 3, "Branch code $missing_branchcode missing" );
832
                $updsth->bind_param( 4, $row->{'import_items_id'} );
833
                $updsth->execute();
834
                $num_items_errored++;
835
                next;
836
            }
815
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } );
837
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } );
816
            if( $itemnumber ) {
838
            if( $itemnumber ) {
817
                $updsth->bind_param( 1, 'imported' );
839
                $updsth->bind_param( 1, 'imported' );
Lines 1195-1200 sub GetImportRecordsRange { Link Here
1195
1217
1196
}
1218
}
1197
1219
1220
=head2 GetImportItemsBranches
1221
1222
  my @results = GetImportItemsBranches($batch_id);
1223
1224
Returns an array of imported item branches.
1225
1226
=cut
1227
1228
sub GetImportItemsBranches {
1229
    my ( $batch_id ) = @_;
1230
1231
    my $dbh   = C4::Context->dbh;
1232
    my $query = "SELECT import_items_id, import_items.marcxml, encoding
1233
        FROM import_items
1234
        JOIN import_records USING (import_record_id)
1235
        WHERE import_batch_id = ?
1236
        ORDER BY import_items_id";
1237
    my @params;
1238
    push( @params, $batch_id );
1239
    my $sth = $dbh->prepare_cached($query);
1240
    $sth->execute(@params);
1241
    my $results = $sth->fetchall_arrayref( {} );
1242
    my @branch;
1243
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1244
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1245
    foreach my $row (@$results) {
1246
        my $item_marc    = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1247
        push @branch, $item_marc->subfield( $homebranchfield,    $homebranchsubfield );
1248
        push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );;
1249
    }
1250
    $sth->finish();
1251
    return uniq @branch;
1252
}
1253
1198
=head2 GetBestRecordMatch
1254
=head2 GetBestRecordMatch
1199
1255
1200
  my $record_id = GetBestRecordMatch($import_record_id);
1256
  my $record_id = GetBestRecordMatch($import_record_id);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+9 lines)
Lines 287-292 Link Here
287
                                    <fieldset class="action">
287
                                    <fieldset class="action">
288
                                        <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
288
                                        <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />
289
                                    </fieldset>
289
                                    </fieldset>
290
                                    [% IF ( missing_branches ) %]
291
                                        <div class="dialog alert">There are some missing branches in your installation :
292
                                        [% FOREACH branche IN branches %]
293
                                        <a href="/cgi-bin/koha/admin/branches.pl?op=add_form" target="_blank">
294
                                            [% branche | html %]
295
                                        </a>
296
                                        [% END %]
297
                                        </div>
298
                                    [% END %]
290
                                </form> <!-- /#import_batch_form -->
299
                                </form> <!-- /#import_batch_form -->
291
                            [% END # /IF can_commit %]
300
                            [% END # /IF can_commit %]
292
                            [% IF ( can_revert ) %]
301
                            [% IF ( can_revert ) %]
(-)a/tools/manage-marc-import.pl (-2 / +9 lines)
Lines 30-41 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 );
33
use C4::ImportBatch qw( 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
40
40
use Koha::Logger;
41
use Koha::Logger;
41
42
Lines 85-90 if ($op eq "") { Link Here
85
    if ($import_batch_id eq '') {
86
    if ($import_batch_id eq '') {
86
        import_batches_list($template, $offset, $results_per_page);
87
        import_batches_list($template, $offset, $results_per_page);
87
    } else {
88
    } else {
89
        my @import_items_branches = GetImportItemsBranches($import_batch_id);
90
        my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
91
        my @missing_branches = array_minus( @import_items_branches, @branches );
92
        $template->param(
93
            missing_branches => scalar @missing_branches,
94
            branches => \@missing_branches
95
        );
88
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
96
        import_records_list($template, $import_batch_id, $offset, $results_per_page);
89
    }
97
    }
90
} elsif ($op eq "commit-batch") {
98
} elsif ($op eq "commit-batch") {
91
- 

Return to bug 12532