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

(-)a/C4/ImportBatch.pm (-1 / +86 lines)
Lines 17-25 package C4::ImportBatch; Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
21
use base 'Exporter';
20
use base 'Exporter';
22
21
22
use strict;
23
use warnings;
24
25
use Modern::Perl;
26
27
use C4::Context;
28
use C4::Koha   qw( GetNormalizedISBN );
29
use C4::Biblio qw(
30
    AddBiblio
31
    DelBiblio
32
    GetMarcFromKohaField
33
    GetXmlBiblio
34
    ModBiblio
35
    TransformMarcToKoha
36
);
37
use C4::Items   qw( AddItemFromMarc ModItemFromMarc );
38
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars );
39
use C4::AuthoritiesMarc
40
    qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading );
41
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
42
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
43
use Koha::Items;
44
use Koha::SearchEngine;
45
use Koha::SearchEngine::Indexer;
46
use Koha::Plugins::Handler;
47
use Koha::Logger;
48
use List::MoreUtils qw( uniq );
49
50
our ( @ISA, @EXPORT_OK );
51
23
BEGIN {
52
BEGIN {
24
    our @EXPORT_OK = qw(
53
    our @EXPORT_OK = qw(
25
        GetZ3950BatchId
54
        GetZ3950BatchId
Lines 46-51 BEGIN { Link Here
46
        GetImportBiblios
75
        GetImportBiblios
47
        GetImportRecordsRange
76
        GetImportRecordsRange
48
        GetItemNumbersFromImportBatch
77
        GetItemNumbersFromImportBatch
78
        GetImportItemsBranches
49
79
50
        GetImportBatchStatus
80
        GetImportBatchStatus
51
        SetImportBatchStatus
81
        SetImportBatchStatus
Lines 839-844 sub _batchCommitItems { Link Here
839
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber");
869
            my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber");
840
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
870
            $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
841
871
872
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch');
873
            my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield );
874
            my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
875
            my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );
876
877
            my @branches = map { $_->branchcode } Koha::Libraries->search->as_list;
878
            my %branches = map { $_ => 1 } @branches;
879
880
            my $missing_branchcode;
881
            $missing_branchcode = $homebranch    if ( !exists( $branches{$homebranch} ) );
882
            $missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) );
883
            if ($missing_branchcode) {
884
                $updsth->bind_param( 1, 'error' );
885
                $updsth->bind_param( 2, undef );
886
                $updsth->bind_param( 3, "Branch code $missing_branchcode missing" );
887
                $updsth->bind_param( 4, $row->{'import_items_id'} );
888
                $updsth->execute();
889
                $num_items_errored++;
890
                next;
891
            }
892
842
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc(
893
            my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc(
843
                $item_marc, $biblionumber,
894
                $item_marc, $biblionumber,
844
                { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 }
895
                { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 }
Lines 1250-1255 sub GetImportRecordsRange { Link Here
1250
1301
1251
}
1302
}
1252
1303
1304
=head2 GetImportItemsBranches
1305
1306
  my @results = GetImportItemsBranches($batch_id);
1307
1308
Returns an array of imported item branches.
1309
1310
=cut
1311
1312
sub GetImportItemsBranches {
1313
    my ( $batch_id ) = @_;
1314
1315
    my $dbh   = C4::Context->dbh;
1316
    my $query = "SELECT import_items_id, import_items.marcxml, encoding
1317
        FROM import_items
1318
        JOIN import_records USING (import_record_id)
1319
        WHERE import_batch_id = ?
1320
        ORDER BY import_items_id";
1321
    my @params;
1322
    push( @params, $batch_id );
1323
    my $sth = $dbh->prepare_cached($query);
1324
    $sth->execute(@params);
1325
    my $results = $sth->fetchall_arrayref( {} );
1326
    my @branch;
1327
    my ( $homebranchfield,    $homebranchsubfield )    = GetMarcFromKohaField('items.homebranch');
1328
    my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch');
1329
    foreach my $row (@$results) {
1330
        my $item_marc    = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
1331
        push @branch, $item_marc->subfield( $homebranchfield,    $homebranchsubfield );
1332
        push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );;
1333
    }
1334
    $sth->finish();
1335
    return uniq @branch;
1336
}
1337
1253
=head2 GetBestRecordMatch
1338
=head2 GetBestRecordMatch
1254
1339
1255
  my $record_id = GetBestRecordMatch($import_record_id);
1340
  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