Lines 86-94
RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) {
Link Here
|
86 |
my $biblio = Koha::Biblios->find($biblionumber); |
86 |
my $biblio = Koha::Biblios->find($biblionumber); |
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( |
99 |
C4::Biblio::ModBiblio( |
94 |
$record, |
100 |
$record, |
Lines 173-176
sub additional_report {
Link Here
|
173 |
}; |
179 |
}; |
174 |
} |
180 |
} |
175 |
|
181 |
|
|
|
182 |
=head3 marc_record_contains_item_data |
183 |
|
184 |
Verify if marc record contains item data |
185 |
|
186 |
=cut |
187 |
|
188 |
sub marc_record_contains_item_data { |
189 |
my ($record) = @_; |
190 |
|
191 |
my $itemfield = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '995' : '952'; |
192 |
my @item_fields = $record->field($itemfield); |
193 |
return scalar @item_fields; |
194 |
} |
195 |
|
196 |
=head3 can_add_item_from_marc_record |
197 |
|
198 |
Checks if adding an item from MARC can be done by checking mandatory fields |
199 |
|
200 |
=cut |
201 |
|
202 |
sub can_add_item_from_marc_record { |
203 |
my ($record) = @_; |
204 |
|
205 |
# Check that holdingbranch is set |
206 |
my $holdingbranch_mss = Koha::MarcSubfieldStructures->find( |
207 |
{ |
208 |
kohafield => 'items.holdingbranch', |
209 |
} |
210 |
); |
211 |
my @holdingbranch_exists = |
212 |
grep { $_->subfield( $holdingbranch_mss->tagsubfield ) } $record->field( $holdingbranch_mss->tagfield ); |
213 |
return ( 0, "No holdingbranch subfield found" ) unless ( scalar @holdingbranch_exists ); |
214 |
|
215 |
# Check that homebranch is set |
216 |
my $homebranch_mss = Koha::MarcSubfieldStructures->find( |
217 |
{ |
218 |
kohafield => 'items.homebranch', |
219 |
} |
220 |
); |
221 |
my @homebranch_exists = |
222 |
grep { $_->subfield( $homebranch_mss->tagsubfield ) } $record->field( $homebranch_mss->tagfield ); |
223 |
return ( 0, "No homebranch subfield found" ) unless ( scalar @homebranch_exists ); |
224 |
|
225 |
# Check that itemtype is set |
226 |
my $item_mss = Koha::MarcSubfieldStructures->find( |
227 |
{ |
228 |
kohafield => C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype', |
229 |
} |
230 |
); |
231 |
my @itemtype_exists = grep { $_->subfield( $item_mss->tagsubfield ) } $record->field( $item_mss->tagfield ); |
232 |
return ( 0, "No itemtype subfield found" ) unless ( scalar @itemtype_exists ); |
233 |
|
234 |
return 1; |
235 |
} |
236 |
|
176 |
1; |
237 |
1; |
177 |
- |
|
|