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

(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-3 / +63 lines)
Lines 87-94 sub process { Link Here
87
            my $record = $biblio->metadata->record;
87
            my $record = $biblio->metadata->record;
88
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
88
            C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record );
89
            my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
89
            my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber );
90
            my $biblioitemnumber = $biblio->biblioitem->biblioitemnumber;
90
91
            C4::Items::AddItemFromMarc( $record, $biblionumber, { biblioitemnumber => $biblioitemnumber } );
91
            if ( marc_record_contains_item_data($record) ) {
92
                my ( $can_add_item, $add_item_error_message ) = can_add_item_from_marc_record($record);
93
                return $add_item_error_message unless $can_add_item;
94
95
                my $biblioitemnumber = $biblio->biblioitem->biblioitemnumber;
96
                C4::Items::AddItemFromMarc( $record, $biblionumber, { biblioitemnumber => $biblioitemnumber } );
97
            }
92
98
93
            C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, {
99
            C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, {
94
                overlay_context   => $args->{overlay_context},
100
                overlay_context   => $args->{overlay_context},
Lines 166-169 sub additional_report { Link Here
166
    };
172
    };
167
}
173
}
168
174
175
=head3 marc_record_contains_item_data
176
177
Verify if marc record contains item data
178
179
=cut
180
181
sub marc_record_contains_item_data {
182
    my ($record) = @_;
183
184
    my $itemfield   = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '995' : '952';
185
    my @item_fields = $record->field($itemfield);
186
    return scalar @item_fields;
187
}
188
189
=head3 can_add_item_from_marc_record
190
191
Checks if adding an item from MARC can be done by checking mandatory fields
192
193
=cut
194
195
sub can_add_item_from_marc_record {
196
    my ($record) = @_;
197
198
    # Check that holdingbranch is set
199
    my $holdingbranch_mss = Koha::MarcSubfieldStructures->find(
200
        {
201
            kohafield => 'items.holdingbranch',
202
        }
203
    );
204
    my @holdingbranch_exists =
205
        grep { $_->subfield( $holdingbranch_mss->tagsubfield ) } $record->field( $holdingbranch_mss->tagfield );
206
    return ( 0, "No holdingbranch subfield found" ) unless ( scalar @holdingbranch_exists );
207
208
    # Check that homebranch is set
209
    my $homebranch_mss = Koha::MarcSubfieldStructures->find(
210
        {
211
            kohafield => 'items.homebranch',
212
        }
213
    );
214
    my @homebranch_exists =
215
        grep { $_->subfield( $homebranch_mss->tagsubfield ) } $record->field( $homebranch_mss->tagfield );
216
    return ( 0, "No homebranch subfield found" ) unless ( scalar @homebranch_exists );
217
218
    # Check that itemtype is set
219
    my $item_mss = Koha::MarcSubfieldStructures->find(
220
        {
221
            kohafield => C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype',
222
        }
223
    );
224
    my @itemtype_exists = grep { $_->subfield( $item_mss->tagsubfield ) } $record->field( $item_mss->tagfield );
225
    return ( 0, "No itemtype subfield found" ) unless ( scalar @itemtype_exists );
226
227
    return 1;
228
}
229
169
1;
230
1;
170
- 

Return to bug 26869